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

109 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2023-01-23 03:02:59 +00:00
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';
2023-01-23 03:02:59 +00:00
import '../../../model/login_data/user_info/role.dart';
import 'components/empty_module.dart';
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key: key);
2022-11-28 08:03:13 +00:00
@override
State<MainScreen> createState() => _MainScreenState();
2022-11-28 08:03:13 +00:00
}
class _MainScreenState extends State<MainScreen> {
List<Role> roles = [];
List<DisplayCard> cards = [];
int? userId;
2022-11-28 08:03:13 +00:00
@override
Widget build(BuildContext context) {
setState(() {
cards.clear();
cards=[];
roles.clear();
roles = [];
});
return WillPopScope(
onWillPop: () async {
return Future.value(true);
},
2023-01-23 03:02:59 +00:00
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!) {
2023-01-23 03:02:59 +00:00
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);
2023-01-23 03:02:59 +00:00
}
}
}
2023-02-08 08:06:27 +00:00
return Scaffold(
2023-01-23 03:02:59 +00:00
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,
),
),
),
2023-01-23 03:02:59 +00:00
body: state.userData!.user!.login!.user!.roles!.isNotEmpty
? DashBoard(
2023-08-11 08:38:26 +00:00
estPersonAssignedArea: state.estPersonAssignedArea,
userId: userId!,
cards: cards,
)
: const NoModule(),
2023-02-08 08:06:27 +00:00
);
2023-01-23 03:02:59 +00:00
}
return Container();
}),
);
2022-11-28 08:03:13 +00:00
}
}
2023-01-23 03:02:59 +00:00
class DisplayCard {
final String roleName;
final String moduleName;
final ModuleObject object;
const DisplayCard(
{required this.moduleName, required this.object, required this.roleName});
2023-01-23 03:02:59 +00:00
}
class Module {
final String name;
final List<Roles> roles;
Module({required this.name, required this.roles});
}
class Roles {
final IconData? icon;
2023-01-23 03:02:59 +00:00
final Role role;
Roles({required this.role, required this.icon});
}