|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:isekai_wiki/global.dart';
|
|
|
|
import 'package:isekai_wiki/models/settings.dart';
|
|
|
|
import 'package:isekai_wiki/models/user.dart';
|
|
|
|
import 'package:isekai_wiki/pages/welcome_page.dart';
|
|
|
|
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.transparent.withAlpha(1),
|
|
|
|
systemNavigationBarContrastEnforced: false,
|
|
|
|
systemNavigationBarIconBrightness: Brightness.dark,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => widget.child;
|
|
|
|
}
|
|
|
|
|
|
|
|
class IsekaiWikiApp extends StatelessWidget {
|
|
|
|
const IsekaiWikiApp({super.key});
|
|
|
|
|
|
|
|
Widget _buildApp(BuildContext context) {
|
|
|
|
if (Global.isAppActive) {
|
|
|
|
return const IsekaiWikiTabsPage();
|
|
|
|
} else {
|
|
|
|
return const WelcomePage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Get.put(UserController());
|
|
|
|
Get.put(AppSettingsController());
|
|
|
|
|
|
|
|
return Material(
|
|
|
|
child: GetCupertinoApp(
|
|
|
|
title: '异世界百科',
|
|
|
|
theme: Styles.cupertinoTheme,
|
|
|
|
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
],
|
|
|
|
supportedLocales: const [
|
|
|
|
Locale('zh', 'CN'),
|
|
|
|
Locale('en'),
|
|
|
|
],
|
|
|
|
initialBinding: InitialBinding(),
|
|
|
|
home: _buildApp(context),
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|