import 'package:flutter/material.dart';
|
import 'package:fluttergamebox/store/app_state.dart';
|
import 'package:window_manager/window_manager.dart';
|
|
import 'api/api_client.dart';
|
import 'pages/login_page.dart';
|
import 'pages/main_shell.dart';
|
|
void main() async {
|
WidgetsFlutterBinding.ensureInitialized();
|
await windowManager.ensureInitialized();
|
await windowManager.waitUntilReadyToShow(
|
const WindowOptions(
|
size: Size(1280, 820),
|
minimumSize: Size(1100, 700),
|
title: '99游戏盒子',
|
titleBarStyle: TitleBarStyle.hidden,
|
center: true,
|
backgroundColor: Color(0xFF14161F),
|
),
|
() async {
|
await windowManager.show();
|
await windowManager.focus();
|
},
|
);
|
runApp(const GameBoxApp());
|
}
|
|
class GameBoxApp extends StatefulWidget {
|
const GameBoxApp({super.key});
|
@override
|
State<GameBoxApp> createState() => _GameBoxAppState();
|
}
|
|
class _GameBoxAppState extends State<GameBoxApp> with WindowListener {
|
bool _ready = false;
|
|
@override
|
void initState() {
|
super.initState();
|
windowManager.addListener(this);
|
_init();
|
}
|
|
@override
|
void dispose() {
|
windowManager.removeListener(this);
|
super.dispose();
|
}
|
|
@override
|
void onWindowClose() async {
|
await windowManager.destroy();
|
}
|
|
Future<void> _init() async {
|
await ApiClient.init();
|
if (ApiClient.token != null) {
|
await AppState.instance.refreshUserInfo();
|
}
|
if (mounted) setState(() => _ready = true);
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return MaterialApp(
|
title: '99游戏盒子',
|
debugShowCheckedModeBanner: false,
|
theme: ThemeData(
|
fontFamily: 'Microsoft YaHei',
|
scaffoldBackgroundColor: const Color(0xFF14161F),
|
colorScheme: const ColorScheme.dark(primary: Color(0xFF2B7FFF)),
|
),
|
home: _ready
|
? AnimatedBuilder(
|
animation: AppState.instance,
|
builder: (context, _) => AppState.instance.loggedIn
|
? const MainShell()
|
: const LoginPage(),
|
)
|
: const Scaffold(
|
body: Center(
|
child: CircularProgressIndicator(color: Color(0xFF2B7FFF)),
|
),
|
),
|
);
|
}
|
}
|