| 1 | import 'package:aero/constants/main.dart'; |
| 2 | import 'package:aero/notifiers/user.dart'; |
| 3 | import 'package:aero/routes/main.dart'; |
| 4 | import 'package:aero/services/widget_update_service.dart'; |
| 5 | import 'package:flutter/material.dart'; |
| 6 | import 'package:provider/provider.dart'; |
| 7 | import 'package:toastification/toastification.dart'; |
| 8 | import 'package:workmanager/workmanager.dart'; |
| 9 | |
| 10 | // Workmanager callback handler |
| 11 | @pragma('vm:entry-point') |
| 12 | void callbackDispatcher() { |
| 13 | Workmanager().executeTask((task, |
| 14 | try { |
| 15 | if (task == 'widgetUpdateTask') { |
| 16 | await WidgetUpdateService.updateWidget() |
| 17 | } |
| 18 | return Future.value |
| 19 | } catch (e) { |
| 20 | print('Error in workmanager task: $e' |
| 21 | return Future.value |
| 22 | } |
| 23 | }); |
| 24 | } |
| 25 | |
| 26 | void main() async { |
| 27 | WidgetsFlutterBinding.ensureInitialized(); |
| 28 | |
| 29 | // Initialize Workmanager |
| 30 | await Workmanager().initialize |
| 31 | callbackDispatcher, |
| 32 | isInDebugMode: false, // Set to true for debugging |
| 33 | ); |
| 34 | |
| 35 | // Register periodic task to update widget every 15 minutes |
| 36 | await Workmanager().registerPeriodicTask |
| 37 | 'widget-update', |
| 38 | 'widgetUpdateTask', |
| 39 | frequency: const Duration(minutes |
| 40 | constraints: Constraints( |
| 41 | networkType: NetworkType.connected, |
| 42 | ), |
| 43 | ); |
| 44 | |
| 45 | runApp( |
| 46 | MultiProvider( |
| 47 | providers: [ |
| 48 | ChangeNotifierProvider( |
| 49 | create: (context) { |
| 50 | return UserNotifier(); |
| 51 | }, |
| 52 | ) |
| 53 | ], |
| 54 | child: const MainApp() |
| 55 | ), |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | class MainApp extends StatelessWidget |
| 60 | const MainApp({super |
| 61 | |
| 62 | @override |
| 63 | Widget build(BuildContext |
| 64 | return ToastificationWrapper( |
| 65 | child: MaterialApp.router( |
| 66 | routerConfig: AeroRouter.router, |
| 67 | debugShowCheckedModeBanner: false, |
| 68 | theme: ThemeData( |
| 69 | useMaterial3: true, |
| 70 | scaffoldBackgroundColor: Colors.white, |
| 71 | fontFamily: "Geist", |
| 72 | brightness: Brightness.light, |
| 73 | primaryColor: Colors.black, |
| 74 | navigationBarTheme: NavigationBarThemeData( |
| 75 | labelTextStyle: const WidgetStatePropertyAll( |
| 76 | TextStyle( |
| 77 | fontSize: 14, |
| 78 | ), |
| 79 | ), |
| 80 | backgroundColor: const Color( |
| 81 | indicatorColor: Colors.black.withValues |
| 82 | alpha: .4, |
| 83 | ), |
| 84 | ), |
| 85 | appBarTheme: const AppBarTheme( |
| 86 | elevation: 0, |
| 87 | scrolledUnderElevation: 0, |
| 88 | titleTextStyle: TextStyle( |
| 89 | fontFamily: "CalSans", |
| 90 | fontSize: 20, |
| 91 | color: Colors.black, |
| 92 | ), |
| 93 | toolbarHeight: 50, |
| 94 | backgroundColor: Colors.white, |
| 95 | ), |
| 96 | textTheme: const TextTheme( |
| 97 | labelMedium: TextStyle( |
| 98 | fontSize: 20, |
| 99 | ), |
| 100 | titleLarge: TextStyle( |
| 101 | fontSize: 32, |
| 102 | fontWeight: FontWeight.bold, |
| 103 | ), |
| 104 | titleSmall: TextStyle( |
| 105 | fontSize: 16, |
| 106 | color: SECONDARY_TEXT_COLOR, |
| 107 | ), |
| 108 | titleMedium: TextStyle( |
| 109 | fontSize: 20, |
| 110 | ), |
| 111 | bodyMedium: TextStyle( |
| 112 | color: Colors.black87, |
| 113 | fontSize: 14, |
| 114 | ), |
| 115 | ), |
| 116 | elevatedButtonTheme: ElevatedButtonThemeData( |
| 117 | style: ElevatedButton.styleFrom( |
| 118 | backgroundColor: Colors.blueAccent, |
| 119 | foregroundColor: Colors.black, |
| 120 | shape: RoundedRectangleBorder( |
| 121 | borderRadius: BorderRadius.circular( |
| 122 | 10, |
| 123 | ), |
| 124 | ), |
| 125 | ), |
| 126 | ), |
| 127 | outlinedButtonTheme: OutlinedButtonThemeData( |
| 128 | style: OutlinedButton.styleFrom( |
| 129 | foregroundColor: Colors.black, |
| 130 | side: const BorderSide( |
| 131 | color: Colors.blueAccent, |
| 132 | width: 2, |
| 133 | ), |
| 134 | shape: RoundedRectangleBorder( |
| 135 | borderRadius: BorderRadius.circular( |
| 136 | ), |
| 137 | padding: const EdgeInsets. |
| 138 | vertical: 12, |
| 139 | horizontal: 16, |
| 140 | ), |
| 141 | ), |
| 142 | ), |
| 143 | ), |
| 144 | ), |
| 145 | ); |
| 146 | } |
| 147 | } |