passo_mobile_app/lib/screens/unit2/homepage.dart/module-screen.dart

108 lines
3.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/dashboard.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/text_container.dart';
import '../../../bloc/user/user_bloc.dart';
import '../../../model/login_data/user_info/module.dart';
import '../../../model/login_data/user_info/role.dart';
import 'components/empty_module.dart';
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key);
@override
State<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
List<Role> roles = [];
List<DisplayCard> cards = [];
int? userId;
@override
Widget build(BuildContext context) {
setState(() {
cards.clear();
cards=[];
roles.clear();
roles = [];
});
return WillPopScope(
onWillPop: () async {
return Future.value(true);
},
child: BlocBuilder<UserBloc, UserState>(builder: (context, state) {
if (state is UserLoggedIn) {
userId = state.userData!.user!.login!.user!.id;
for (var role in state.userData!.user!.login!.user!.roles!) {
Role? getRole = role;
roles.add(getRole!);
}
for (var role in roles) {
for (var module in role.modules!) {
for (var object in module!.objects!) {
DisplayCard newCard = DisplayCard(
moduleName: module.name!.toLowerCase(),
object: object!,
roleName: role.name!.toLowerCase());
cards.add(newCard);
}
}
}
return Scaffold(
appBar: AppBar(
backgroundColor: primary,
leading: IconButton(
onPressed: () {
ZoomDrawer.of(context)!.toggle();
},
icon: const Icon(
Icons.menu,
color: Colors.white,
),
),
centerTitle: true,
title: const Text(
unit2ModuleScreen,
style: TextStyle(
fontSize: 18.0,
color: Colors.white,
),
),
),
body: state.userData!.user!.login!.user!.roles!.isNotEmpty
? DashBoard(
userId: userId!,
cards: cards,
)
: const NoModule(),
);
}
return Container();
}),
);
}
}
class DisplayCard {
final String roleName;
final String moduleName;
final ModuleObject object;
const DisplayCard(
{required this.moduleName, required this.object, required this.roleName});
}
class Module {
final String name;
final List<Roles> roles;
Module({required this.name, required this.roles});
}
class Roles {
final IconData? icon;
final Role role;
Roles({required this.role, required this.icon});
}