|
|
|
@@ -1,14 +1,18 @@ |
|
|
|
import 'package:farm_tpf/custom_model/NotificationDTO.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/dash_line_widget.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.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_icons.dart'; |
|
|
|
import 'package:farm_tpf/utils/pref.dart'; |
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
import 'package:farm_tpf/utils/formatter.dart'; |
|
|
|
import 'package:flutter_svg/svg.dart'; |
|
|
|
|
|
|
|
import 'bloc/noti_bloc.dart'; |
|
|
|
|
|
|
|
@@ -55,29 +59,8 @@ class HoldInfinityWidget extends StatelessWidget { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return Scaffold( |
|
|
|
key: _scaffoldKey, |
|
|
|
appBar: AppBar( |
|
|
|
centerTitle: true, |
|
|
|
title: Text("Thông báo"), |
|
|
|
actions: <Widget>[ |
|
|
|
BlocBuilder<NotiBloc, NotiState>( |
|
|
|
cubit: notiBloc, |
|
|
|
builder: (context, state) { |
|
|
|
if (state is NotiSuccess) { |
|
|
|
if (state.items.length > 0) { |
|
|
|
return IconButton( |
|
|
|
icon: Icon(Icons.done_all), |
|
|
|
onPressed: () { |
|
|
|
notiBloc.add(MarkAllNotificationUpdate(status: "1")); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return SizedBox(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return SizedBox(); |
|
|
|
} |
|
|
|
}, |
|
|
|
) |
|
|
|
], |
|
|
|
appBar: AppBarWidget( |
|
|
|
isBack: false, |
|
|
|
), |
|
|
|
body: BlocBuilder<NotiBloc, NotiState>( |
|
|
|
cubit: notiBloc, |
|
|
|
@@ -107,7 +90,6 @@ class _InfinityViewState extends State<InfinityView> { |
|
|
|
bool isUpdatingFromApi = true; |
|
|
|
|
|
|
|
var pref = LocalPref(); |
|
|
|
// final SocketService socketService = injector.get<SocketService>(); |
|
|
|
var token; |
|
|
|
Future<Null> getSharedPrefs() async { |
|
|
|
_scrollController.addListener(() { |
|
|
|
@@ -144,9 +126,41 @@ class _InfinityViewState extends State<InfinityView> { |
|
|
|
return Column( |
|
|
|
children: <Widget>[ |
|
|
|
Container( |
|
|
|
child: |
|
|
|
countNotification(unread: state.unread, read: state.read), |
|
|
|
), |
|
|
|
padding: EdgeInsets.all(8), |
|
|
|
color: Colors.white, |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
'Thông báo', |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.w500, fontSize: 22), |
|
|
|
)), |
|
|
|
BlocBuilder<NotiBloc, NotiState>( |
|
|
|
cubit: widget.notiBloc, |
|
|
|
builder: (context, state) { |
|
|
|
if (state is NotiSuccess) { |
|
|
|
if (state.items.length > 0) { |
|
|
|
return FlatButton( |
|
|
|
onPressed: () { |
|
|
|
widget.notiBloc.add( |
|
|
|
MarkAllNotificationUpdate(status: "1")); |
|
|
|
}, |
|
|
|
child: Text('Đánh dấu đã đọc tất cả', |
|
|
|
style: TextStyle( |
|
|
|
fontWeight: FontWeight.normal, |
|
|
|
fontSize: 14, |
|
|
|
color: Colors.blue))); |
|
|
|
} else { |
|
|
|
return SizedBox(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
return SizedBox(); |
|
|
|
} |
|
|
|
}, |
|
|
|
) |
|
|
|
], |
|
|
|
)), |
|
|
|
Expanded( |
|
|
|
child: RefreshIndicator( |
|
|
|
child: ListView.builder( |
|
|
|
@@ -183,47 +197,9 @@ class _InfinityViewState extends State<InfinityView> { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget countNotification({num unread, num read}) { |
|
|
|
return Container( |
|
|
|
child: Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
mainAxisSize: MainAxisSize.max, |
|
|
|
children: <Widget>[ |
|
|
|
Expanded( |
|
|
|
child: OutlineButton( |
|
|
|
child: RichText( |
|
|
|
text: TextSpan( |
|
|
|
text: "Chưa đọc ", |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.black, fontWeight: FontWeight.bold), |
|
|
|
children: <TextSpan>[ |
|
|
|
TextSpan( |
|
|
|
text: "($unread)", |
|
|
|
style: TextStyle(color: Colors.blue)), |
|
|
|
])), |
|
|
|
onPressed: () {})), |
|
|
|
Expanded( |
|
|
|
child: OutlineButton( |
|
|
|
child: RichText( |
|
|
|
text: TextSpan( |
|
|
|
text: "Đã đọc ", |
|
|
|
style: TextStyle( |
|
|
|
color: Colors.black, fontWeight: FontWeight.bold), |
|
|
|
children: <TextSpan>[ |
|
|
|
TextSpan( |
|
|
|
text: "($read)", |
|
|
|
style: TextStyle(color: Colors.grey)), |
|
|
|
])), |
|
|
|
onPressed: () {})) |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
void dispose() { |
|
|
|
_scrollController.dispose(); |
|
|
|
// socketService.disconnect(); |
|
|
|
super.dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
@@ -250,66 +226,85 @@ class ItemInfinityWidget extends StatelessWidget { |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return GestureDetector( |
|
|
|
child: Card( |
|
|
|
margin: EdgeInsets.all(4.0), |
|
|
|
child: ListTile( |
|
|
|
title: Text(item.subject), |
|
|
|
subtitle: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: <Widget>[ |
|
|
|
Text(item.message), |
|
|
|
Text( |
|
|
|
item.sendDate.format_DDMMYY_HHmm(), |
|
|
|
style: TextStyle( |
|
|
|
color: item.isRead == 1 ? Colors.grey : Colors.blue), |
|
|
|
), |
|
|
|
return Column( |
|
|
|
children: [ |
|
|
|
GestureDetector( |
|
|
|
child: Container( |
|
|
|
margin: EdgeInsets.all(4.0), |
|
|
|
child: Column( |
|
|
|
children: [ |
|
|
|
ListTile( |
|
|
|
title: Text(item.subject), |
|
|
|
subtitle: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: <Widget>[ |
|
|
|
Text(item.message), |
|
|
|
Row(children: [ |
|
|
|
Icon(Icons.access_time, |
|
|
|
color: item.isRead == 1 |
|
|
|
? Colors.grey |
|
|
|
: Colors.blue, |
|
|
|
size: 18), |
|
|
|
SizedBox( |
|
|
|
width: 4, |
|
|
|
), |
|
|
|
Text(item.sendDate.format_DDMMYY_HHmm(), |
|
|
|
style: TextStyle( |
|
|
|
color: item.isRead == 1 |
|
|
|
? Colors.grey |
|
|
|
: Colors.blue)) |
|
|
|
]), |
|
|
|
], |
|
|
|
), |
|
|
|
leading: SvgPicture.asset(AppIcons.icNotificationItem)), |
|
|
|
], |
|
|
|
), |
|
|
|
leading: Icon( |
|
|
|
Icons.notifications_active, |
|
|
|
color: item.isRead == 1 ? Colors.grey : Colors.blue, |
|
|
|
))), |
|
|
|
onTap: () { |
|
|
|
if (item.contents == "ENV_UPDATE") { |
|
|
|
Navigator.push( |
|
|
|
context, |
|
|
|
MaterialPageRoute( |
|
|
|
builder: (BuildContext context) => PlotDetailScreen( |
|
|
|
cropId: item.tbCropId, |
|
|
|
cropType: item.type, |
|
|
|
))).then((value) { |
|
|
|
if (item.isRead == 0) { |
|
|
|
_updateReadNotification( |
|
|
|
context: context, |
|
|
|
unread: unread, |
|
|
|
read: read, |
|
|
|
item: item, |
|
|
|
currentItems: currentItems, |
|
|
|
currentPage: currentPage, |
|
|
|
currentReachedMax: currentReachedMax); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (item.contents == "PIC_UPDATE") { |
|
|
|
Navigator.push( |
|
|
|
context, |
|
|
|
MaterialPageRoute( |
|
|
|
builder: (BuildContext context) => PlotInformationScreen( |
|
|
|
cropId: item.tbCropId, |
|
|
|
))).then((value) { |
|
|
|
if (item.isRead == 0) { |
|
|
|
_updateReadNotification( |
|
|
|
context: context, |
|
|
|
unread: unread, |
|
|
|
read: read, |
|
|
|
item: item, |
|
|
|
currentItems: currentItems, |
|
|
|
currentPage: currentPage, |
|
|
|
currentReachedMax: currentReachedMax); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else {} |
|
|
|
}); |
|
|
|
)), |
|
|
|
onTap: () { |
|
|
|
if (item.contents == "ENV_UPDATE") { |
|
|
|
Navigator.push( |
|
|
|
context, |
|
|
|
MaterialPageRoute( |
|
|
|
builder: (BuildContext context) => PlotDetailScreen( |
|
|
|
cropId: item.tbCropId, |
|
|
|
cropType: item.type, |
|
|
|
))).then((value) { |
|
|
|
if (item.isRead == 0) { |
|
|
|
_updateReadNotification( |
|
|
|
context: context, |
|
|
|
unread: unread, |
|
|
|
read: read, |
|
|
|
item: item, |
|
|
|
currentItems: currentItems, |
|
|
|
currentPage: currentPage, |
|
|
|
currentReachedMax: currentReachedMax); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (item.contents == "PIC_UPDATE") { |
|
|
|
Navigator.push( |
|
|
|
context, |
|
|
|
MaterialPageRoute( |
|
|
|
builder: (BuildContext context) => |
|
|
|
PlotInformationScreen( |
|
|
|
cropId: item.tbCropId, |
|
|
|
))).then((value) { |
|
|
|
if (item.isRead == 0) { |
|
|
|
_updateReadNotification( |
|
|
|
context: context, |
|
|
|
unread: unread, |
|
|
|
read: read, |
|
|
|
item: item, |
|
|
|
currentItems: currentItems, |
|
|
|
currentPage: currentPage, |
|
|
|
currentReachedMax: currentReachedMax); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else {} |
|
|
|
}), |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.only(left: 16, right: 16), |
|
|
|
child: DashLineWidget()) |
|
|
|
], |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
_updateReadNotification( |