import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart'; import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/font_awesome_icons.dart'; import 'package:fluttericon/typicons_icons.dart'; import 'package:unit2/screens/unit2/homepage.dart/components/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/role.dart'; import 'components/empty_module.dart'; class MainScreen extends StatefulWidget { const MainScreen({Key? key}) : super(key: key); @override State createState() => _MainScreenState(); } class _MainScreenState extends State { List roles = [ Module(name: 'UniT2 module operations', roles: []), Module(name: 'DocSms module operations', roles: []) ]; @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { return Future.value(true); }, child: BlocBuilder(builder: (context, state) { if (state is UserLoggedIn) { print(state.userData!.user!.login!.token); state.userData!.user!.login!.user!.roles!.forEach((role) { Role? getRole = role; role!.modules!.forEach((module) { if (module!.name!.toLowerCase() == 'unit2') { IconData iconData = iconGenerator(getRole!.name!); Roles newRole = Roles(role: getRole, icon: iconData); roles[0].roles.add(newRole); } if (module.name!.toLowerCase() == 'document management') { IconData iconData = iconGenerator(getRole!.name!); Roles newRole = Roles(role: getRole, icon: iconData); roles[1].roles.add(newRole); } }); }); 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( roles: roles, ) : const NoModule(), ); } return Container(); }), ); } IconData iconGenerator(String roleName) { IconData? iconData; switch (roleName.toLowerCase()) { case 'qr code scanner': iconData = FontAwesome.qrcode; break; case 'security guard': iconData = FontAwesome5.user_shield; break; case 'establishment point-person': iconData = FontAwesome.building_filled; break; case 'registration in-charge': iconData = FontAwesome.user_plus; break; case 'process server': iconData = Typicons.doc_text; break; } return iconData!; } } class Module { final String name; final List roles; Module({required this.name, required this.roles}); } class Roles { final IconData icon; final Role role; Roles({required this.role, required this.icon}); }