| 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:google_fonts/google_fonts.dart'; |
| 7 | import 'package:provider/provider.dart'; |
| 8 | import 'package:toastification/toastification.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 | runApp( |
| 47 | MultiProvider( |
| 48 | providers: [ |
| 49 | ChangeNotifierProvider( |
| 50 | create: (context) { |
| 51 | return UserNotifier(); |
| 52 | }, |
| 53 | ) |
| 54 | ], |
| 55 | child: const MainApp() |
| 56 | ), |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | class MainApp extends StatelessWidget |
| 61 | const MainApp({super |
| 62 | |
| 63 | @override |
| 64 | Widget build(BuildContext |
| 65 | return ToastificationWrapper( |
| 66 | child: MaterialApp.router( |
| 67 | routerConfig: AeroRouter.router, |
| 68 | debugShowCheckedModeBanner: false, |
| 69 | theme: ThemeData( |
| 70 | useMaterial3: true, |
| 71 | scaffoldBackgroundColor: Colors.white, |
| 72 | fontFamily: GoogleFonts.inter() |
| 73 | brightness: Brightness.light, |
| 74 | primaryColor: Colors.black, |
| 75 | navigationBarTheme: NavigationBarThemeData( |
| 76 | labelTextStyle: const WidgetStatePropertyAll( |
| 77 | TextStyle( |
| 78 | fontSize: 14, |
| 79 | ), |
| 80 | ), |
| 81 | backgroundColor: const Color( |
| 82 | indicatorColor: Colors.black.withValues |
| 83 | alpha: .4, |
| 84 | ), |
| 85 | ), |
| 86 | appBarTheme: const AppBarTheme( |
| 87 | elevation: 0, |
| 88 | scrolledUnderElevation: 0, |
| 89 | titleTextStyle: TextStyle( |
| 90 | fontFamily: "CalSans", |
| 91 | fontSize: 20, |
| 92 | color: Colors.black, |
| 93 | ), |
| 94 | toolbarHeight: 50, |
| 95 | backgroundColor: Colors.white, |
| 96 | ), |
| 97 | textTheme: const TextTheme( |
| 98 | labelMedium: TextStyle( |
| 99 | fontSize: 20, |
| 100 | ), |
| 101 | titleLarge: TextStyle( |
| 102 | fontSize: 32, |
| 103 | fontWeight: FontWeight.bold, |
| 104 | ), |
| 105 | titleSmall: TextStyle( |
| 106 | fontSize: 16, |
| 107 | color: SECONDARY_TEXT_COLOR, |
| 108 | ), |
| 109 | titleMedium: TextStyle( |
| 110 | fontSize: 20, |
| 111 | ), |
| 112 | bodyMedium: TextStyle( |
| 113 | color: Colors.black87, |
| 114 | fontSize: 14, |
| 115 | ), |
| 116 | ), |
| 117 | elevatedButtonTheme: ElevatedButtonThemeData( |
| 118 | style: ElevatedButton.styleFrom( |
| 119 | backgroundColor: Colors.blueAccent, |
| 120 | foregroundColor: Colors.black, |
| 121 | shape: RoundedRectangleBorder( |
| 122 | borderRadius: BorderRadius.circular( |
| 123 | 10, |
| 124 | ), |
| 125 | ), |
| 126 | ), |
| 127 | ), |
| 128 | outlinedButtonTheme: OutlinedButtonThemeData( |
| 129 | style: OutlinedButton.styleFrom( |
| 130 | foregroundColor: Colors.black, |
| 131 | side: const BorderSide( |
| 132 | color: Colors.blueAccent, |
| 133 | width: 2, |
| 134 | ), |
| 135 | shape: RoundedRectangleBorder( |
| 136 | borderRadius: BorderRadius.circular( |
| 137 | ), |
| 138 | padding: const EdgeInsets. |
| 139 | vertical: 12, |
| 140 | horizontal: 16, |
| 141 | ), |
| 142 | ), |
| 143 | ), |
| 144 | ), |
| 145 | ), |
| 146 | ); |
| 147 | } |
| 148 | } |