Browse Source

fix Bug #7964

master
daivph 5 years ago
parent
commit
0540f37b03
6 changed files with 130 additions and 11 deletions
  1. +1
    -1
      ios/Flutter/.last_build_id
  2. +1
    -1
      lib/custom_model/NotificationDTO.dart
  3. +5
    -5
      lib/data/api/dio_provider.dart
  4. +8
    -2
      lib/presentation/screens/notification/sc_notification.dart
  5. +2
    -2
      lib/presentation/screens/plot/sc_plot.dart
  6. +113
    -0
      lib/presentation/screens/tabbar/tabbar.dart

+ 1
- 1
ios/Flutter/.last_build_id View File

@@ -1 +1 @@
471e09183e20ec9c20cca9b580fecc10
d91c957b2422e26116533c8dae89710a

+ 1
- 1
lib/custom_model/NotificationDTO.dart View File

@@ -8,7 +8,7 @@ class NotificationDTO {
String createdDate;
String sendDate;
int isRead;
int type;
String type;

NotificationDTO(
{this.id,

+ 5
- 5
lib/data/api/dio_provider.dart View File

@@ -26,11 +26,11 @@ class HttpLogInterceptor extends InterceptorsWrapper {
var token = await pref.getString(DATA_CONST.TOKEN_KEY);
options.headers["Authorization"] = "Bearer $token";
options.receiveTimeout = 20000;
log("onRequest: ${options.uri}\n"
"data=${options.data}\n"
"method=${options.method}\n"
"headers=${options.headers}\n"
"queryParameters=${options.queryParameters}");
// log("onRequest: ${options.uri}\n"
// "data=${options.data}\n"
// "method=${options.method}\n"
// "headers=${options.headers}\n"
// "queryParameters=${options.queryParameters}");
return options;
}


+ 8
- 2
lib/presentation/screens/notification/sc_notification.dart View File

@@ -251,6 +251,12 @@ class ItemInfinityWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
var type;
try {
type = int.parse(item.type);
} catch (_) {
type = -1;
}
return Column(
children: [
GestureDetector(
@@ -290,7 +296,7 @@ class ItemInfinityWidget extends StatelessWidget {
context,
MaterialPageRoute(
builder: (BuildContext context) => PlotDetailScreen(
cropType: item.type,
cropType: type,
cropId: item.tbCropId,
initialIndex: 0,
))).then((value) {
@@ -310,7 +316,7 @@ class ItemInfinityWidget extends StatelessWidget {
context,
MaterialPageRoute(
builder: (BuildContext context) => PlotDetailScreen(
cropType: item.type,
cropType: type,
cropId: item.tbCropId,
initialIndex: 1,
))).then((value) {

+ 2
- 2
lib/presentation/screens/plot/sc_plot.dart View File

@@ -50,7 +50,7 @@ class _PlotListScreenState extends State<PlotListScreen> {
}
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print("onMessage: $message");
print("onMessage---: $message");
},
onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
@@ -128,7 +128,7 @@ class _PlotListScreenState extends State<PlotListScreen> {
@override
void initState() {
super.initState();
getSharedPrefs();
// getSharedPrefs();
}

@override

+ 113
- 0
lib/presentation/screens/tabbar/tabbar.dart View File

@@ -1,12 +1,21 @@
import 'dart:io';

import 'package:badges/badges.dart';
import 'package:dio/dio.dart';
import 'package:farm_tpf/custom_model/NotificationDTO.dart';
import 'package:farm_tpf/custom_model/NotificationObjectDTO.dart';
import 'package:farm_tpf/data/repository/user_repository.dart';
import 'package:farm_tpf/presentation/screens/account/sc_account.dart';
import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart';
import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart';
import 'package:farm_tpf/presentation/screens/notification/update_count_noti_bloc.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/utils/const_color.dart';
import 'package:farm_tpf/utils/const_common.dart';
import 'package:farm_tpf/utils/const_icons.dart';
import 'package:farm_tpf/utils/pref.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
@@ -23,6 +32,13 @@ class TabbarScreen extends StatefulWidget {
}

class _TabbarScreenState extends State<TabbarScreen> {
UserRepository _userRepository = UserRepository();
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
var pref = LocalPref();
String pushkey = "";
String currentFullName = "";
var token;
var client;
final changeTabbar = Get.put(TabbarSelected());
List<TabbarItem> itemsTabbar = [
TabbarItem(
@@ -38,13 +54,110 @@ class _TabbarScreenState extends State<TabbarScreen> {
icon: AppIcons.icPerson, title: 'Cá nhân', index: TabBarIndex.account)
];

Future<Null> getSharedPrefs() async {
token = await pref.getString(DATA_CONST.TOKEN_KEY);
pushkey = await pref.getString(DATA_CONST.PUSH_KEY);
currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME);
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");
try {
print('call bloc update noti');
updateCountNotiBloc.getNotifications((data) {}, (err) {});
} catch (e) {
print('error');
print(e);
}
},
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(
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");
}

if (currentFullName?.isEmpty ?? true) {
try {
var currentUser = await _userRepository.getUser();
pref.saveString(DATA_CONST.CURRENT_FULL_NAME, currentUser.fullName);
print("fullname: ${currentUser.fullName}");
} catch (e) {
print("error: ${e.toString()}");
}
}
}

@override
void initState() {
super.initState();
getSharedPrefs();
changeTabbar.initValue();
updateCountNotiBloc.getNotifications((data) {}, (err) {});
}

_notificationNavigateOnFCM(Map<String, dynamic> message) {
try {
final int type = message['tbCropType'];
final String contents = message['contents'];
final int tbCropId = message['tbCropId'];
if (contents == "ENV_UPDATE") {
Get.to(PlotDetailScreen(
cropType: type,
cropId: tbCropId,
initialIndex: 0,
));
} else if (contents == "PIC_UPDATE") {
Get.to(PlotDetailScreen(
cropType: type,
cropId: tbCropId,
initialIndex: 1,
));
} else {
//Go home
}
} catch (e) {
//Go home
}
Get.to(PlotDetailScreen(
cropType: 0,
cropId: 1,
initialIndex: 0,
));
}

Widget textCountNoti() {
return StreamBuilder(
stream: updateCountNotiBloc.actions,

Loading…
Cancel
Save