12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import 'dart:io';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_chinese_chees/models/game_manager.dart';
- import 'package:flutter_localizations/flutter_localizations.dart';
- import 'package:shirne_dialog/shirne_dialog.dart';
- import 'package:window_manager/window_manager.dart';
- import 'global.dart';
- import 'l10n/generated/app_localizations.dart';
- import 'pages/home_page.dart';
- import 'game_board.dart';
- /// Description: enter point
- /// Time : 04/28/2023 Friday
- /// Author : liuyuqi.gov@msn.cn
- void main() async {
- WidgetsFlutterBinding.ensureInitialized();
- // pc 平台,非 web 版本,设置窗体大小
- if (!kIsWeb && (Platform.isWindows || Platform.isMacOS || Platform.isLinux)) {
- await windowManager.ensureInitialized();
- const windowOptions = WindowOptions(
- size: Size(1024, 720),
- center: true,
- backgroundColor: Colors.transparent,
- skipTaskbar: false,
- titleBarStyle: TitleBarStyle.normal,
- );
- windowManager.waitUntilReadyToShow(windowOptions, () async {
- await windowManager.show();
- await windowManager.focus();
- });
- windowManager.addListener(MainWindowListener());
- }
- final gamer = GameManager();
- await gamer.init();
- runApp(const MyApp());
- }
- class MainWindowListener extends WindowListener {
- @override
- void onWindowClose() {
- GameManager.instance.engine?.dispose();
- }
- }
- class MyApp extends StatelessWidget {
- const MyApp({Key? key}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: '中国象棋',
- debugShowCheckedModeBanner: false,
- // onGenerateRoute: Routes.onGenerateRoute,
- // initialRoute: Routes.home,
- onGenerateTitle: (BuildContext context) {
- if (!kIsWeb &&
- (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
- windowManager.setTitle(context.l10n.appTitle);
- }
- return context.l10n.appTitle;
- },
- navigatorKey: MyDialog.navigatorKey,
- localizationsDelegates: const [
- AppLocalizations.delegate,
- ShirneDialogLocalizations.delegate,
- GlobalMaterialLocalizations.delegate,
- GlobalWidgetsLocalizations.delegate,
- GlobalCupertinoLocalizations.delegate,
- ],
- supportedLocales: const [
- Locale('en', ''),
- Locale('zh', 'CN'),
- ],
- theme: AppTheme.createTheme(),
- highContrastTheme: AppTheme.createTheme(isHighContrast: true),
- darkTheme: AppTheme.createTheme(isDark: true),
- highContrastDarkTheme: AppTheme.createTheme(
- isDark: true,
- isHighContrast: true,
- ),
- home: const HomePage(
- isMain: true,
- child: GameBoard(),
- ),
- );
- }
- }
|