main.dart 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_clock/index_page.dart';
  5. import 'package:flutter_clock/utils/app_utils.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:window_manager/window_manager.dart';
  8. /// Description: enter point of the app
  9. /// Time : 04/06/2025 Sunday
  10. /// Author : liuyuqi.gov@msn.cn
  11. void main() async {
  12. WidgetsFlutterBinding.ensureInitialized();
  13. AppUtils.setOverrideForDesktop();
  14. // Initialize window manager for desktop platforms
  15. if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
  16. await windowManager.ensureInitialized();
  17. // Calculate window size with 16:9 portrait ratio
  18. // Common phone resolution is 1080x1920 (16:9 portrait)
  19. const double width = 360.0; // Phone width
  20. const double height = 640.0; // Phone height (16:9 ratio)
  21. WindowOptions windowOptions = WindowOptions(
  22. size: Size(width, height),
  23. center: true,
  24. backgroundColor: Colors.transparent,
  25. skipTaskbar: false,
  26. titleBarStyle: TitleBarStyle.normal,
  27. );
  28. await windowManager.waitUntilReadyToShow(windowOptions, () async {
  29. await windowManager.show();
  30. await windowManager.focus();
  31. });
  32. }
  33. // Configure system settings for better background execution
  34. if (Platform.isAndroid) {
  35. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  36. statusBarColor: Colors.transparent,
  37. statusBarIconBrightness: Brightness.dark,
  38. ));
  39. // Prevent app from being killed in background
  40. SystemChannels.platform.invokeMethod('SystemChrome.setEnabledSystemUIMode', [
  41. SystemUiMode.edgeToEdge.index,
  42. ]);
  43. }
  44. runApp(MyApp());
  45. }
  46. class MyApp extends StatelessWidget {
  47. @override
  48. Widget build(BuildContext context) {
  49. // Initialize ScreenUtil for responsive UI
  50. return ScreenUtilInit(
  51. designSize: const Size(360, 640), // Base design size
  52. minTextAdapt: true,
  53. splitScreenMode: true,
  54. builder: (context, child) {
  55. return MaterialApp(
  56. title: 'Flutter Clock',
  57. debugShowCheckedModeBanner: false,
  58. theme: ThemeData(
  59. primarySwatch: Colors.blue,
  60. visualDensity: VisualDensity.adaptivePlatformDensity,
  61. fontFamily: 'Roboto',
  62. brightness: Brightness.light,
  63. tabBarTheme: TabBarTheme(
  64. labelColor: Colors.blue,
  65. unselectedLabelColor: Colors.black87,
  66. indicatorSize: TabBarIndicatorSize.tab,
  67. labelStyle: TextStyle(fontWeight: FontWeight.bold),
  68. unselectedLabelStyle: TextStyle(fontWeight: FontWeight.normal),
  69. ),
  70. appBarTheme: AppBarTheme(
  71. color: Colors.white,
  72. foregroundColor: Colors.black,
  73. elevation: 1.0,
  74. ),
  75. ),
  76. home: IndexPage(),
  77. );
  78. }
  79. );
  80. }
  81. }