main.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ),
  63. home: IndexPage(),
  64. );
  65. }
  66. );
  67. }
  68. }