take in business user and business as parameters

This commit is contained in:
2024-08-08 13:17:07 +02:00
parent b2edd63e78
commit 446d093e26

View File

@@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_nav_bar/google_nav_bar.dart'; import 'package:google_nav_bar/google_nav_bar.dart';
import 'package:patient_manager/components/homeTile.dart'; import 'package:patient_manager/components/homeTile.dart';
@@ -12,14 +10,18 @@ import 'package:patient_manager/env/env.dart';
import 'package:patient_manager/main.dart'; import 'package:patient_manager/main.dart';
import 'package:patient_manager/objects/appUser.dart'; import 'package:patient_manager/objects/appUser.dart';
import 'package:patient_manager/objects/arguments.dart'; import 'package:patient_manager/objects/arguments.dart';
import 'package:patient_manager/objects/business.dart';
import 'package:patient_manager/objects/businessUser.dart'; import 'package:patient_manager/objects/businessUser.dart';
import 'package:supertokens_flutter/http.dart' as http;
class HomeTileGrid extends StatefulWidget { class HomeTileGrid extends StatefulWidget {
final AppUser signedInUser; final AppUser signedInUser;
final BusinessUser? businessUser;
final Business? business;
const HomeTileGrid({ const HomeTileGrid({
super.key, super.key,
required this.signedInUser, required this.signedInUser,
required this.businessUser,
required this.business,
}); });
@override @override
@@ -30,24 +32,39 @@ class _HomeTileGridState extends State<HomeTileGrid> {
late List<List<dynamic>> personalTileList = []; late List<List<dynamic>> personalTileList = [];
late List<List<dynamic>> businessTileList = []; late List<List<dynamic>> businessTileList = [];
late List<List<dynamic>> devTileList = []; late List<List<dynamic>> devTileList = [];
List<List<List<dynamic>>> pbswitch = []; late Future<List<List<List<dynamic>>>> pbswitch;
int _selectedIndex = 0; int _selectedIndex = 0;
final baseAPI = AppEnviroment.baseApiUrl; final baseAPI = AppEnviroment.baseApiUrl;
late Future<BusinessUser?> futureBusinessUser; // late Future<BusinessUser?> futureBusinessUser;
BusinessUser? businessUser; // late Future<Business?> futureBusiness;
// late BusinessUser? businessUser;
// late Business? business;
Future<BusinessUser?> getBusinessUserDetails() async { // Future<BusinessUser?> getBusinessUserDetails() async {
var response = await http // var response = await http
.get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}")); // .get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}"));
if (response.statusCode == 200) { // if (response.statusCode == 200) {
String body = response.body; // String body = response.body;
var decodedData = jsonDecode(body); // var decodedData = jsonDecode(body);
BusinessUser business_User = BusinessUser.fromJson(decodedData); // BusinessUser business_User = BusinessUser.fromJson(decodedData);
return business_User; // return business_User;
} else { // } else {
return null; // return null;
} // }
} // }
// Future<Business?> getBusinessDetails() async {
// var response = await http.get(
// Uri.parse("$baseAPI/business/app_id/${widget.signedInUser.app_id}"));
// if (response.statusCode == 200) {
// String body = response.body;
// var decodedData = jsonDecode(body);
// Business business = Business.fromJson(decodedData);
// return business;
// } else {
// return null;
// }
// }
void setAppsNewPersonal(List<List<dynamic>> tileList) { void setAppsNewPersonal(List<List<dynamic>> tileList) {
if (widget.signedInUser.fname == "") { if (widget.signedInUser.fname == "") {
@@ -97,6 +114,7 @@ class _HomeTileGridState extends State<HomeTileGrid> {
} }
void setAppsBusiness(List<List<dynamic>> tileList) { void setAppsBusiness(List<List<dynamic>> tileList) {
if (widget.businessUser!.access == "Full") {
tileList.add( tileList.add(
[ [
Icons.business, Icons.business,
@@ -111,6 +129,8 @@ class _HomeTileGridState extends State<HomeTileGrid> {
} }
], ],
); );
}
if (widget.business!.type == "Doctors Office") {
tileList.add( tileList.add(
[ [
Icons.medication, Icons.medication,
@@ -124,6 +144,7 @@ class _HomeTileGridState extends State<HomeTileGrid> {
], ],
); );
} }
}
void setAppsDev(List<List<dynamic>> tileList) { void setAppsDev(List<List<dynamic>> tileList) {
if (AppEnviroment.getEnv() == "Dev") { if (AppEnviroment.getEnv() == "Dev") {
@@ -204,16 +225,17 @@ class _HomeTileGridState extends State<HomeTileGrid> {
} }
} }
Future<void> setApps(List<List<dynamic>> personalTileList, Future<List<List<List<dynamic>>>> setApps(
List<List<dynamic>> personalTileList,
List<List<dynamic>> businessTileList) async { List<List<dynamic>> businessTileList) async {
//print(businessUser); //print(widget.businessUser);
if (widget.signedInUser.fname == "") { if (widget.signedInUser.fname == "") {
//print("New personal user"); //print("New personal user");
setAppsNewPersonal(personalTileList); setAppsNewPersonal(personalTileList);
} else if (widget.signedInUser.type == "personal") { } else if (widget.signedInUser.type == "personal") {
//print("existing personal user"); //print("existing personal user");
setAppsPersonal(personalTileList); setAppsPersonal(personalTileList);
} else if (businessUser == null) { } else if (widget.businessUser == null) {
//print("new business user"); //print("new business user");
setAppsPersonal(personalTileList); setAppsPersonal(personalTileList);
setAppsNewBusiness(businessTileList); setAppsNewBusiness(businessTileList);
@@ -228,8 +250,9 @@ class _HomeTileGridState extends State<HomeTileGrid> {
setAppsDev(personalTileList); setAppsDev(personalTileList);
setAppsDev(businessTileList); setAppsDev(businessTileList);
} }
pbswitch.add(personalTileList); return [personalTileList, businessTileList];
pbswitch.add(businessTileList); // pbswitch.add(personalTileList);
// pbswitch.add(businessTileList);
} }
Color getPrim() { Color getPrim() {
@@ -264,15 +287,7 @@ class _HomeTileGridState extends State<HomeTileGrid> {
@override @override
void initState() { void initState() {
futureBusinessUser = getBusinessUserDetails().then((results) { pbswitch = setApps(personalTileList, businessTileList);
//print(results);
setState(() {
businessUser = results;
setApps(personalTileList, businessTileList);
});
return null;
});
super.initState(); super.initState();
} }
@@ -282,32 +297,44 @@ class _HomeTileGridState extends State<HomeTileGrid> {
double width = size.width; double width = size.width;
double height = size.height; double height = size.height;
return FutureBuilder( // return FutureBuilder(
future: futureBusinessUser, // future: getBusinessDetails(),
builder: (BuildContext context, AsyncSnapshot<BusinessUser?> snapshot) { // builder: (BuildContext context, AsyncSnapshot<Business?> snapshot) {
if (snapshot.connectionState == ConnectionState.done) { // if (snapshot.connectionState == ConnectionState.done &&
// pbswitch.isNotEmpty) {
return Scaffold( return Scaffold(
appBar: const MIHAppBar(barTitle: "Mzansi Innovation Hub"), appBar: const MIHAppBar(barTitle: "Mzansi Innovation Hub"),
drawer: MIHAppDrawer( drawer: MIHAppDrawer(
signedInUser: widget.signedInUser, signedInUser: widget.signedInUser,
logo: MzanziInnovationHub.of(context)!.theme.logoImage(), //logo, logo: MzanziInnovationHub.of(context)!.theme.logoImage(), //logo,
), ),
body: Container( body: FutureBuilder(
future: pbswitch,
builder: (ctx, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
var apps = snapshot.requireData;
return Container(
width: width, width: width,
height: height, height: height,
child: GridView.builder( child: GridView.builder(
padding: EdgeInsets.fromLTRB(width / 6, height / 16, width / 6, padding: EdgeInsets.fromLTRB(width / 6, height / 16, width / 6,
0), //EdgeInsets.symmetric(horizontal: width / 6), 0), //EdgeInsets.symmetric(horizontal: width / 6),
itemCount: pbswitch[_selectedIndex].length, itemCount: apps[_selectedIndex].length,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200), maxCrossAxisExtent: 200),
//const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), //const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (context, index) { itemBuilder: (context, index) {
var tile = pbswitch[_selectedIndex][index]; var tile = apps[_selectedIndex][index];
//setState(() {}); //setState(() {});
return buildtile(tile); return buildtile(tile);
}, },
), ),
);
}
return const Center(
child: CircularProgressIndicator(),
);
},
), ),
bottomNavigationBar: Visibility( bottomNavigationBar: Visibility(
visible: isBusinessUser(widget.signedInUser), visible: isBusinessUser(widget.signedInUser),
@@ -315,11 +342,9 @@ class _HomeTileGridState extends State<HomeTileGrid> {
padding: const EdgeInsets.all(15.0), padding: const EdgeInsets.all(15.0),
child: GNav( child: GNav(
//hoverColor: Colors.lightBlueAccent, //hoverColor: Colors.lightBlueAccent,
color: color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
iconSize: 35.0, iconSize: 35.0,
activeColor: activeColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
MzanziInnovationHub.of(context)!.theme.primaryColor(),
tabBackgroundColor: tabBackgroundColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(), MzanziInnovationHub.of(context)!.theme.secondaryColor(),
//gap: 20, //gap: 20,
@@ -349,11 +374,11 @@ class _HomeTileGridState extends State<HomeTileGrid> {
), ),
), ),
); );
} // }
return const Center( // return const Center(
child: CircularProgressIndicator(), // child: CircularProgressIndicator(),
); // );
}, // },
); // );
} }
} }