passo_mobile_app/lib/screens/unit2/homepage.dart/components/dashboard.dart

225 lines
10 KiB
Dart
Raw Normal View History

2023-01-23 03:02:59 +00:00
import 'package:flutter/material.dart';
2023-04-25 07:50:36 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/screens/docsms/components/request_receipt.dart';
import 'package:unit2/screens/docsms/index.dart';
2023-01-23 03:02:59 +00:00
import 'package:unit2/screens/unit2/homepage.dart/module-screen.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart';
2023-04-25 07:50:36 +00:00
import 'package:unit2/utils/global_context.dart';
import 'package:unit2/utils/qr_scanner.dart';
import 'package:unit2/utils/text_container.dart';
import '../../../../bloc/docsms/docsms_bloc.dart';
2023-01-23 03:02:59 +00:00
class DashBoard extends StatelessWidget {
final List<Module> roles;
const DashBoard({super.key, required this.roles});
@override
Widget build(BuildContext context) {
2023-04-25 07:50:36 +00:00
List<String> finishRoles = [];
2023-01-23 03:02:59 +00:00
return Container(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24),
height: MediaQuery.of(context).size.height,
2023-04-25 07:50:36 +00:00
////listview builder
2023-01-23 03:02:59 +00:00
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: roles.length,
itemBuilder: (BuildContext context, int index) {
2023-04-25 07:50:36 +00:00
//// gridview.count
return roles[index].roles.isNotEmpty
? SizedBox(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
roles[index].name.toUpperCase(),
style: Theme.of(context)
.textTheme
.labelLarge!
.copyWith(fontSize: 12),
),
const SizedBox(
height: 8,
),
GridView.count(
shrinkWrap: true,
crossAxisCount: 4,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(
vertical: 5, horizontal: 5),
children: roles[index].roles.map((role) {
//// if role name is qr code && finishRoles not contain security
//// this card will visible if the user has qr code scanner or security role
if (role.role.name!.toLowerCase() ==
'qr code scanner' &&
!finishRoles.contains("security")) {
finishRoles.add('scanner');
//// loop thru module to find unit module exist
for (var element in role.role.modules!) {
if (element!.name!.toLowerCase() == 'unit2') {
for (var element in element.objects!) {
//// loop thru objects to find pass check exist
if (element!.id == 9 &&
//// check if operations contains read and write
element.operations!
.contains("read")) {
//// if all conditions are true return card
return CardLabel(
ontap: () {},
icon: role.icon,
title: "Pass Check",
);
}
}
}
}
return Container();
//// if role name is security
//// this card will visible if the user has qr code scanner or security role
} else if (role.role.name!.toLowerCase() ==
'security guard' &&
!finishRoles.contains('scanner')) {
finishRoles.add('security');
for (var element in role.role.modules!) {
if (element!.name!.toLowerCase() == 'unit2') {
for (var element in element.objects!) {
if (element!.id == 9 &&
element.operations!
.contains("read")) {
return CardLabel(
ontap: () {},
icon: role.icon,
title: "Pass Check",
);
}
}
}
}
return Container();
//// if role name is field surveyor
} else if (role.role.name!.toLowerCase() ==
'field surveyor') {
for (var element in role.role.modules!) {
if (element!.name!.toLowerCase() == 'rpass') {
for (var element in element.objects!) {
if (element!.id == 11 &&
element.operations!
.contains("read")) {
return CardLabel(
ontap: () {},
icon: role.icon,
title: "Field Surveyor",
);
}
}
}
}
return Container();
//// if role name is process server
} else if (role.role.name!.toLowerCase() ==
'process server') {
for (var element in role.role.modules!) {
if (element!.name!.toLowerCase() ==
'document management') {
for (var element in element.objects!) {
if (element!.id == 3 &&
element.operations!
.contains("read")) {
return CardLabel(
ontap: () async {
String? qrBarcode =
await qrScanner();
if (qrBarcode != null) {
Navigator.push(NavigationService.navigatorKey.currentContext!, MaterialPageRoute(builder:
(BuildContext context) {
return BlocProvider(
create: (context) => DocsmsBloc()
..add(LoadDocument(
documentId: qrBarcode)),
child:
const AutoReceiveDocument(),
);
}));
}
},
icon: role.icon,
title: "Process Server",
);
}
}
}
}
return Container();
} else {
return Container();
}
}).toList()),
const SizedBox(
height: 8,
)
],
),
)
: Container();
2023-01-23 03:02:59 +00:00
}),
);
}
}
2023-04-25 07:50:36 +00:00
// ignore: must_be_immutable
class CardLabel extends StatelessWidget {
final String title;
final IconData icon;
final Function()? ontap;
const CardLabel(
{super.key,
required this.icon,
required this.title,
required this.ontap});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: ontap,
child: Container(
padding: const EdgeInsetsDirectional.fromSTEB(8, 5, 8, 13),
alignment: Alignment.center,
decoration: const BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(color: Colors.black12, spreadRadius: 2, blurRadius: 3)
],
borderRadius: BorderRadius.all(Radius.circular(8))),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Icon(
icon,
size: 20,
weight: 100,
grade: 100,
color: second,
),
),
const SizedBox(
height: 5,
),
Text(
title,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.labelLarge!.copyWith(
fontSize: blockSizeVertical * 1.2,
fontWeight: FontWeight.bold),
),
]),
),
);
}
}