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.

112 lines
3.4 KiB
Dart

2 years ago
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
2 years ago
import 'package:get/get.dart';
2 years ago
import 'package:isekai_wiki/global.dart';
import 'package:isekai_wiki/models/settings.dart';
import 'package:isekai_wiki/models/user.dart';
2 years ago
import 'package:isekai_wiki/pages/welcome_page.dart';
2 years ago
import 'models/model.dart';
import 'pages/tab_page.dart';
import 'styles.dart';
class IsekaiWikiAppWrapper extends StatefulWidget {
final Widget child;
const IsekaiWikiAppWrapper({super.key, required this.child});
@override
State<StatefulWidget> createState() => _IsekaiWikiAppWrapperState();
}
class _IsekaiWikiAppWrapperState extends State<IsekaiWikiAppWrapper> {
@override
void initState() {
super.initState();
if (GetPlatform.isAndroid) {
// 仅允许竖屏
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
if (GetPlatform.isAndroid) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarBrightness: Brightness.dark,
statusBarIconBrightness: Brightness.light,
systemStatusBarContrastEnforced: false,
systemNavigationBarColor: Colors.black.withAlpha(1),
systemNavigationBarContrastEnforced: false,
systemNavigationBarIconBrightness: Brightness.dark,
),
);
}
}
}
@override
Widget build(BuildContext context) => widget.child;
}
2 years ago
class IsekaiWikiApp extends StatelessWidget {
const IsekaiWikiApp({super.key});
2 years ago
Widget _buildApp(BuildContext context) {
if (Global.isAppActive) {
return const IsekaiWikiTabsPage();
} else {
return const WelcomePage();
}
}
2 years ago
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
Get.put(UserController());
Get.put(AppSettingsController());
2 years ago
return Material(
child: GetCupertinoApp(
title: '异世界百科',
theme: Styles.cupertinoTheme,
2 years ago
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en'),
Locale('zh', 'CN'),
2 years ago
],
initialBinding: InitialBinding(),
2 years ago
home: _buildApp(context),
2 years ago
builder: (context, child) {
if (child == null) {
return Container();
} else {
Styles.textScaleFactor = MediaQuery.of(context).textScaleFactor;
Styles.isXs = MediaQuery.of(context).size.width <= 340;
var brightness = MediaQuery.of(context).platformBrightness;
return IsekaiWikiAppWrapper(
child: Theme(
data: brightness != Brightness.dark
? Styles.materialLightTheme
: Styles.materialDarkTheme,
child: CupertinoTheme(
data:
Styles.cupertinoTheme.copyWith(brightness: brightness),
child: child),
),
);
2 years ago
}
},
debugShowCheckedModeBanner: false,
),
);
}
}