| @@ -1,6 +1,7 @@ | |||
| import 'dart:io'; | |||
| 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/user_repository.dart'; | |||
| import 'package:farm_tpf/main.dart'; | |||
| @@ -9,6 +10,7 @@ import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.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_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_common.dart'; | |||
| import 'package:farm_tpf/utils/pref.dart'; | |||
| @@ -18,6 +20,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; | |||
| import 'package:farm_tpf/utils/const_string.dart'; | |||
| import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | |||
| import 'package:farm_tpf/utils/formatter.dart'; | |||
| import 'package:get/get.dart'; | |||
| import 'bloc/plot_bloc.dart'; | |||
| @@ -53,9 +56,13 @@ class _PlotListScreenState extends State<PlotListScreen> { | |||
| onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler, | |||
| onLaunch: (Map<String, dynamic> message) async { | |||
| print("onLaunch: $message"); | |||
| Future.delayed(Duration(milliseconds: 500), () { | |||
| _notificationNavigateOnFCM(message); | |||
| }); | |||
| }, | |||
| onResume: (Map<String, dynamic> message) async { | |||
| print("onResume: $message"); | |||
| _notificationNavigateOnFCM(message); | |||
| }, | |||
| ); | |||
| _firebaseMessaging.requestNotificationPermissions( | |||
| @@ -90,6 +97,28 @@ class _PlotListScreenState extends State<PlotListScreen> { | |||
| } | |||
| } | |||
| _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 | |||
| void initState() { | |||
| super.initState(); | |||