| @@ -1 +1 @@ | |||
| 440505e9ea1eee7043d2cbfeb318f6bc | |||
| 48197743e3d78b3769f70bac9a76e7e0 | |||
| @@ -1,4 +1,3 @@ | |||
| import 'package:farm_tpf/presentation/screens/home/view/home_page.dart'; | |||
| import 'package:farm_tpf/presentation/screens/login/view/login_page.dart'; | |||
| import 'package:farm_tpf/presentation/screens/slide_menu/navigation_home_screen.dart'; | |||
| import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart'; | |||
| @@ -8,6 +8,7 @@ class NotificationDTO { | |||
| String createdDate; | |||
| String sendDate; | |||
| int isRead; | |||
| int type; | |||
| NotificationDTO( | |||
| {this.id, | |||
| @@ -18,6 +19,7 @@ class NotificationDTO { | |||
| this.contents, | |||
| this.createdDate, | |||
| this.sendDate, | |||
| this.type, | |||
| this.isRead}); | |||
| NotificationDTO.clone(NotificationDTO noti) { | |||
| this.id = noti.id; | |||
| @@ -28,6 +30,7 @@ class NotificationDTO { | |||
| this.message = noti.message; | |||
| this.createdDate = noti.createdDate; | |||
| this.sendDate = noti.sendDate; | |||
| this.type = noti.type; | |||
| this.isRead = noti.isRead; | |||
| } | |||
| NotificationDTO.fromJson(Map<String, dynamic> json) { | |||
| @@ -39,6 +42,7 @@ class NotificationDTO { | |||
| contents = json['contents']; | |||
| createdDate = json['createdDate']; | |||
| sendDate = json['sendDate']; | |||
| type = json['type']; | |||
| isRead = json['isRead']; | |||
| } | |||
| @@ -52,6 +56,7 @@ class NotificationDTO { | |||
| data['contents'] = this.contents; | |||
| data['createdDate'] = this.createdDate; | |||
| data['sendDate'] = this.sendDate; | |||
| data['type'] = this.type; | |||
| data['isRead'] = this.isRead; | |||
| return data; | |||
| } | |||
| @@ -84,6 +84,7 @@ _showAlertCheckCropCode( | |||
| if (Get.isDialogOpen) Get.back(); | |||
| Get.to(PlotDetailScreen( | |||
| cropId: value.tbCropDTO.id, | |||
| cropType: value.tbCropDTO.type, | |||
| initialIndex: 1, | |||
| )); | |||
| }).catchError((onError) { | |||
| @@ -1 +0,0 @@ | |||
| export 'view/home_page.dart'; | |||
| @@ -1,125 +0,0 @@ | |||
| import 'dart:io'; | |||
| import 'package:dio/dio.dart'; | |||
| import 'package:farm_tpf/data/repository/user_repository.dart'; | |||
| import 'package:farm_tpf/main.dart'; | |||
| import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart'; | |||
| import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; | |||
| import 'package:farm_tpf/presentation/screens/resources/sc_resource_helper.dart'; | |||
| import 'package:farm_tpf/utils/const_common.dart'; | |||
| import 'package:farm_tpf/utils/pref.dart'; | |||
| import 'package:firebase_messaging/firebase_messaging.dart'; | |||
| import 'package:flutter/material.dart'; | |||
| class HomePage extends StatefulWidget { | |||
| static Route route() { | |||
| return MaterialPageRoute<void>(builder: (_) => HomePage()); | |||
| } | |||
| @override | |||
| _HomePageState createState() => _HomePageState(); | |||
| } | |||
| class _HomePageState extends State<HomePage> { | |||
| UserRepository _userRepository = UserRepository(); | |||
| final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); | |||
| var pref = LocalPref(); | |||
| var token; | |||
| var client; | |||
| String pushkey = ""; | |||
| Future<Null> getSharedPrefs() async { | |||
| token = await pref.getString(DATA_CONST.TOKEN_KEY); | |||
| pushkey = await pref.getString(DATA_CONST.PUSH_KEY); | |||
| var options = BaseOptions(baseUrl: ConstCommon.baseUrl); | |||
| options.headers["Authorization"] = "Bearer $token"; | |||
| client = Dio(options); | |||
| if (Platform.isIOS) { | |||
| _firebaseMessaging | |||
| .requestNotificationPermissions(IosNotificationSettings()); | |||
| } | |||
| _firebaseMessaging.configure( | |||
| onMessage: (Map<String, dynamic> message) async { | |||
| print("onMessage: $message"); | |||
| }, | |||
| onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler, | |||
| onLaunch: (Map<String, dynamic> message) async { | |||
| print("onLaunch: $message"); | |||
| }, | |||
| onResume: (Map<String, dynamic> message) async { | |||
| print("onResume: $message"); | |||
| }, | |||
| ); | |||
| _firebaseMessaging.requestNotificationPermissions( | |||
| const IosNotificationSettings( | |||
| sound: true, badge: true, alert: true, provisional: true)); | |||
| _firebaseMessaging.onIosSettingsRegistered | |||
| .listen((IosNotificationSettings settings) { | |||
| print("Settings registered: $settings"); | |||
| }); | |||
| if (pushkey?.isEmpty ?? true) { | |||
| _firebaseMessaging.getToken().then((String token) { | |||
| assert(token != null); | |||
| print("Push Messaging token: $token"); | |||
| _userRepository.updateFcmToken(token).then((value) { | |||
| print("send push key successful"); | |||
| pref.saveString(DATA_CONST.PUSH_KEY, token); | |||
| }); | |||
| // client.put(""); | |||
| }); | |||
| } else { | |||
| print("Don't need get push key"); | |||
| } | |||
| } | |||
| @override | |||
| void initState() { | |||
| super.initState(); | |||
| getSharedPrefs(); | |||
| } | |||
| @override | |||
| Widget build(BuildContext context) { | |||
| return Scaffold( | |||
| appBar: AppBar(title: const Text('Home')), | |||
| body: Center( | |||
| child: Column( | |||
| mainAxisSize: MainAxisSize.min, | |||
| children: <Widget>[ | |||
| Text("logged in."), | |||
| MaterialButton( | |||
| child: Text("Chi tiết lô"), | |||
| onPressed: () { | |||
| Navigator.of(context).push(MaterialPageRoute( | |||
| builder: (_) => PlotDetailScreen( | |||
| cropId: 1, | |||
| ))); | |||
| }), | |||
| MaterialButton( | |||
| child: Text("Danh sách lô"), | |||
| onPressed: () { | |||
| Navigator.of(context).push( | |||
| MaterialPageRoute(builder: (_) => PlotListScreen())); | |||
| }), | |||
| MaterialButton( | |||
| child: Text("ResourceHelperScreen"), | |||
| onPressed: () { | |||
| Navigator.of(context) | |||
| .push(MaterialPageRoute( | |||
| builder: (_) => ResourceHelperScreen( | |||
| titleName: "phân bón", | |||
| type: ConstCommon.supplyTypeDung, | |||
| selectedId: 3, | |||
| ), | |||
| fullscreenDialog: false)) | |||
| .then((value) { | |||
| if (value != null) { | |||
| print("Home: $value"); | |||
| } | |||
| }); | |||
| }), | |||
| ], | |||
| ), | |||
| ), | |||
| ); | |||
| } | |||
| } | |||
| @@ -154,6 +154,7 @@ class _InfinityViewState extends State<InfinityView> { | |||
| return index >= state.items.length | |||
| ? BottomLoader() | |||
| : ItemInfinityWidget( | |||
| notiBloc: widget.notiBloc, | |||
| unread: state.unread, | |||
| read: state.read, | |||
| currentItems: currentItems, | |||
| @@ -234,6 +235,7 @@ class ItemInfinityWidget extends StatelessWidget { | |||
| final List<NotificationDTO> currentItems; | |||
| final int currentPage; | |||
| final bool currentReachedMax; | |||
| final NotiBloc notiBloc; | |||
| const ItemInfinityWidget( | |||
| {Key key, | |||
| @@ -242,7 +244,8 @@ class ItemInfinityWidget extends StatelessWidget { | |||
| @required this.currentItems, | |||
| @required this.item, | |||
| @required this.currentPage, | |||
| @required this.currentReachedMax}) | |||
| @required this.currentReachedMax, | |||
| @required this.notiBloc}) | |||
| : super(key: key); | |||
| @override | |||
| @@ -272,8 +275,10 @@ class ItemInfinityWidget extends StatelessWidget { | |||
| Navigator.push( | |||
| context, | |||
| MaterialPageRoute( | |||
| builder: (BuildContext context) => | |||
| PlotDetailScreen(cropId: item.tbCropId))).then((value) { | |||
| builder: (BuildContext context) => PlotDetailScreen( | |||
| cropId: item.tbCropId, | |||
| cropType: item.type, | |||
| ))).then((value) { | |||
| if (item.isRead == 0) { | |||
| _updateReadNotification( | |||
| context: context, | |||
| @@ -323,7 +328,7 @@ class ItemInfinityWidget extends StatelessWidget { | |||
| updatedItems.add(NotificationDTO.clone(e)); | |||
| }); | |||
| BlocProvider.of<NotiBloc>(context).add(OnUpdate<NotificationDTO>( | |||
| notiBloc.add(OnUpdate<NotificationDTO>( | |||
| unread: unread - 1, | |||
| read: read + 1, | |||
| currentItemId: item.id, | |||
| @@ -104,12 +104,16 @@ class _PlotListScreenState extends State<PlotListScreen> { | |||
| var data = message['data']; | |||
| noti = NotificationDTO() | |||
| ..contents = data['contents'] | |||
| ..tbCropId = data['tbCropId']; | |||
| ..tbCropId = data['tbCropId'] | |||
| ..type = data['type']; | |||
| } else { | |||
| noti = NotificationDTO.fromJson(message); | |||
| } | |||
| if (noti.contents == "ENV_UPDATE") { | |||
| Get.to(PlotDetailScreen(cropId: noti.tbCropId)); | |||
| Get.to(PlotDetailScreen( | |||
| cropId: noti.tbCropId, | |||
| cropType: noti.type, | |||
| )); | |||
| } else if (noti.contents == "PIC_UPDATE") { | |||
| Get.to(PlotInformationScreen( | |||
| cropId: noti.tbCropId, | |||
| @@ -13,7 +13,10 @@ class PlotDetailScreen extends StatefulWidget { | |||
| int cropType; | |||
| int initialIndex; | |||
| PlotDetailScreen( | |||
| {this.cropId, this.initialIndex = 0, this.cropCode, this.cropType}); | |||
| {this.cropId, | |||
| this.initialIndex = 0, | |||
| this.cropCode, | |||
| @required this.cropType}); | |||
| @override | |||
| _PlotDetailScreenState createState() => _PlotDetailScreenState(); | |||
| } | |||