You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9 KiB
Dart

2 years ago
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
2 years ago
import 'package:isekai_wiki/global.dart';
import 'package:isekai_wiki/models/lifecycle.dart';
2 years ago
import 'package:package_info_plus/package_info_plus.dart';
import 'app.dart';
Future<void> init() async {
// 仅允许竖屏
/*SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);*/
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(statusBarColor: Colors.transparent));
if (kIsWeb) {
// 设置web origin
Global.webOrigin = Uri.base.origin;
}
await GetStorage.init();
2 years ago
// 检测是否已激活
var storage = GetStorage();
Global.isAppActive = storage.read<bool>("appActive") ?? false;
2 years ago
}
Future<void> postInit() async {
Global.packageInfo = await PackageInfo.fromPlatform();
if (!kIsWeb && GetPlatform.isAndroid) {
2 years ago
// 启用高刷
try {
if (kDebugMode) {
var modes = await FlutterDisplayMode.supported;
print("Refresh rate list:");
// ignore: avoid_print
modes.forEach(print);
print("Preferred refresh rate:");
print(await FlutterDisplayMode.preferred);
}
await FlutterDisplayMode.setHighRefreshRate();
} catch (err) {
if (kDebugMode) {
print("Cannot set to high refresh rate: ");
print(err);
}
}
}
WidgetsFlutterBinding.ensureInitialized();
if (GetPlatform.isAndroid) {
await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
}
2 years ago
}
Future<void> main() async {
Get.put(LifeCycleController());
await init();
2 years ago
runApp(const IsekaiWikiApp());
postInit();
}