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