| import 'dart:io'; | import 'dart:io'; | ||||
| import 'package:dio/dio.dart'; | import 'package:dio/dio.dart'; | ||||
| import 'package:farm_tpf/custom_model/NotificationDTO.dart'; | |||||
| import 'package:farm_tpf/data/repository/repository.dart'; | import 'package:farm_tpf/data/repository/repository.dart'; | ||||
| import 'package:farm_tpf/data/repository/user_repository.dart'; | import 'package:farm_tpf/data/repository/user_repository.dart'; | ||||
| import 'package:farm_tpf/main.dart'; | import 'package:farm_tpf/main.dart'; | ||||
| import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot/widget_search.dart'; | import 'package:farm_tpf/presentation/screens/plot/widget_search.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; | import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; | ||||
| import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_information.dart'; | |||||
| import 'package:farm_tpf/utils/const_color.dart'; | import 'package:farm_tpf/utils/const_color.dart'; | ||||
| import 'package:farm_tpf/utils/const_common.dart'; | import 'package:farm_tpf/utils/const_common.dart'; | ||||
| import 'package:farm_tpf/utils/pref.dart'; | import 'package:farm_tpf/utils/pref.dart'; | ||||
| import 'package:farm_tpf/utils/const_string.dart'; | import 'package:farm_tpf/utils/const_string.dart'; | ||||
| import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | ||||
| import 'package:farm_tpf/utils/formatter.dart'; | import 'package:farm_tpf/utils/formatter.dart'; | ||||
| import 'package:get/get.dart'; | |||||
| import 'bloc/plot_bloc.dart'; | import 'bloc/plot_bloc.dart'; | ||||
| onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler, | onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler, | ||||
| onLaunch: (Map<String, dynamic> message) async { | onLaunch: (Map<String, dynamic> message) async { | ||||
| print("onLaunch: $message"); | print("onLaunch: $message"); | ||||
| Future.delayed(Duration(milliseconds: 500), () { | |||||
| _notificationNavigateOnFCM(message); | |||||
| }); | |||||
| }, | }, | ||||
| onResume: (Map<String, dynamic> message) async { | onResume: (Map<String, dynamic> message) async { | ||||
| print("onResume: $message"); | print("onResume: $message"); | ||||
| _notificationNavigateOnFCM(message); | |||||
| }, | }, | ||||
| ); | ); | ||||
| _firebaseMessaging.requestNotificationPermissions( | _firebaseMessaging.requestNotificationPermissions( | ||||
| } | } | ||||
| } | } | ||||
| _notificationNavigateOnFCM(Map<String, dynamic> message) { | |||||
| //parse data difference between Ios and Android | |||||
| var noti; | |||||
| if (Platform.isAndroid) { | |||||
| var data = message['data']; | |||||
| noti = NotificationDTO() | |||||
| ..contents = data['contents'] | |||||
| ..tbCropId = data['tbCropId']; | |||||
| } else { | |||||
| noti = NotificationDTO.fromJson(message); | |||||
| } | |||||
| if (noti.contents == "ENV_UPDATE") { | |||||
| Get.to(PlotDetailScreen(cropId: noti.tbCropId)); | |||||
| } else if (noti.contents == "PIC_UPDATE") { | |||||
| Get.to(PlotInformationScreen( | |||||
| cropId: noti.tbCropId, | |||||
| )); | |||||
| } else { | |||||
| //Go home | |||||
| } | |||||
| } | |||||
| @override | @override | ||||
| void initState() { | void initState() { | ||||
| super.initState(); | super.initState(); |