cater for new business and business tab

This commit is contained in:
2024-08-06 16:42:14 +02:00
parent 26f3e6309b
commit c90eaf2bc0

View File

@@ -1,3 +1,5 @@
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';
@@ -9,6 +11,8 @@ import 'package:patient_manager/components/mySuccessMessage.dart';
import 'package:patient_manager/env/env.dart'; 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/businessUser.dart';
import 'package:supertokens_flutter/http.dart' as http;
class HomeTileGrid extends StatefulWidget { class HomeTileGrid extends StatefulWidget {
final AppUser signedInUser; final AppUser signedInUser;
@@ -27,13 +31,40 @@ class _HomeTileGridState extends State<HomeTileGrid> {
late List<List<dynamic>> devTileList = []; late List<List<dynamic>> devTileList = [];
List<List<List<dynamic>>> pbswitch = []; List<List<List<dynamic>>> pbswitch = [];
int _selectedIndex = 0; int _selectedIndex = 0;
final baseAPI = AppEnviroment.baseApiUrl;
late Future<BusinessUser?> futureBusinessUser;
BusinessUser? businessUser;
Future<BusinessUser?> getBusinessUserDetails() async {
//print("pat man drawer: " + endpointUserData + widget.userEmail);
//var uid = await SuperTokens.getUserId();
var response = await http
.get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}"));
// print(response.statusCode);
// print(response.body);
if (response.statusCode == 200) {
// print("here");
String body = response.body;
var decodedData = jsonDecode(body);
BusinessUser business_User = BusinessUser.fromJson(decodedData);
// print(u.email);
//setState(() {
//_widgetOptions = setLayout(u);
//});
print("in api call: $business_User");
return business_User;
} else {
return null;
}
}
void setAppsNewPersonal(List<List<dynamic>> tileList) { void setAppsNewPersonal(List<List<dynamic>> tileList) {
if (widget.signedInUser.fname == "") { if (widget.signedInUser.fname == "") {
tileList.add( tileList.add(
[ [
Icons.perm_identity, Icons.perm_identity,
"Update Profie", "Setup Profie",
() { () {
Navigator.of(context) Navigator.of(context)
.pushNamed('/profile', arguments: widget.signedInUser); .pushNamed('/profile', arguments: widget.signedInUser);
@@ -45,6 +76,23 @@ class _HomeTileGridState extends State<HomeTileGrid> {
} }
} }
void setAppsNewBusiness(List<List<dynamic>> tileList) {
tileList.add(
[
Icons.add_business_outlined,
"Setup Business",
() {
Navigator.of(context).pushNamed(
'/business/add',
arguments: widget.signedInUser,
);
// Navigator.popAndPushNamed(context, '/patient-manager',
// arguments: widget.userEmail);
}
],
);
}
void setAppsPersonal(List<List<dynamic>> tileList) { void setAppsPersonal(List<List<dynamic>> tileList) {
tileList.add( tileList.add(
[ [
@@ -61,6 +109,18 @@ class _HomeTileGridState extends State<HomeTileGrid> {
} }
void setAppsBusiness(List<List<dynamic>> tileList) { void setAppsBusiness(List<List<dynamic>> tileList) {
tileList.add(
[
Icons.business,
"Manage Bus",
() {
Navigator.of(context)
.pushNamed('/business-profile', arguments: widget.signedInUser);
// Navigator.popAndPushNamed(context, '/patient-manager',
// arguments: widget.userEmail);
}
],
);
tileList.add( tileList.add(
[ [
Icons.medication, Icons.medication,
@@ -104,7 +164,7 @@ class _HomeTileGridState extends State<HomeTileGrid> {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return const MyErrorMessage(errorType: "Invalid Email"); return const MyErrorMessage(errorType: "Invalid Username");
}, },
); );
} }
@@ -141,18 +201,27 @@ class _HomeTileGridState extends State<HomeTileGrid> {
} }
} }
void setApps(List<List<dynamic>> personalTileList, Future<void> setApps(List<List<dynamic>> personalTileList,
List<List<dynamic>> businessTileList) { List<List<dynamic>> businessTileList) async {
print(businessUser);
if (widget.signedInUser.fname == "") { if (widget.signedInUser.fname == "") {
print("New personal user");
setAppsNewPersonal(personalTileList); setAppsNewPersonal(personalTileList);
} else if (widget.signedInUser.type == "personal") { } else if (widget.signedInUser.type == "personal") {
print("existing personal user");
setAppsPersonal(personalTileList); setAppsPersonal(personalTileList);
} else if (businessUser == null) {
print("new business user");
setAppsPersonal(personalTileList);
setAppsNewBusiness(businessTileList);
} else { } else {
//business //business
print("existing business user");
setAppsPersonal(personalTileList); setAppsPersonal(personalTileList);
setAppsBusiness(businessTileList); setAppsBusiness(businessTileList);
} }
if (AppEnviroment.getEnv() == "Dev") { if (AppEnviroment.getEnv() == "Dev") {
print("Dev Enviroment");
setAppsDev(personalTileList); setAppsDev(personalTileList);
setAppsDev(businessTileList); setAppsDev(businessTileList);
} }
@@ -192,7 +261,15 @@ class _HomeTileGridState extends State<HomeTileGrid> {
@override @override
void initState() { void initState() {
setApps(personalTileList, businessTileList); futureBusinessUser = getBusinessUserDetails().then((results) {
//print(results);
setState(() {
businessUser = results;
setApps(personalTileList, businessTileList);
});
return null;
});
super.initState(); super.initState();
} }
@@ -202,66 +279,78 @@ class _HomeTileGridState extends State<HomeTileGrid> {
double width = size.width; double width = size.width;
double height = size.height; double height = size.height;
return Scaffold( return FutureBuilder(
appBar: const MIHAppBar(barTitle: "Mzansi Innovation Hub"), future: futureBusinessUser,
drawer: MIHAppDrawer( builder: (BuildContext context, AsyncSnapshot<BusinessUser?> snapshot) {
signedInUser: widget.signedInUser, if (snapshot.connectionState == ConnectionState.done) {
logo: MzanziInnovationHub.of(context)!.theme.logoImage(), //logo, return Scaffold(
), appBar: const MIHAppBar(barTitle: "Mzansi Innovation Hub"),
body: Container( drawer: MIHAppDrawer(
width: width, signedInUser: widget.signedInUser,
height: height, logo: MzanziInnovationHub.of(context)!.theme.logoImage(), //logo,
child: GridView.builder( ),
padding: EdgeInsets.fromLTRB(width / 6, height / 16, width / 6, body: Container(
0), //EdgeInsets.symmetric(horizontal: width / 6), width: width,
itemCount: pbswitch[_selectedIndex].length, height: height,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent( child: GridView.builder(
maxCrossAxisExtent: 200), padding: EdgeInsets.fromLTRB(width / 6, height / 16, width / 6,
//const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), 0), //EdgeInsets.symmetric(horizontal: width / 6),
itemBuilder: (context, index) { itemCount: pbswitch[_selectedIndex].length,
var tile = pbswitch[_selectedIndex][index]; gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
//setState(() {}); maxCrossAxisExtent: 200),
return buildtile(tile); //const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
}, itemBuilder: (context, index) {
), var tile = pbswitch[_selectedIndex][index];
), //setState(() {});
bottomNavigationBar: Visibility( return buildtile(tile);
visible: isBusinessUser(widget.signedInUser),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: GNav(
//hoverColor: Colors.lightBlueAccent,
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
iconSize: 35.0,
activeColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
tabBackgroundColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
//gap: 20,
//padding: EdgeInsets.all(15),
tabs: [
GButton(
icon: Icons.perm_identity,
text: "Personal",
onPressed: () {
setState(() {
_selectedIndex = 0;
});
}, },
), ),
GButton( ),
icon: Icons.business, bottomNavigationBar: Visibility(
text: "Business", visible: isBusinessUser(widget.signedInUser),
onPressed: () { child: Padding(
setState(() { padding: const EdgeInsets.all(15.0),
_selectedIndex = 1; child: GNav(
}); //hoverColor: Colors.lightBlueAccent,
}, color:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
iconSize: 35.0,
activeColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(),
tabBackgroundColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
//gap: 20,
//padding: EdgeInsets.all(15),
tabs: [
GButton(
icon: Icons.perm_identity,
text: "Personal",
onPressed: () {
setState(() {
_selectedIndex = 0;
});
},
),
GButton(
icon: Icons.business_center,
text: "Business",
onPressed: () {
setState(() {
_selectedIndex = 1;
});
},
),
],
selectedIndex: _selectedIndex,
),
), ),
], ),
selectedIndex: _selectedIndex, );
), }
), return const Center(
), child: CircularProgressIndicator(),
);
},
); );
} }
} }