mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
new: PlatformType
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:plain_notification_token/plain_notification_token.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import 'platform.dart';
|
||||
|
||||
Future<bool> shareFiles(BuildContext context, List<String> filePaths) async {
|
||||
for (final filePath in filePaths) {
|
||||
if (!await File(filePath).exists()) {
|
||||
@@ -34,14 +36,14 @@ Future<String?> pickOneFile() async {
|
||||
}
|
||||
|
||||
Future<String?> getToken() async {
|
||||
final plainNotificationToken = PlainNotificationToken();
|
||||
if (Platform.isIOS) {
|
||||
if (isIOS) {
|
||||
final plainNotificationToken = PlainNotificationToken();
|
||||
plainNotificationToken.requestPermission();
|
||||
|
||||
// If you want to wait until Permission dialog close,
|
||||
// you need wait changing setting registered.
|
||||
await plainNotificationToken.onIosSettingsRegistered.first;
|
||||
return await plainNotificationToken.getToken();
|
||||
}
|
||||
|
||||
return await plainNotificationToken.getToken();
|
||||
return null;
|
||||
}
|
||||
|
||||
44
lib/core/utils/platform.dart
Normal file
44
lib/core/utils/platform.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
enum PlatformType {
|
||||
android,
|
||||
ios,
|
||||
linux,
|
||||
macos,
|
||||
windows,
|
||||
web,
|
||||
}
|
||||
|
||||
final _p = () {
|
||||
if (kIsWeb) {
|
||||
return PlatformType.web;
|
||||
}
|
||||
if (Platform.isAndroid) {
|
||||
return PlatformType.android;
|
||||
}
|
||||
if (Platform.isIOS) {
|
||||
return PlatformType.ios;
|
||||
}
|
||||
if (Platform.isLinux) {
|
||||
return PlatformType.linux;
|
||||
}
|
||||
if (Platform.isMacOS) {
|
||||
return PlatformType.macos;
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
return PlatformType.windows;
|
||||
}
|
||||
return PlatformType.web;
|
||||
}();
|
||||
|
||||
PlatformType get platform => _p;
|
||||
|
||||
bool get isAndroid => _p == PlatformType.android;
|
||||
bool get isIOS => _p == PlatformType.ios;
|
||||
bool get isLinux => _p == PlatformType.linux;
|
||||
bool get isMacOS => _p == PlatformType.macos;
|
||||
bool get isWindows => _p == PlatformType.windows;
|
||||
bool get isWeb => _p == PlatformType.web;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
@@ -8,6 +6,7 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../view/widget/card_dialog.dart';
|
||||
import '../persistant_store.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
bool isDarkMode(BuildContext context) =>
|
||||
Theme.of(context).brightness == Brightness.dark;
|
||||
@@ -62,7 +61,7 @@ Widget buildSwitch(BuildContext context, StoreProperty<bool> prop,
|
||||
}
|
||||
|
||||
void setTransparentNavigationBar(BuildContext context) {
|
||||
if (Platform.isAndroid) {
|
||||
if (isAndroid) {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
|
||||
Reference in New Issue
Block a user