add pulldown to refresh as true. on refresh get new notifications.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:google_nav_bar/google_nav_bar.dart';
|
import 'package:google_nav_bar/google_nav_bar.dart';
|
||||||
@@ -22,6 +24,7 @@ import 'package:patient_manager/mih_objects/arguments.dart';
|
|||||||
import 'package:patient_manager/mih_objects/business.dart';
|
import 'package:patient_manager/mih_objects/business.dart';
|
||||||
import 'package:patient_manager/mih_objects/business_user.dart';
|
import 'package:patient_manager/mih_objects/business_user.dart';
|
||||||
import 'package:patient_manager/mih_objects/notification.dart';
|
import 'package:patient_manager/mih_objects/notification.dart';
|
||||||
|
import 'package:supertokens_flutter/http.dart' as http;
|
||||||
|
|
||||||
class MIHHome extends StatefulWidget {
|
class MIHHome extends StatefulWidget {
|
||||||
final AppUser signedInUser;
|
final AppUser signedInUser;
|
||||||
@@ -56,9 +59,11 @@ class _MIHHomeState extends State<MIHHome> {
|
|||||||
late List<MIHTile> persHTList = [];
|
late List<MIHTile> persHTList = [];
|
||||||
late List<MIHTile> busHTList = [];
|
late List<MIHTile> busHTList = [];
|
||||||
late List<List<MIHTile>> pbswitch;
|
late List<List<MIHTile>> pbswitch;
|
||||||
|
late List<MIHNotification> notifiList;
|
||||||
late bool businessUserSwitch;
|
late bool businessUserSwitch;
|
||||||
int _selectedIndex = 0;
|
int _selectedIndex = 0;
|
||||||
String appSearch = "";
|
String appSearch = "";
|
||||||
|
int amount = 10;
|
||||||
final baseAPI = AppEnviroment.baseApiUrl;
|
final baseAPI = AppEnviroment.baseApiUrl;
|
||||||
|
|
||||||
void setAppsNewPersonal(List<MIHTile> tileList) {
|
void setAppsNewPersonal(List<MIHTile> tileList) {
|
||||||
@@ -703,14 +708,36 @@ class _MIHHomeState extends State<MIHHome> {
|
|||||||
if (widget.notifications
|
if (widget.notifications
|
||||||
.map((item) => item.notification_read)
|
.map((item) => item.notification_read)
|
||||||
.contains("No")) {
|
.contains("No")) {
|
||||||
print("New Notification Available");
|
//print("New Notification Available");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
print("No New Notification Available");
|
//print("No New Notification Available");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> refreshNotifications() async {
|
||||||
|
var responseNotification = await http.get(Uri.parse(
|
||||||
|
"$baseAPI/notifications/${widget.signedInUser.app_id}?amount=$amount"));
|
||||||
|
List<MIHNotification> notifi;
|
||||||
|
if (responseNotification.statusCode == 200) {
|
||||||
|
String body = responseNotification.body;
|
||||||
|
// var decodedData = jsonDecode(body);
|
||||||
|
// MIHNotification notifications = MIHNotification.fromJson(decodedData);
|
||||||
|
|
||||||
|
Iterable l = jsonDecode(body);
|
||||||
|
//print("Here2");
|
||||||
|
List<MIHNotification> notifications = List<MIHNotification>.from(
|
||||||
|
l.map((model) => MIHNotification.fromJson(model)));
|
||||||
|
notifi = notifications;
|
||||||
|
} else {
|
||||||
|
notifi = [];
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
notifiList = notifi;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
searchController.dispose();
|
searchController.dispose();
|
||||||
@@ -723,6 +750,7 @@ class _MIHHomeState extends State<MIHHome> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
pbswitch = setApps(persHTList, busHTList);
|
pbswitch = setApps(persHTList, busHTList);
|
||||||
businessUserSwitch = false;
|
businessUserSwitch = false;
|
||||||
|
notifiList = widget.notifications;
|
||||||
});
|
});
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -742,6 +770,8 @@ class _MIHHomeState extends State<MIHHome> {
|
|||||||
actionDrawer: getActionDrawer(),
|
actionDrawer: getActionDrawer(),
|
||||||
secondaryActionDrawer: getSecondaryActionDrawer(),
|
secondaryActionDrawer: getSecondaryActionDrawer(),
|
||||||
bottomNavBar: getBottomNavBar(),
|
bottomNavBar: getBottomNavBar(),
|
||||||
|
pullDownToRefresh: true,
|
||||||
|
onPullDown: refreshNotifications,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user