Browse Source

fix bug Bug #7813

master
daivph 5 years ago
parent
commit
f9c6016a9e
9 changed files with 26 additions and 135 deletions
  1. +1
    -1
      ios/Flutter/.last_build_id
  2. +0
    -1
      lib/app.dart
  3. +5
    -0
      lib/custom_model/NotificationDTO.dart
  4. +1
    -0
      lib/main.dart
  5. +0
    -1
      lib/presentation/screens/home/home.dart
  6. +0
    -125
      lib/presentation/screens/home/view/home_page.dart
  7. +9
    -4
      lib/presentation/screens/notification/sc_notification.dart
  8. +6
    -2
      lib/presentation/screens/plot/sc_plot.dart
  9. +4
    -1
      lib/presentation/screens/plot_detail/sc_plot_detail.dart

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

440505e9ea1eee7043d2cbfeb318f6bc
48197743e3d78b3769f70bac9a76e7e0

+ 0
- 1
lib/app.dart View File

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/login/view/login_page.dart';
import 'package:farm_tpf/presentation/screens/slide_menu/navigation_home_screen.dart'; import 'package:farm_tpf/presentation/screens/slide_menu/navigation_home_screen.dart';
import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart'; import 'package:farm_tpf/presentation/screens/splash/view/splash_page.dart';

+ 5
- 0
lib/custom_model/NotificationDTO.dart View File

String createdDate; String createdDate;
String sendDate; String sendDate;
int isRead; int isRead;
int type;


NotificationDTO( NotificationDTO(
{this.id, {this.id,
this.contents, this.contents,
this.createdDate, this.createdDate,
this.sendDate, this.sendDate,
this.type,
this.isRead}); this.isRead});
NotificationDTO.clone(NotificationDTO noti) { NotificationDTO.clone(NotificationDTO noti) {
this.id = noti.id; this.id = noti.id;
this.message = noti.message; this.message = noti.message;
this.createdDate = noti.createdDate; this.createdDate = noti.createdDate;
this.sendDate = noti.sendDate; this.sendDate = noti.sendDate;
this.type = noti.type;
this.isRead = noti.isRead; this.isRead = noti.isRead;
} }
NotificationDTO.fromJson(Map<String, dynamic> json) { NotificationDTO.fromJson(Map<String, dynamic> json) {
contents = json['contents']; contents = json['contents'];
createdDate = json['createdDate']; createdDate = json['createdDate'];
sendDate = json['sendDate']; sendDate = json['sendDate'];
type = json['type'];
isRead = json['isRead']; isRead = json['isRead'];
} }


data['contents'] = this.contents; data['contents'] = this.contents;
data['createdDate'] = this.createdDate; data['createdDate'] = this.createdDate;
data['sendDate'] = this.sendDate; data['sendDate'] = this.sendDate;
data['type'] = this.type;
data['isRead'] = this.isRead; data['isRead'] = this.isRead;
return data; return data;
} }

+ 1
- 0
lib/main.dart View File

if (Get.isDialogOpen) Get.back(); if (Get.isDialogOpen) Get.back();
Get.to(PlotDetailScreen( Get.to(PlotDetailScreen(
cropId: value.tbCropDTO.id, cropId: value.tbCropDTO.id,
cropType: value.tbCropDTO.type,
initialIndex: 1, initialIndex: 1,
)); ));
}).catchError((onError) { }).catchError((onError) {

+ 0
- 1
lib/presentation/screens/home/home.dart View File

export 'view/home_page.dart';

+ 0
- 125
lib/presentation/screens/home/view/home_page.dart View File

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");
}
});
}),
],
),
),
);
}
}

+ 9
- 4
lib/presentation/screens/notification/sc_notification.dart View File

return index >= state.items.length return index >= state.items.length
? BottomLoader() ? BottomLoader()
: ItemInfinityWidget( : ItemInfinityWidget(
notiBloc: widget.notiBloc,
unread: state.unread, unread: state.unread,
read: state.read, read: state.read,
currentItems: currentItems, currentItems: currentItems,
final List<NotificationDTO> currentItems; final List<NotificationDTO> currentItems;
final int currentPage; final int currentPage;
final bool currentReachedMax; final bool currentReachedMax;
final NotiBloc notiBloc;


const ItemInfinityWidget( const ItemInfinityWidget(
{Key key, {Key key,
@required this.currentItems, @required this.currentItems,
@required this.item, @required this.item,
@required this.currentPage, @required this.currentPage,
@required this.currentReachedMax})
@required this.currentReachedMax,
@required this.notiBloc})
: super(key: key); : super(key: key);


@override @override
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( 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) { if (item.isRead == 0) {
_updateReadNotification( _updateReadNotification(
context: context, context: context,
updatedItems.add(NotificationDTO.clone(e)); updatedItems.add(NotificationDTO.clone(e));
}); });


BlocProvider.of<NotiBloc>(context).add(OnUpdate<NotificationDTO>(
notiBloc.add(OnUpdate<NotificationDTO>(
unread: unread - 1, unread: unread - 1,
read: read + 1, read: read + 1,
currentItemId: item.id, currentItemId: item.id,

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

var data = message['data']; var data = message['data'];
noti = NotificationDTO() noti = NotificationDTO()
..contents = data['contents'] ..contents = data['contents']
..tbCropId = data['tbCropId'];
..tbCropId = data['tbCropId']
..type = data['type'];
} else { } else {
noti = NotificationDTO.fromJson(message); noti = NotificationDTO.fromJson(message);
} }
if (noti.contents == "ENV_UPDATE") { 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") { } else if (noti.contents == "PIC_UPDATE") {
Get.to(PlotInformationScreen( Get.to(PlotInformationScreen(
cropId: noti.tbCropId, cropId: noti.tbCropId,

+ 4
- 1
lib/presentation/screens/plot_detail/sc_plot_detail.dart View File

int cropType; int cropType;
int initialIndex; int initialIndex;
PlotDetailScreen( PlotDetailScreen(
{this.cropId, this.initialIndex = 0, this.cropCode, this.cropType});
{this.cropId,
this.initialIndex = 0,
this.cropCode,
@required this.cropType});
@override @override
_PlotDetailScreenState createState() => _PlotDetailScreenState(); _PlotDetailScreenState createState() => _PlotDetailScreenState();
} }

Loading…
Cancel
Save