2022-12-05 08:06:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-23 03:02:59 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2022-12-05 08:06:45 +00:00
|
|
|
import 'package:flutter_zoom_drawer/flutter_zoom_drawer.dart';
|
2023-01-23 03:02:59 +00:00
|
|
|
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';
|
2022-12-05 08:06:45 +00:00
|
|
|
import 'package:unit2/theme-data.dart/colors.dart';
|
|
|
|
import 'package:unit2/utils/text_container.dart';
|
2023-02-01 08:03:05 +00:00
|
|
|
import '../../../bloc/user/user_bloc.dart';
|
2023-01-23 03:02:59 +00:00
|
|
|
import '../../../model/login_data/user_info/role.dart';
|
2022-12-05 08:06:45 +00:00
|
|
|
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
|
2022-12-05 08:06:45 +00:00
|
|
|
State<MainScreen> createState() => _MainScreenState();
|
2022-11-28 08:03:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 08:06:45 +00:00
|
|
|
class _MainScreenState extends State<MainScreen> {
|
2023-01-23 03:02:59 +00:00
|
|
|
List<Module> roles = [
|
2023-02-01 08:03:05 +00:00
|
|
|
Module(name: 'UniT2 module operations', roles: []),
|
|
|
|
Module(name: 'DocSms module operations', roles: [])
|
2023-01-23 03:02:59 +00:00
|
|
|
];
|
2022-11-28 08:03:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-12-05 08:06:45 +00:00
|
|
|
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) {
|
2023-01-26 02:15:00 +00:00
|
|
|
print(state.userData!.user!.login!.token);
|
2023-01-23 03:02:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2023-02-08 08:06:27 +00:00
|
|
|
return Scaffold(
|
2023-01-23 03:02:59 +00:00
|
|
|
appBar: AppBar(
|
2023-02-08 08:06:27 +00:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
2022-12-05 08:06:45 +00:00
|
|
|
),
|
2023-01-23 03:02:59 +00:00
|
|
|
body: state.userData!.user!.login!.user!.roles!.isNotEmpty
|
2023-02-08 08:06:27 +00:00
|
|
|
? DashBoard(
|
|
|
|
roles: roles,
|
|
|
|
)
|
|
|
|
: const NoModule(),
|
|
|
|
);
|
2023-01-23 03:02:59 +00:00
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
}),
|
2022-12-05 08:06:45 +00:00
|
|
|
);
|
2022-11-28 08:03:13 +00:00
|
|
|
}
|
2023-01-23 03:02:59 +00:00
|
|
|
|
|
|
|
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> roles;
|
|
|
|
Module({required this.name, required this.roles});
|
|
|
|
}
|
|
|
|
|
|
|
|
class Roles {
|
|
|
|
final IconData icon;
|
|
|
|
final Role role;
|
|
|
|
Roles({required this.role, required this.icon});
|
2022-12-05 08:06:45 +00:00
|
|
|
}
|