@@ -23,11 +23,11 @@ import 'dart:async';
2323
2424import 'package:adaptive_theme/adaptive_theme.dart' ;
2525import 'package:background_downloader/background_downloader.dart' ;
26+ import 'package:boxbox/api/formula1.dart' ;
2627import 'package:boxbox/config/router.dart' ;
27- // import 'package:awesome_notifications/awesome_notifications.dart';
28+ import 'package:awesome_notifications/awesome_notifications.dart' ;
2829import 'package:boxbox/helpers/constants.dart' ;
2930import 'package:boxbox/helpers/route_handler.dart' ;
30- // import 'package:boxbox/Screens/article.dart';
3131import 'package:boxbox/helpers/team_background_color.dart' ;
3232import 'package:flutter/material.dart' ;
3333import 'package:flutter/foundation.dart' show kIsWeb;
@@ -36,6 +36,7 @@ import 'package:go_router/go_router.dart';
3636import 'package:hive_flutter/hive_flutter.dart' ;
3737import 'package:receive_sharing_intent/receive_sharing_intent.dart' ;
3838import 'package:timeago/timeago.dart' as timeago;
39+ import 'package:workmanager/workmanager.dart' ;
3940
4041void main () async {
4142 WidgetsFlutterBinding .ensureInitialized ();
@@ -50,10 +51,8 @@ void main() async {
5051
5152 if (! kIsWeb) {
5253 await FileDownloader ().trackTasks ();
53- }
5454
55- /* if (!kIsWeb) {
56- AwesomeNotifications().initialize(
55+ await AwesomeNotifications ().initialize (
5756 'resource://drawable/notification_icon' ,
5857 [
5958 NotificationChannel (
@@ -75,29 +74,29 @@ void main() async {
7574 ),
7675 ],
7776 );
78- } */
77+ }
7978
80- /* Workmanager().initialize(
79+ await Workmanager ().initialize (
8180 callbackDispatcher,
82- isInDebugMode: false,
8381 );
84- Workmanager().registerPeriodicTask(
82+ await Workmanager ().registerPeriodicTask (
8583 'newsLoader' ,
8684 "Load news in background" ,
8785 existingWorkPolicy: ExistingWorkPolicy .replace,
88- frequency: const Duration(hours: 2 ),
86+ frequency: const Duration (seconds : 30 ),
8987 initialDelay: const Duration (hours: 2 ),
90- ); */
88+ );
9189
9290 GoRouter .optionURLReflectsImperativeAPIs = true ;
9391
9492 runApp (const MyApp ());
9593}
9694
97- /* int createUniqueId() {
95+ int createUniqueId () {
9896 return DateTime .now ().millisecondsSinceEpoch.remainder (100000 );
9997}
10098
99+ @pragma ('vm:entry-point' )
101100void callbackDispatcher () {
102101 Workmanager ().executeTask (
103102 (task, inputData) async {
@@ -108,7 +107,7 @@ void callbackDispatcher() {
108107 bool useDataSaverMode =
109108 settingsBox.get ('useDataSaverMode' , defaultValue: false ) as bool ;
110109 try {
111- Map<String, dynamic> fetchedData = await F1NewsFetcher ().getRawNews();
110+ Map fetchedData = await Formula1 ().getRawNews (0 );
112111 if (cachedNews.isNotEmpty &&
113112 fetchedData['items' ][0 ]['id' ] != cachedNews['items' ][0 ]['id' ]) {
114113 String imageUrl =
@@ -167,7 +166,7 @@ void callbackDispatcher() {
167166 }
168167 },
169168 );
170- } */
169+ }
171170
172171void setTimeagoLocaleMessages () {
173172 timeago.setLocaleMessages ('ar' , timeago.ArMessages ());
@@ -248,43 +247,24 @@ void setTimeagoLocaleMessages() {
248247 timeago.setLocaleMessages ('zh' , timeago.ZhMessages ());
249248}
250249
251- /* class NotificationController {
252- static Future<void> startListeningNotificationEvents(
253- BuildContext context) async {
254- AwesomeNotifications().setListeners(
255- onActionReceivedMethod: (receivedAction) async =>
256- receivedAction.payload?['id'] == null
257- ? Navigator.push(
258- context,
259- MaterialPageRoute(
260- builder: (context) => Scaffold(
261- appBar: AppBar(
262- title: const Text('wrong payload'),
263- backgroundColor:
264- Theme.of(context).colorScheme.onPrimary,
265- ),
266- body: Center(
267- child: Text(
268- receivedAction.payload.toString(),
269- ),
270- ),
271- ),
272- ),
273- )
274- : Navigator.push(
275- context,
276- MaterialPageRoute(
277- builder: (context) => ArticleScreen(
278- receivedAction.payload!['id']!,
279- receivedAction.payload!['title']!,
280- false,
281- ),
282- ),
283- ),
250+ class NotificationController {
251+ @pragma ("vm:entry-point" )
252+ static Future <void > onActionReceivedMethod (
253+ ReceivedAction receivedAction) async {
254+ RouterLocalConfig .router.pushNamed (
255+ 'article' ,
256+ pathParameters: receivedAction.payload? ['title' ] != null
257+ ? {
258+ 'id' : receivedAction.payload? ['id' ] ?? '' ,
259+ 'articleName' : receivedAction.payload! ['title' ]! ,
260+ }
261+ : {
262+ 'id' : receivedAction.payload? ['id' ] ?? '' ,
263+ },
284264 );
285265 }
286266}
287- */
267+
288268class MyApp extends StatefulWidget {
289269 const MyApp ({Key ? key}) : super (key: key);
290270
@@ -300,11 +280,13 @@ class _MyAppState extends State<MyApp> {
300280 super .initState ();
301281 if (! kIsWeb) {
302282 // notifications service
303- // NotificationController.startListeningNotificationEvents(context);
283+ AwesomeNotifications ().setListeners (
284+ onActionReceivedMethod: NotificationController .onActionReceivedMethod,
285+ );
304286
305287 // For sharing or opening urls/text coming from outside the app while the app is in the memory
306288 _intentDataStreamSubscription =
307- ReceiveSharingIntent .getMediaStream ().listen (
289+ ReceiveSharingIntent .instance. getMediaStream ().listen (
308290 (List <SharedMediaFile >? value) {
309291 if (value? .isNotEmpty ?? false ) {
310292 if (value? [0 ] != null ) {
@@ -318,7 +300,7 @@ class _MyAppState extends State<MyApp> {
318300 );
319301
320302 // For sharing or opening urls/text coming from outside the app while the app is closed
321- ReceiveSharingIntent .getInitialMedia ().then (
303+ ReceiveSharingIntent .instance. getInitialMedia ().then (
322304 (List <SharedMediaFile >? value) {
323305 if (value? .isNotEmpty ?? false ) {
324306 if (value? [0 ] != null ) {
0 commit comments