main.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:flutter/foundation.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_localizations/flutter_localizations.dart';
  5. import 'package:tetris/gamer/gamer.dart';
  6. import 'package:tetris/generated/l10n.dart';
  7. import 'package:tetris/material/audios.dart';
  8. import 'package:tetris/panel/page_portrait.dart';
  9. import 'gamer/keyboard.dart';
  10. void main() {
  11. WidgetsFlutterBinding.ensureInitialized();
  12. debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
  13. _disableDebugPrint();
  14. runApp(const MainApp());
  15. SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
  16. statusBarColor: Colors.transparent,
  17. statusBarIconBrightness: Brightness.dark,
  18. systemNavigationBarColor: Colors.transparent,
  19. systemNavigationBarIconBrightness: Brightness.dark,
  20. ));
  21. }
  22. void _disableDebugPrint() {
  23. bool debug = false;
  24. assert(() {
  25. debug = true;
  26. return true;
  27. }());
  28. if (!debug) {
  29. debugPrint = (message, {wrapWidth}) {
  30. //disable log print when not in debug mode
  31. };
  32. }
  33. }
  34. final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();
  35. class MainApp extends StatelessWidget {
  36. const MainApp({super.key});
  37. // This widget is the root of your application.
  38. @override
  39. Widget build(BuildContext context) {
  40. return MaterialApp(
  41. title: '俄罗斯方块',
  42. localizationsDelegates: const [
  43. S.delegate,
  44. GlobalMaterialLocalizations.delegate,
  45. GlobalWidgetsLocalizations.delegate
  46. ],
  47. navigatorObservers: [routeObserver],
  48. supportedLocales: S.delegate.supportedLocales,
  49. theme: ThemeData(
  50. primarySwatch: Colors.blue,
  51. ),
  52. home: Scaffold(
  53. body: Sound(child: Game(child: KeyboardController(child: _HomePage()))),
  54. ),
  55. );
  56. }
  57. }
  58. const screenBorderWidth = 3.0;
  59. const backgroundColor = Color(0xffefcc19);
  60. class _HomePage extends StatelessWidget {
  61. @override
  62. Widget build(BuildContext context) {
  63. //only Android/iOS support land mode
  64. bool land = MediaQuery.of(context).orientation == Orientation.landscape;
  65. return land ? const PageLand() : const PagePortrait();
  66. }
  67. }