remove future builder and add switch Icon

This commit is contained in:
2024-08-23 15:40:41 +02:00
parent 3616c534db
commit 67358e515a

View File

@@ -33,7 +33,7 @@ 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 = [];
late Future<List<List<List<dynamic>>>> pbswitch; late List<List<List<dynamic>>> pbswitch;
late bool businessUserSwitch; late bool businessUserSwitch;
int _selectedIndex = 0; int _selectedIndex = 0;
final baseAPI = AppEnviroment.baseApiUrl; final baseAPI = AppEnviroment.baseApiUrl;
@@ -246,9 +246,8 @@ class _HomeTileGridState extends State<HomeTileGrid> {
} }
} }
Future<List<List<List<dynamic>>>> setApps( List<List<List<dynamic>>> setApps(List<List<dynamic>> personalTileList,
List<List<dynamic>> personalTileList, List<List<dynamic>> businessTileList) {
List<List<dynamic>> businessTileList) async {
//print(widget.businessUser); //print(widget.businessUser);
if (widget.signedInUser.fname == "") { if (widget.signedInUser.fname == "") {
//print("New personal user"); //print("New personal user");
@@ -344,85 +343,59 @@ class _HomeTileGridState extends State<HomeTileGrid> {
signedInUser: widget.signedInUser, signedInUser: widget.signedInUser,
//logo: MzanziInnovationHub.of(context)!.theme.logoImage(), //logo, //logo: MzanziInnovationHub.of(context)!.theme.logoImage(), //logo,
), ),
body: FutureBuilder( body: Column(
future: pbswitch, children: [
builder: (ctx, snapshot) { Row(
if (snapshot.connectionState == ConnectionState.done) { children: [
var apps = snapshot.requireData; IconButton(
return Column( onPressed: () {
children: [ //print(businessUserSwitch);
Padding( if (!businessUserSwitch) {
padding: const EdgeInsets.only(top: 10, left: 10), setState(() {
child: Row( businessUserSwitch = true;
children: [ _selectedIndex = 1;
Text( });
"Switch\nProfile", } else {
textAlign: TextAlign.center, setState(() {
style: TextStyle( businessUserSwitch = false;
fontWeight: FontWeight.bold, _selectedIndex = 0;
fontSize: 15.0, });
color: MzanziInnovationHub.of(context)! }
.theme },
.secondaryColor(), icon: const Icon(
), Icons.swap_horizontal_circle_outlined,
), size: 35,
const SizedBox(width: 10.0),
Switch(
value: businessUserSwitch,
onChanged: (bool value) {
setState(() {
businessUserSwitch = value;
});
if (businessUserSwitch) {
setState(() {
_selectedIndex = 1;
});
} else {
setState(() {
_selectedIndex = 0;
});
}
},
),
],
),
), ),
Text( ),
getHeading(_selectedIndex), ],
textAlign: TextAlign.center, ),
style: TextStyle( Text(
fontWeight: FontWeight.bold, getHeading(_selectedIndex),
fontSize: 35.0, textAlign: TextAlign.center,
color: style: TextStyle(
MzanziInnovationHub.of(context)!.theme.secondaryColor(), fontWeight: FontWeight.bold,
), fontSize: 35.0,
), color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
Expanded( ),
child: GridView.builder( ),
padding: EdgeInsets.fromLTRB( Expanded(
width / 6, child: GridView.builder(
height / 35, padding: EdgeInsets.fromLTRB(width / 6, height / 35, width / 6,
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: maxCrossAxisExtent: 200),
const SliverGridDelegateWithMaxCrossAxisExtent( //const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
maxCrossAxisExtent: 200), itemBuilder: (context, index) {
//const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), var tile = pbswitch[_selectedIndex][index];
itemBuilder: (context, index) { //setState(() {});
var tile = apps[_selectedIndex][index]; return buildtile(tile);
//setState(() {}); },
return buildtile(tile); ),
}, ),
), ],
),
],
);
}
return const Mihloadingcircle();
},
), ),
// bottomNavigationBar: Visibility( // bottomNavigationBar: Visibility(
// visible: isBusinessUser(widget.signedInUser), // visible: isBusinessUser(widget.signedInUser),
// child: Padding( // child: Padding(