commit before tree view

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-08-11 16:38:26 +08:00
parent 58c8435f9e
commit 5a56eb0adf
21 changed files with 1572 additions and 380 deletions

View File

@ -1,5 +1,6 @@
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/model/utils/agency.dart';
import 'package:unit2/utils/profile_utilities.dart'; import 'package:unit2/utils/profile_utilities.dart';
import '../../../../model/utils/category.dart'; import '../../../../model/utils/category.dart';
@ -27,6 +28,11 @@ class AgencyBloc extends Bloc<AgencyEvent, AgencyState> {
emit(AgencyErrorState(message: e.toString())); emit(AgencyErrorState(message: e.toString()));
} }
}); });
on<GetEstPointPersonAgencies>((event,emit)async{
if (agencyCategory.isEmpty) {
agencyCategory = await ProfileUtilities.instance.agencyCategory();
}
});
on<AddAgency>((event, emit) async { on<AddAgency>((event, emit) async {
emit(AgencyLoadingState()); emit(AgencyLoadingState());
try { try {

View File

@ -14,3 +14,8 @@ class AddAgency extends AgencyEvent{
final Agency agency; final Agency agency;
const AddAgency({required this.agency}); const AddAgency({required this.agency});
} }
class GetEstPointPersonAgencies extends AgencyEvent{
final List<AssignedArea>? assignedAreas;
const GetEstPointPersonAgencies({required this.assignedAreas});
}

View File

@ -15,7 +15,7 @@ class StationBloc extends Bloc<StationEvent, StationState> {
emit(StationLoadingState()); emit(StationLoadingState());
try { try {
stations = await RbacStationServices.instance stations = await RbacStationServices.instance
.getStations(agencyId: event.agencyId); .getStations(agencyId: event.agencyId.toString());
if (agencies.isEmpty) { if (agencies.isEmpty) {
List<Agency> newAgencies = List<Agency> newAgencies =
@ -31,7 +31,7 @@ class StationBloc extends Bloc<StationEvent, StationState> {
// emit(StationLoadingState()); // emit(StationLoadingState());
try { try {
stations = await RbacStationServices.instance stations = await RbacStationServices.instance
.getStations(agencyId: event.agencyId); .getStations(agencyId: event.agencyId.toString());
if (agencies.isEmpty) { if (agencies.isEmpty) {
List<Agency> newAgencies = List<Agency> newAgencies =

View File

@ -0,0 +1,31 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/utils/agency.dart';
import 'package:unit2/model/utils/category.dart';
import '../../../../../utils/profile_utilities.dart';
part 'assign_area_agency_event.dart';
part 'assign_area_agency_state.dart';
class AssignAreaAgencyBloc
extends Bloc<AssignAreaAgencyEvent, AssignAreaAgencyState> {
AssignAreaAgencyBloc() : super(AssignAreaAgencyInitial()) {
List<AssignedArea>? agencies = [];
List<Category> agencyCategory = [];
on<EstPointPersonGetAgencies>((event, emit) async {
emit(EstPointPersonAgencyLoadingState());
try {
if (agencyCategory.isEmpty) {
agencyCategory = await ProfileUtilities.instance.agencyCategory();
}
agencies = event.assignedAreas;
emit(EstPointPersonAgenciesLoaded(
agencies: agencies, agencyCategory: agencyCategory));
} catch (e) {
emit(EstPointAgencyErrorState(message: e.toString()));
}
});
}
}

View File

@ -0,0 +1,18 @@
part of 'assign_area_agency_bloc.dart';
abstract class AssignAreaAgencyEvent extends Equatable {
const AssignAreaAgencyEvent();
@override
List<Object> get props => [];
}
class EstPointPersonGetAgencies extends AssignAreaAgencyEvent {
final List<AssignedArea>? assignedAreas;
const EstPointPersonGetAgencies({required this.assignedAreas});
}
class EstPointPersonAddAgency extends AssignAreaAgencyEvent {
final Agency agency;
const EstPointPersonAddAgency({required this.agency});
}

View File

@ -0,0 +1,34 @@
part of 'assign_area_agency_bloc.dart';
abstract class AssignAreaAgencyState extends Equatable {
const AssignAreaAgencyState();
@override
List<Object> get props => [];
get message => null;
}
class AssignAreaAgencyInitial extends AssignAreaAgencyState {}
class EstPointPersonAgenciesLoaded extends AssignAreaAgencyState {
final List<AssignedArea>? agencies;
final List<Category> agencyCategory;
const EstPointPersonAgenciesLoaded({required this.agencies, required this.agencyCategory});
}
class EstPointAgencyErrorState extends AssignAreaAgencyState {
final String message;
const EstPointAgencyErrorState({required this.message});
}
class EstPointPersonAgencyLoadingState extends AssignAreaAgencyState {}
class EstPointPersonAgencyAddesState extends AssignAreaAgencyState {
final Map<dynamic, dynamic> response;
const EstPointPersonAgencyAddesState({required this.response});
}
class EstPointPersonAgencyDeletedState extends AssignAreaAgencyState {
final bool success;
const EstPointPersonAgencyDeletedState({required this.success});
}

View File

@ -0,0 +1,33 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import '../../../../../model/rbac/rbac_station.dart';
import '../../../../../model/utils/agency.dart';
import '../../../../../sevices/roles/rbac_operations/station_services.dart';
import '../../../../../utils/profile_utilities.dart';
part 'est_point_person_station_event.dart';
part 'est_point_person_station_state.dart';
class EstPointPersonStationBloc extends Bloc<EstPointPersonStationEvent, EstPointPersonStationState> {
EstPointPersonStationBloc() : super(EstPointPersonStationInitial()) {
List<RbacStation> stations = [];
List<AssignedArea> assignAreas = [];
on<EstPointPersonGetStations>((event, emit) async {
emit(EstPersonStationLoadingState());
try {
if(stations.isEmpty){
stations = await RbacStationServices.instance
.getStations(agencyId: event.agencyId);
}
assignAreas = event.assignedAreas;
emit(EstPersonStationLoadedState(stations: stations, assignedAreas: assignAreas));
} catch (e) {
emit(EstPersonStationErrorState(message: e.toString()));
}
});
}
}

View File

@ -0,0 +1,13 @@
part of 'est_point_person_station_bloc.dart';
abstract class EstPointPersonStationEvent extends Equatable {
const EstPointPersonStationEvent();
@override
List<Object> get props => [];
}
class EstPointPersonGetStations extends EstPointPersonStationEvent {
final String agencyId;
final List<AssignedArea> assignedAreas;
const EstPointPersonGetStations({required this.agencyId, required this.assignedAreas});
}

View File

@ -0,0 +1,27 @@
part of 'est_point_person_station_bloc.dart';
abstract class EstPointPersonStationState extends Equatable {
const EstPointPersonStationState();
@override
List<Object> get props => [];
}
class EstPointPersonStationInitial extends EstPointPersonStationState {}
class EstPersonStationLoadedState extends EstPointPersonStationState {
final List<AssignedArea> assignedAreas;
final List<RbacStation> stations;
const EstPersonStationLoadedState({required this.stations, required this.assignedAreas});
@override
List<Object> get props => [assignedAreas,stations];
}
class EstPersonStationLoadingState extends EstPointPersonStationState {}
class EstPersonStationErrorState extends EstPointPersonStationState {
final String message;
const EstPersonStationErrorState({required this.message});
@override
List<Object> get props => [message];
}

View File

@ -4,6 +4,8 @@ import 'package:barcode_scan2/barcode_scan2.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/login_data/user_info/role.dart';
import 'package:unit2/model/login_data/user_info/user_data.dart'; import 'package:unit2/model/login_data/user_info/user_data.dart';
import 'package:unit2/model/login_data/version_info.dart'; import 'package:unit2/model/login_data/version_info.dart';
import 'package:unit2/screens/unit2/login/functions/get_app_version.dart'; import 'package:unit2/screens/unit2/login/functions/get_app_version.dart';
@ -22,6 +24,7 @@ class UserBloc extends Bloc<UserEvent, UserState> {
String? _apkVersion; String? _apkVersion;
bool save = false; bool save = false;
String? uuid; String? uuid;
List<AssignedArea> establishmentPointPersonAssignedAreas = [];
UserBloc() : super(UserInitial()) { UserBloc() : super(UserInitial()) {
//// this event is called when opening the app to check if //// this event is called when opening the app to check if
//// there is new app version //// there is new app version
@ -69,13 +72,24 @@ class UserBloc extends Bloc<UserEvent, UserState> {
.webLogin(username: event.username, password: event.password); .webLogin(username: event.username, password: event.password);
if (response['status'] == true) { if (response['status'] == true) {
UserData userData = UserData.fromJson(response['data']); UserData userData = UserData.fromJson(response['data']);
Role? estPointPerson = userData.user?.login?.user?.roles?.firstWhere(
(element) =>
element?.name?.toLowerCase() == "establishment point-person",
);
if (estPointPerson != null) {
estPointPerson.assignedArea!.forEach((element) {
establishmentPointPersonAssignedAreas.add(element!);
});
}
emit(UserLoggedIn( emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: userData, userData: userData,
success: true, success: true,
message: response['message'], message: response['message'],
savedCredentials: save)); savedCredentials: save));
} else { } else {
emit(UserLoggedIn( emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: null, userData: null,
success: false, success: false,
message: response['message'], message: response['message'],
@ -85,39 +99,47 @@ class UserBloc extends Bloc<UserEvent, UserState> {
emit(InternetTimeout(message: timeoutError)); emit(InternetTimeout(message: timeoutError));
} on SocketException catch (_) { } on SocketException catch (_) {
emit(InternetTimeout(message: timeoutError)); emit(InternetTimeout(message: timeoutError));
}on Error catch(e){ } on Error catch (e) {
emit(LoginErrorState(message: e.toString())); emit(LoginErrorState(message: e.toString()));
} }
}); });
on<UuidLogin>((event, emit) async { on<UuidLogin>((event, emit) async {
try { try {
Map<dynamic,dynamic> response = await AuthService.instance Map<dynamic, dynamic> response = await AuthService.instance
.qrLogin(uuid: event.uuid, password: event.password); .qrLogin(uuid: event.uuid, password: event.password);
if (response['status'] == true) { if (response['status'] == true) {
UserData userData = UserData.fromJson(response['data']); UserData userData = UserData.fromJson(response['data']);
emit(UserLoggedIn( emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: userData, userData: userData,
success: true, success: true,
message: response['message'], message: response['message'],
savedCredentials: save)); savedCredentials: save));
} else { } else {
emit(UserLoggedIn( emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: null, userData: null,
success: false, success: false,
message: response['message'], message: response['message'],
savedCredentials: save)); savedCredentials: save));
} }
emit(UserLoggedIn(userData: _userData, savedCredentials: save)); emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: _userData,
savedCredentials: save));
} on TimeoutException catch (_) { } on TimeoutException catch (_) {
emit(InternetTimeout(message: timeoutError)); emit(InternetTimeout(message: timeoutError));
} on SocketException catch (_) { } on SocketException catch (_) {
emit(InternetTimeout(message: timeoutError)); emit(InternetTimeout(message: timeoutError));
} on Error catch(e){ } on Error catch (e) {
emit(LoginErrorState(message: e.toString())); emit(LoginErrorState(message: e.toString()));
} }
}); });
on<LoadLoggedInUser>((event, emit) { on<LoadLoggedInUser>((event, emit) {
emit(UserLoggedIn(userData: _userData, savedCredentials: save)); emit(UserLoggedIn(
estPersonAssignedArea: establishmentPointPersonAssignedAreas,
userData: _userData,
savedCredentials: save));
}); });
on<GetUuid>((event, emit) async { on<GetUuid>((event, emit) async {
ScanResult result = await QRCodeBarCodeScanner.instance.scanner(); ScanResult result = await QRCodeBarCodeScanner.instance.scanner();
@ -125,8 +147,9 @@ emit(LoginErrorState(message: e.toString()));
uuid = result.rawContent.toString(); uuid = result.rawContent.toString();
emit(UuidLoaded(uuid: uuid!)); emit(UuidLoaded(uuid: uuid!));
} }
});on<LoadUuid>((event,emit){ });
emit(UuidLoaded(uuid: uuid!)); on<LoadUuid>((event, emit) {
emit(UuidLoaded(uuid: uuid!));
}); });
} }
} }

View File

@ -32,11 +32,12 @@ class UserError extends UserState {
List<Object> get props => []; List<Object> get props => [];
} }
class UserLoggedIn extends UserState{ class UserLoggedIn extends UserState{
final List<AssignedArea>? estPersonAssignedArea;
final UserData? userData; final UserData? userData;
final String? message; final String? message;
final bool? success; final bool? success;
final bool? savedCredentials; final bool? savedCredentials;
UserLoggedIn({this.userData,this.message,this.success,this.savedCredentials}); UserLoggedIn({this.userData,this.message,this.success,this.savedCredentials, required this.estPersonAssignedArea});
} }
class VersionLoaded extends UserState { class VersionLoaded extends UserState {

View File

@ -19,7 +19,6 @@ class Agency {
category: json["category"] == null ? null : Category.fromJson(json["category"]), category: json["category"] == null ? null : Category.fromJson(json["category"]),
privateEntity: json["private_entity"], privateEntity: json["private_entity"],
); );
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"id": id, "id": id,
"name": name, "name": name,

View File

@ -25,8 +25,8 @@ import '../../../widgets/Leadings/add_leading.dart';
import '../../../widgets/empty_data.dart'; import '../../../widgets/empty_data.dart';
class RbacAgencyScreen extends StatelessWidget { class RbacAgencyScreen extends StatelessWidget {
final int id;
const RbacAgencyScreen({super.key, required this.id}); const RbacAgencyScreen();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -1,17 +1,30 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/dashboard_icon_generator.dart'; import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/dashboard_icon_generator.dart';
import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/superadmin_expanded_menu.dart'; import 'package:unit2/screens/unit2/homepage.dart/components/dashboard/superadmin_expanded_menu.dart';
import 'package:unit2/screens/unit2/homepage.dart/module-screen.dart'; import 'package:unit2/screens/unit2/homepage.dart/module-screen.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/theme-data.dart/form-style.dart';
import '../../../../../bloc/rbac/rbac_operations/agency/agency_bloc.dart';
import '../../../../../bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart';
import '../../../../../bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart';
import '../../../../superadmin/agency.dart/agency_screen.dart';
import '../../../roles/establishment_point_person/est_point_person_agecies.dart';
import '../../../roles/establishment_point_person/est_point_person_station.dart';
import './shared_card_label.dart'; import './shared_card_label.dart';
class DashBoard extends StatefulWidget { class DashBoard extends StatefulWidget {
final List<AssignedArea>? estPersonAssignedArea;
final List<DisplayCard> cards; final List<DisplayCard> cards;
final int userId; final int userId;
const DashBoard({super.key, required this.cards, required this.userId}); const DashBoard(
{super.key,
required this.cards,
required this.userId,
required this.estPersonAssignedArea});
@override @override
State<DashBoard> createState() => _DashBoardState(); State<DashBoard> createState() => _DashBoardState();
@ -70,373 +83,561 @@ class _DashBoardState extends State<DashBoard> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
////unit2 module operations ////unit2 module operations
Container(child: unit2Cards.isEmpty?const SizedBox():Text( Container(
"Unit2 module operations", child: unit2Cards.isEmpty
style: Theme.of(context).textTheme.displaySmall!.copyWith( ? const SizedBox()
fontSize: 16, color: primary, fontWeight: FontWeight.w300), : Text(
),), "Unit2 module operations",
SizedBox( style: Theme.of(context)
height: unit2Cards.isEmpty?0: 8, .textTheme
.displaySmall!
.copyWith(
fontSize: 16,
color: primary,
fontWeight: FontWeight.w300),
),
), ),
Container(child: unit2Cards.isEmpty?const SizedBox():GridView.count( SizedBox(
shrinkWrap: true, height: unit2Cards.isEmpty ? 0 : 8,
crossAxisCount: 4, ),
crossAxisSpacing: 8, Container(
mainAxisSpacing: 10, child: unit2Cards.isEmpty
physics: const BouncingScrollPhysics(), ? const SizedBox()
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5), : GridView.count(
children: unit2Cards.length > 3 shrinkWrap: true,
? tempUnit2Cards.map(( crossAxisCount: 4,
e, crossAxisSpacing: 8,
) { mainAxisSpacing: 10,
int index = tempUnit2Cards.indexOf(e); physics: const BouncingScrollPhysics(),
//// if unit2 cards is less then 3 padding: const EdgeInsets.symmetric(
return Container( vertical: 5, horizontal: 5),
child: index == 3 children: unit2Cards.length > 3
? CardLabel( ? tempUnit2Cards.map((
icon: FontAwesome5.chevron_circle_right, e,
title: "See More", ) {
ontap: () { int index = tempUnit2Cards.indexOf(e);
showDialog( //// if unit2 cards is greater then 3
context: context, return Container(
builder: (BuildContext context) { child: index == 3
return AlertDialog( ? CardLabel(
title: const Text( icon: FontAwesome5
"Unit2 Admin Module Operations", .chevron_circle_right,
textAlign: TextAlign.center, title: "See More",
), ontap: () {
content: Column( showDialog(
mainAxisSize: MainAxisSize.min, context: context,
children: [ builder:
SizedBox( (BuildContext context) {
height: 200, return AlertDialog(
width: double.maxFinite, title: const Text(
child: GridView.count( "Unit2 Admin Module Operations",
shrinkWrap: true, textAlign:
crossAxisCount: 3, TextAlign.center,
crossAxisSpacing: 8, ),
mainAxisSpacing: 10, content: Column(
physics: mainAxisSize:
const BouncingScrollPhysics(), MainAxisSize.min,
padding: children: [
const EdgeInsets SizedBox(
.symmetric( height: 300,
vertical: 5, width: double
horizontal: 5), .maxFinite,
children:
unit2Cards.map((
e,
) {
int index = unit2Cards
.indexOf(e);
//// if unit2 cards is less then 3
return AnimationConfiguration
.staggeredGrid(
position: index,
columnCount: 3,
child: child:
ScaleAnimation( GridView.count(
child: shrinkWrap:
FadeInAnimation( true,
child: Container( crossAxisCount:
child: (e.roleName == 'superadmin' || e.roleName == 'qr code scanner' || e.roleName == 'security guard' || e.roleName == 'establishment point-person' || e.roleName == 'registration in-charge') && e.moduleName == 'unit2' 3,
? CardLabel( crossAxisSpacing:
icon: iconGenerator(name: e.object.name!), 8,
title: e.object.name!.toLowerCase() == 'role based access control' mainAxisSpacing:
? "RBAC" 10,
: e.object.name!.toLowerCase() == "person basic information" physics:
? "Basic Info" const BouncingScrollPhysics(),
: e.object.name!, padding: const EdgeInsets
ontap: () { .symmetric(
if (e.object.name!.toLowerCase() == 'pass check') { vertical:
PassCheckArguments passCheckArguments = PassCheckArguments(roleId: 10, userId: widget.userId); 5,
Navigator.pushNamed(context, '/pass-check', arguments: passCheckArguments); horizontal:
} 5),
if (e.object.name!.toLowerCase() == 'role based access control') { children:
Navigator.pushNamed(context, '/rbac'); unit2Cards
} .map((
}) e,
: Container( ) {
color: int index =
Colors.black, unit2Cards
)), .indexOf(e);
//// if unit2 cards is less then 3
return AnimationConfiguration
.staggeredGrid(
position:
index,
columnCount:
3,
child:
ScaleAnimation(
child:
FadeInAnimation(
child: Container(
child: (e.roleName == 'superadmin' || e.roleName == 'qr code scanner' || e.roleName == 'security guard' || e.roleName == 'establishment point-person' || e.roleName == 'registration in-charge') && e.moduleName == 'unit2'
? CardLabel(
icon: iconGenerator(name: e.object.name!),
title: e.object.name!.toLowerCase() == 'role based access control'
? "RBAC"
: e.object.name!.toLowerCase() == "person basic information"
? "Basic Info"
: e.object.name!,
ontap: () {
if (e.object.name!.toLowerCase() == 'pass check') {
PassCheckArguments passCheckArguments = PassCheckArguments(roleId: 10, userId: widget.userId);
Navigator.pushNamed(context, '/pass-check', arguments: passCheckArguments);
}
if (e.object.name!.toLowerCase() == 'role based access control') {
Navigator.pushNamed(context, '/rbac');
}
if (e.object.name!.toLowerCase() == 'agency') {
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
return BlocProvider(
create: (context) => AssignAreaAgencyBloc()..add((EstPointPersonGetAgencies(assignedAreas: widget.estPersonAssignedArea))),
child: const EstPorintPersonAgencyScreen(),
);
}));
}
if (e.object.name == 'Station') {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Select Agency"),
content: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
DropdownButtonFormField(
isDense: true,
decoration: normalTextFieldStyle("select agency", "select agency"),
isExpanded: true,
items: widget.estPersonAssignedArea!.map((e) {
return DropdownMenuItem(
value: e,
child: FittedBox(child: Text(e.areaName!)),
);
}).toList(),
onChanged: (value) {
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
return BlocProvider(
create: (context) => EstPointPersonStationBloc()..add( EstPointPersonGetStations(agencyId: value!.areaid!,assignedAreas: widget.estPersonAssignedArea!)),
child: const EstPointPersonStationScreen(),
);
}));
})
],
),
);
});
}
})
: Container(
color: Colors.black,
)),
),
),
);
}).toList()),
),
],
),
);
});
})
: (e.roleName == 'superadmin' ||
e.roleName ==
'qr code scanner' ||
e.roleName ==
'security guard' ||
e.roleName ==
'establishment point-person' ||
e.roleName ==
'registration in-charge') &&
e.moduleName == 'unit2'
? CardLabel(
icon: iconGenerator(
name: e.object.name!),
title: e.object.name!
.toLowerCase() ==
'role based access control'
? "RBAC"
: e.object.name!
.toLowerCase() ==
"person basic information"
? "Basic Info"
: e.object.name!,
ontap: () {
if (e.object.name!
.toLowerCase() ==
'pass check') {
PassCheckArguments
passCheckArguments =
PassCheckArguments(
roleId: 10,
userId:
widget.userId);
Navigator.pushNamed(
context, '/pass-check',
arguments:
passCheckArguments);
}
if (e.object.name!
.toLowerCase() ==
'role based access control') {
Navigator.pushNamed(
context, '/rbac');
}
if (e.object.name!
.toLowerCase() ==
'agency') {
Navigator.push(context,
MaterialPageRoute(
builder:
(BuildContext
context) {
return BlocProvider(
create: (context) =>
AssignAreaAgencyBloc()
..add((EstPointPersonGetAgencies(
assignedAreas:
widget
.estPersonAssignedArea))),
child:
const EstPorintPersonAgencyScreen(),
);
}));
}
})
: Container(
color: Colors.black,
));
}).toList()
: unit2Cards.map((
e,
) {
////if unit2 cards is greater than 3
return Container(
child: (e.roleName == 'superadmin' ||
e.roleName ==
'qr code scanner' ||
e.roleName ==
'security guard' ||
e.roleName ==
'establishment point-person' ||
e.roleName ==
'registration in-charge') &&
e.moduleName == 'unit2'
? CardLabel(
icon: iconGenerator(
name: e.object.name!),
title: e.object.name!
.toLowerCase() ==
'role based access control'
? "RBAC"
: e.object.name!
.toLowerCase() ==
"person basic information"
? "Basic Info"
: e.object.name!,
ontap: () {
if (e.object.name!
.toLowerCase() ==
'pass check') {
PassCheckArguments
passCheckArguments =
PassCheckArguments(
roleId: 10,
userId: widget.userId);
Navigator.pushNamed(
context, '/pass-check',
arguments:
passCheckArguments);
}
if (e.object.name!
.toLowerCase() ==
'role based access control') {
Navigator.pushNamed(
context, '/rbac');
}
if (e.object.name!
.toLowerCase() ==
'agency') {
Navigator.push(context,
MaterialPageRoute(builder:
(BuildContext context) {
return BlocProvider(
create: (context) =>
AssignAreaAgencyBloc()
..add((EstPointPersonGetAgencies(
assignedAreas: widget
.estPersonAssignedArea))),
child:
const EstPorintPersonAgencyScreen(),
);
}));
}
})
: Container(
color: Colors.black,
));
}).toList(),
),
),
SizedBox(
height: unit2Cards.isEmpty ? 0 : 24,
),
Container(
child: superadminCards.isEmpty
? const SizedBox()
: Text(
"Superadmin module operations",
style: Theme.of(context)
.textTheme
.displaySmall!
.copyWith(
fontSize: 16,
color: primary,
fontWeight: FontWeight.w300),
),
),
SizedBox(
height: superadminCards.isEmpty ? 0 : 8,
),
Container(
child: superadminCards.isEmpty
? const SizedBox()
: GridView.count(
shrinkWrap: true,
crossAxisCount: 4,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(
vertical: 5, horizontal: 5),
children: superadminCards.length > 3
//// in superadmincards lenght is greaterthan 3
? tempSuperAdminCards.map((e) {
int index = tempSuperAdminCards.indexOf(e);
return Container(
child: index == 3
? CardLabel(
icon: FontAwesome5
.chevron_circle_right,
title: "See More",
ontap: () {
showDialog(
context: context,
builder:
(BuildContext context) {
return AlertDialog(
title: const Text(
"Super Admin Module Operations",
textAlign:
TextAlign.center,
),
content: Column(
mainAxisSize:
MainAxisSize.min,
children: [
SizedBox(
height: 480,
width: double
.maxFinite,
child: GridView
.count(
shrinkWrap:
true,
crossAxisCount:
3,
crossAxisSpacing:
8,
mainAxisSpacing:
10,
physics:
const BouncingScrollPhysics(),
padding: const EdgeInsets
.symmetric(
vertical: 5,
horizontal:
5),
children:
superadminCards
.map(
(e) {
int index =
superadminCards
.indexOf(
e);
return SuperAdminMenu(
id: widget
.userId,
columnCount:
3,
index:
index,
object: e,
);
}).toList(),
), ),
), ),
); ],
}).toList()), ),
), );
], });
), })
); : SuperAdminMenu(
}); id: widget.userId,
}) object: e,
: (e.roleName == 'superadmin' || index: index,
e.roleName == 'qr code scanner' || columnCount: 3,
e.roleName == 'security guard' || ));
e.roleName == }).toList()
'establishment point-person' || //// in superadmincards lenght is lessthan 3
e.roleName == : superadminCards.map((e) {
'registration in-charge') && int index = tempSuperAdminCards.indexOf(e);
e.moduleName == 'unit2' return Container(
? CardLabel( child: index == 3
icon: ? CardLabel(
iconGenerator(name: e.object.name!), icon: FontAwesome5
title: e.object.name!.toLowerCase() == .chevron_circle_right,
'role based access control' title: "See More",
? "RBAC" ontap: () {
: e.object.name!.toLowerCase() == showDialog(
"person basic information" context: context,
? "Basic Info" builder:
: e.object.name!, (BuildContext context) {
ontap: () { return AlertDialog(
if (e.object.name!.toLowerCase() == title: const Text(
'pass check') { "Super Admin Module Operations",
PassCheckArguments textAlign:
passCheckArguments = TextAlign.center,
PassCheckArguments( ),
roleId: 10, content: Column(
userId: widget.userId); mainAxisSize:
Navigator.pushNamed( MainAxisSize.min,
context, '/pass-check', children: [
arguments: passCheckArguments); SizedBox(
} height: 480,
if (e.object.name!.toLowerCase() == width: double
'role based access control') { .maxFinite,
Navigator.pushNamed( child: GridView
context, '/rbac'); .count(
} shrinkWrap:
}) true,
: Container( crossAxisCount:
color: Colors.black, 3,
)); crossAxisSpacing:
}).toList() 8,
: unit2Cards.map(( mainAxisSpacing:
e, 10,
) { physics:
////if unit2 cards is greater than 3 const BouncingScrollPhysics(),
return Container( padding: const EdgeInsets
child: (e.roleName == 'superadmin' || .symmetric(
e.roleName == 'qr code scanner' || vertical: 5,
e.roleName == 'security guard' || horizontal:
e.roleName == 5),
'establishment point-person' || children:
e.roleName == superadminCards
'registration in-charge') && .map(
e.moduleName == 'unit2' (e) {
? CardLabel( return SuperAdminMenu(
icon: iconGenerator(name: e.object.name!), id: widget
title: e.object.name!.toLowerCase() == .userId,
'role based access control' columnCount:
? "RBAC" 4,
: e.object.name!.toLowerCase() == index:
"person basic information" index,
? "Basic Info" object: e,
: e.object.name!, );
ontap: () { }).toList(),
if (e.object.name!.toLowerCase() == ),
'pass check') { ),
PassCheckArguments passCheckArguments = ],
PassCheckArguments( ),
roleId: 10, );
userId: widget.userId); });
Navigator.pushNamed( })
context, '/pass-check', : SuperAdminMenu(
arguments: passCheckArguments); id: widget.userId,
} object: e,
if (e.object.name!.toLowerCase() == index: index,
'role based access control') { columnCount: 4,
Navigator.pushNamed(context, '/rbac'); ));
} }).toList())),
})
: Container(
color: Colors.black,
));
}).toList(),
),),
SizedBox(
height: unit2Cards.isEmpty?0:24,
),
Container(child: superadminCards.isEmpty?const SizedBox(): Text(
"Superadmin module operations",
style: Theme.of(context).textTheme.displaySmall!.copyWith(
fontSize: 16, color: primary, fontWeight: FontWeight.w300),
),),
SizedBox(
height: superadminCards.isEmpty? 0: 8,
),
Container(child: superadminCards.isEmpty?const SizedBox():GridView.count(
shrinkWrap: true,
crossAxisCount: 4,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics: const BouncingScrollPhysics(),
padding:
const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
children: superadminCards.length > 3
//// in superadmincards lenght is greaterthan 3
? tempSuperAdminCards.map((e) {
int index = tempSuperAdminCards.indexOf(e);
return Container(
child: index == 3
? CardLabel(
icon: FontAwesome5.chevron_circle_right,
title: "See More",
ontap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
"Super Admin Module Operations",
textAlign: TextAlign.center,
),
content: Column(
mainAxisSize:
MainAxisSize.min,
children: [
SizedBox(
height: 480,
width: double.maxFinite,
child: GridView.count(
shrinkWrap: true,
crossAxisCount: 3,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics:
const BouncingScrollPhysics(),
padding:
const EdgeInsets
.symmetric(
vertical: 5,
horizontal: 5),
children:
superadminCards
.map((e) {
int index =
superadminCards
.indexOf(e);
return SuperAdminMenu(
id: widget.userId,
columnCount: 3,
index: index,
object: e,
);
}).toList(),
),
),
],
),
);
});
})
: SuperAdminMenu(
id: widget.userId,
object: e,
index: index,
columnCount: 3,
));
}).toList()
//// in superadmincards lenght is lessthan 3
: superadminCards.map((e) {
int index = tempSuperAdminCards.indexOf(e);
return Container(
child: index == 3
? CardLabel(
icon: FontAwesome5.chevron_circle_right,
title: "See More",
ontap: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
"Super Admin Module Operations",
textAlign: TextAlign.center,
),
content: Column(
mainAxisSize:
MainAxisSize.min,
children: [
SizedBox(
height: 480,
width: double.maxFinite,
child: GridView.count(
shrinkWrap: true,
crossAxisCount: 3,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics:
const BouncingScrollPhysics(),
padding:
const EdgeInsets
.symmetric(
vertical: 5,
horizontal: 5),
children:
superadminCards
.map((e) {
return SuperAdminMenu(
id: widget.userId,
columnCount: 4,
index: index,
object: e,
);
}).toList(),
),
),
],
),
);
});
})
: SuperAdminMenu(
id: widget.userId,
object: e,
index: index,
columnCount: 4,
));
}).toList())),
const SizedBox( const SizedBox(
height: 24, height: 24,
), ),
Container(child: rpassCards.isEmpty?const SizedBox(): Text( Container(
"RPAss module operations", child: rpassCards.isEmpty
style: Theme.of(context).textTheme.displaySmall!.copyWith( ? const SizedBox()
fontSize: 16, color: primary, fontWeight: FontWeight.w300), : Text(
),) "RPAss module operations",
, SizedBox( style: Theme.of(context)
height:rpassCards.isEmpty?0: 8, .textTheme
.displaySmall!
.copyWith(
fontSize: 16,
color: primary,
fontWeight: FontWeight.w300),
),
),
SizedBox(
height: rpassCards.isEmpty ? 0 : 8,
),
Container(
child: rpassCards.isEmpty
? const SizedBox()
: GridView.count(
shrinkWrap: true,
crossAxisCount: 4,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(
vertical: 5, horizontal: 5),
children: rpassCards.map((e) {
return Container(
child: (e.roleName == 'field surveyor') &&
e.moduleName == 'rpass'
? CardLabel(
icon: iconGenerator(name: e.object.name!),
title: e.object.name == 'Real Property'
? "Field Surveyor"
: e.object.name!,
ontap: () {})
: Container(
color: Colors.black,
));
}).toList(),
),
), ),
Container(child: rpassCards.isEmpty?const SizedBox():GridView.count(
shrinkWrap: true,
crossAxisCount: 4,
crossAxisSpacing: 8,
mainAxisSpacing: 10,
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
children: rpassCards.map((e) {
return Container(
child: (e.roleName == 'field surveyor') &&
e.moduleName == 'rpass'
? CardLabel(
icon: iconGenerator(name: e.object.name!),
title: e.object.name == 'Real Property'
? "Field Surveyor"
: e.object.name!,
ontap: () {})
: Container(
color: Colors.black,
));
}).toList(),
),),
const SizedBox( const SizedBox(
height: 24, height: 24,
), ),
Container(child: docSmsCards.isEmpty?const SizedBox(): Text( Container(
"DocSMS module operations", child: docSmsCards.isEmpty
style: Theme.of(context).textTheme.displaySmall!.copyWith( ? const SizedBox()
fontSize: 16, color: primary, fontWeight: FontWeight.w300), : Text(
),), "DocSMS module operations",
style: Theme.of(context)
.textTheme
.displaySmall!
.copyWith(
fontSize: 16,
color: primary,
fontWeight: FontWeight.w300),
),
),
const SizedBox( const SizedBox(
height: 8, height: 8,
), ),
@ -456,9 +657,7 @@ class _DashBoardState extends State<DashBoard> {
title: e.object.name == "Document" title: e.object.name == "Document"
? "Process Server" ? "Process Server"
: e.object.name!, : e.object.name!,
ontap: () { ontap: () {})
})
: Container( : Container(
color: Colors.black, color: Colors.black,
)); ));

View File

@ -157,7 +157,7 @@ class SuperAdminMenu extends StatelessWidget {
create: (context) => create: (context) =>
AgencyBloc()..add(GetAgencies()), AgencyBloc()..add(GetAgencies()),
child: RbacAgencyScreen( child: RbacAgencyScreen(
id: id,
), ),
); );
})); }));

View File

@ -74,6 +74,7 @@ class _MainScreenState extends State<MainScreen> {
), ),
body: state.userData!.user!.login!.user!.roles!.isNotEmpty body: state.userData!.user!.login!.user!.roles!.isNotEmpty
? DashBoard( ? DashBoard(
estPersonAssignedArea: state.estPersonAssignedArea,
userId: userId!, userId: userId!,
cards: cards, cards: cards,
) )

View File

@ -0,0 +1,248 @@
import 'package:app_popup_menu/app_popup_menu.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:fluttericon/font_awesome_icons.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/rbac/rbac_operations/agency/agency_bloc.dart';
import 'package:unit2/bloc/rbac/rbac_operations/object/object_bloc.dart';
import 'package:unit2/bloc/role/pass_check/est_point_person/assign_area/assign_area_agency_bloc.dart';
import 'package:unit2/model/utils/category.dart';
import 'package:unit2/widgets/error_state.dart';
import '../../../../model/utils/agency.dart';
import '../../../../theme-data.dart/box_shadow.dart';
import '../../../../theme-data.dart/btn-style.dart';
import '../../../../theme-data.dart/colors.dart';
import '../../../../theme-data.dart/form-style.dart';
import '../../../../utils/global.dart';
import '../../../../utils/global_context.dart';
import '../../../../widgets/Leadings/add_leading.dart';
import '../../../../widgets/empty_data.dart';
class EstPorintPersonAgencyScreen extends StatelessWidget {
const EstPorintPersonAgencyScreen({super.key});
@override
Widget build(BuildContext context) {
final formKey = GlobalKey<FormBuilderState>();
List<Category> agencyCategory = [];
Category? selectedAgencyCategory;
bool? isPrivate;
final agencyCategoryFocusNode = FocusNode();
BuildContext parent;
return Scaffold(
appBar: AppBar(
backgroundColor: primary,
title: const Text("Agencies"),
actions: [
AddLeading(onPressed: () {
parent = context;
showDialog(
context: NavigationService.navigatorKey.currentContext!,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Add Agency"),
content: FormBuilder(
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
FormBuilderTextField(
validator: FormBuilderValidators.required(
errorText: "This field is required"),
name: "name",
decoration: normalTextFieldStyle(
"Agency name ", "Agency name"),
),
const SizedBox(
height: 12,
),
SearchField(
focusNode: agencyCategoryFocusNode,
itemHeight: 80,
suggestions: agencyCategory
.map((Category category) =>
SearchFieldListItem(category.name!,
item: category,
child: ListTile(
title: Text(category.name!),
subtitle: Text(
category.industryClass!.name!),
)))
.toList(),
emptyWidget: Container(
height: 100,
decoration: box1(),
child: const Center(
child: Text("No result found ...")),
),
onSuggestionTap: (agencyCategory) {
selectedAgencyCategory = agencyCategory.item;
agencyCategoryFocusNode.unfocus();
},
searchInputDecoration:
normalTextFieldStyle("Category *", "")
.copyWith(
suffixIcon: IconButton(
icon: const Icon(Icons.arrow_drop_down),
onPressed: () {
agencyCategoryFocusNode.unfocus();
},
)),
validator: (value) {
if (value!.isEmpty) {
return "This field is required";
}
return null;
},
),
FormBuilderRadioGroup(
decoration: InputDecoration(
border: InputBorder.none,
label: Row(
children: [
Text(
"Is this private sector? ",
style: Theme.of(context)
.textTheme
.headlineSmall!
.copyWith(fontSize: 24),
),
const Icon(FontAwesome.help_circled)
],
),
),
////onvhange private sector
onChanged: (value) {
if (value.toString() == "YES") {
isPrivate = true;
} else {
isPrivate = false;
}
},
name: 'isPrivate',
validator: FormBuilderValidators.required(),
options: ["YES", "NO"]
.map((lang) =>
FormBuilderFieldOption(value: lang))
.toList(growable: false),
),
const SizedBox(
height: 12,
),
SizedBox(
height: 50,
width: double.maxFinite,
child: ElevatedButton(
style: mainBtnStyle(
primary, Colors.transparent, second),
onPressed: () {
if (formKey.currentState!
.saveAndValidate()) {
String name =
formKey.currentState!.value['name'];
parent.read<AssignAreaAgencyBloc>().add(
EstPointPersonAddAgency(
agency: Agency(
category:
selectedAgencyCategory,
id: null,
name: name,
privateEntity: isPrivate)));
Navigator.pop(context);
}
},
child: const Text("Add")),
)
],
)),
);
});
})
],
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocConsumer<AssignAreaAgencyBloc, AssignAreaAgencyState>(
listener: (context, state) {
if (state is EstPointPersonAgencyLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is EstPointPersonAgenciesLoaded ||
state is EstPointPersonAgencyAddesState ||
state is EstPointAgencyErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
builder: (context, state) {
final parent = context;
if (state is EstPointPersonAgenciesLoaded) {
agencyCategory = state.agencyCategory;
if (state.agencies != null && state.agencies!.isNotEmpty) {
return ListView.builder(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
itemCount: state.agencies!.length,
itemBuilder: (BuildContext context, int index) {
return Column(
children: [
Container(
width: screenWidth,
decoration: box1(),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
child: Expanded(
child: Row(
children: [
CircleAvatar(
child: Text('${index + 1}'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(state.agencies![index].areaName!,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500,
color: primary)),
),
],
)),
),
const SizedBox(
height: 5,
)
],
);
});
} else {
return const EmptyData(
message: "No Object available. Please click + to add.");
}
}
if (state is EstPointAgencyErrorState) {
return SomethingWentWrong(
message: state.message,
onpressed: () {
context.read<ObjectBloc>().add(GetObjects());
});
}
return Container();
},
),
),
);
}
}

View File

@ -0,0 +1,536 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/rbac/rbac_station.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/error_state.dart';
import '../../../../bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart';
import '../../../../model/utils/agency.dart';
import '../../../../theme-data.dart/box_shadow.dart';
import '../../../../theme-data.dart/colors.dart';
import '../../../../theme-data.dart/form-style.dart';
import '../../../../utils/formatters.dart';
import '../../../../utils/global.dart';
import '../../../../widgets/empty_data.dart';
class EstPointPersonStationScreen extends StatelessWidget {
const EstPointPersonStationScreen({
super.key,
});
@override
Widget build(BuildContext context) {
final agencyFocusNode = FocusNode();
List<RbacStation> stations = [];
final formKey = GlobalKey<FormBuilderState>();
Agency selectedAgency;
List<Map<dynamic, dynamic>> hierarchy = [];
return Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: primary,
title: const Text("Station Screen"),
actions: [
AddLeading(onPressed: () {
BuildContext parent = context;
// showDialog(
// context: context,
// builder: (BuildContext context) {
// return AlertDialog(
// title: const Text("Add New Station"),
// content: FormBuilder(
// key: formKey,
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// FormBuilderTextField(
// name: "object_name",
// decoration: normalTextFieldStyle(
// "Role name *", "Role name "),
// validator: FormBuilderValidators.required(
// errorText: "This field is required"),
// ),
// const SizedBox(
// height: 8,
// ),
// FormBuilderTextField(
// name: "slug",
// decoration: normalTextFieldStyle("Slug ", "Slug"),
// ),
// const SizedBox(
// height: 8,
// ),
// FormBuilderTextField(
// validator: FormBuilderValidators.maxLength(50,
// errorText: "Max characters only 50"),
// name: "shorthand",
// decoration:
// normalTextFieldStyle("Shorthand ", "Shorthand"),
// ),
// const SizedBox(
// height: 12,
// ),
// SizedBox(
// width: double.infinity,
// height: 50,
// child: ElevatedButton(
// style: mainBtnStyle(
// primary, Colors.transparent, second),
// onPressed: () {
// if (formKey.currentState!
// .saveAndValidate()) {
// String name = formKey
// .currentState!.value['object_name'];
// String? slug =
// formKey.currentState!.value['slug'];
// String? short = formKey
// .currentState!.value['shorthand'];
// parent.read<RoleBloc>().add(AddRbacRole(
// id: id,
// name: name,
// shorthand: short,
// slug: slug));
// Navigator.pop(context);
// }
// },
// child: const Text("Add"))),
// ],
// ),
// ),
// );
// });
})
],
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child:
BlocConsumer<EstPointPersonStationBloc, EstPointPersonStationState>(
listener: (context, state) {
if (state is EstPersonStationLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is EstPersonStationLoadedState ||
state is EstPersonStationErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
builder: (context, state) {
final parent = context;
if (state is EstPersonStationLoadedState) {
stations = state.stations;
int max = 0;
for (RbacStation station in stations) {
if (station.hierarchyOrderNo != null) {
if (max < station.hierarchyOrderNo!) {
max = station.hierarchyOrderNo!;
}
}
}
for (int i = 1; i <= max; i++) {
hierarchy.add({i: []});
}
for (var station in stations) {
if (station.hierarchyOrderNo != null) {
for (int i = 0; i <= max; i++) {
if (station.hierarchyOrderNo == i + 1) {
hierarchy[i][i + 1].add(station);
}
}
}
}
if (hierarchy[0][1].isNotEmpty) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: SearchField(
inputFormatters: [UpperCaseTextFormatter()],
itemHeight: 70,
focusNode: agencyFocusNode,
suggestions: state.assignedAreas
.map((AssignedArea agency) =>
SearchFieldListItem(agency.areaName!,
item: agency,
child: ListTile(
title: Text(
agency.areaName!,
overflow: TextOverflow.visible,
),
)))
.toList(),
searchInputDecoration:
normalTextFieldStyle("Filter", "").copyWith(
prefixIcon: const Icon(Icons.filter_list),
suffixIcon: IconButton(
icon: const Icon(Icons.arrow_drop_down),
onPressed: () {
agencyFocusNode.unfocus();
},
)),
onSuggestionTap: (agency) {
agencyFocusNode.unfocus();
},
validator: (agency) {
if (agency!.isEmpty) {
return "This field is required";
}
return null;
},
emptyWidget: const Center(
child: Text("No result found..."),
)),
),
Expanded(
child: ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: hierarchy[0][1].length,
itemBuilder: (BuildContext context, int index) {
List<RbacStation> second = [];
for (var rbacStation in hierarchy[1][2]) {
if (rbacStation.parentStation ==
hierarchy[0][1][index].id) {
second.add(rbacStation);
}
}
return Column(
children: [
Container(
width: screenWidth,
decoration: box1(),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
child: Row(
children: [
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text('1'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(
hierarchy[0][1][index]
.stationName!,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight.w500,
color: primary)),
),
],
)),
],
),
),
////SECOND
SizedBox(
child: second.isNotEmpty
? Column(
mainAxisSize: MainAxisSize.min,
children: second.map((e) {
List<RbacStation> childs = [];
if (max >= 3) {
for (RbacStation station
in hierarchy[2][3]) {
if (station.parentStation ==
e.id) {
childs.add(station);
}
}
} else {
childs = [];
}
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Expanded(
child: Container(
width: screenWidth,
decoration: box1(),
padding:
const EdgeInsets
.only(
left: 30),
child: Row(
children: [
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text(
'2'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(
e
.stationName!,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500,
color: primary)),
),
],
)),
],
),
),
),
],
),
////THIRD
SizedBox(
child: childs.isNotEmpty
? Column(
mainAxisSize:
MainAxisSize
.min,
children: childs
.map((e) {
List<RbacStation>
childs = [];
if (max >= 4) {
for (RbacStation station
in hierarchy[3][4]) {
if (station.parentStation ==
e.id) {
childs.add(station);
}
}
} else {
childs = [];
}
return Column(
children: [
Container(
width:
screenWidth,
decoration:
box1(),
padding: const EdgeInsets
.only(
left:
50),
child:
Row(
children: [
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text('3'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(e.stationName!, style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500, color: primary)),
),
],
)),
],
),
),
////Fourth
SizedBox(
child: childs.isNotEmpty
? Column(
mainAxisSize: MainAxisSize.min,
children: childs.map((e) {
List<RbacStation> childs = [];
if (max > 4) {
for (RbacStation station in hierarchy[4][5]) {
if (station.parentStation == e.id) {
childs.add(station);
}
}
} else {
childs = [];
}
return Column(
children: [
Container(
width: screenWidth,
decoration: box1(),
padding: const EdgeInsets.only(left: 80),
child: Row(
children: [
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text('4'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(e.stationName!, style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500, color: primary)),
),
],
)),
],
),
),
////Fifth
SizedBox(
child: childs.isNotEmpty
? Column(
mainAxisSize: MainAxisSize.min,
children: childs.map((e) {
List<RbacStation> childs = [];
if (max > 5) {
for (RbacStation station in hierarchy[5][6]) {
if (station.parentStation == e.id) {
childs.add(station);
}
}
} else {
childs = [];
}
return Column(
children: [
Container(
width: screenWidth,
decoration: box1(),
padding: const EdgeInsets.only(left: 80),
child: Row(
children: [
Expanded(
child: Row(
children: [
const CircleAvatar(
child: Text('5'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(e.stationName!, style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500, color: primary)),
),
],
)),
],
),
),
],
);
}).toList(),
)
: const SizedBox()),
],
);
}).toList(),
)
: const SizedBox()),
],
);
}).toList(),
)
: const SizedBox
.shrink()),
],
);
}).toList(),
)
: const SizedBox()),
const Divider(
height: 5,
),
],
);
}),
),
],
);
} else {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: SearchField(
inputFormatters: [UpperCaseTextFormatter()],
itemHeight: 70,
focusNode: agencyFocusNode,
suggestions: state.assignedAreas
.map((AssignedArea agency) =>
SearchFieldListItem(agency.areaName!,
item: agency,
child: ListTile(
title: Text(
agency.areaName!,
overflow: TextOverflow.visible,
),
)))
.toList(),
searchInputDecoration:
normalTextFieldStyle("Filter", "").copyWith(
prefixIcon: const Icon(Icons.filter_list),
suffixIcon: IconButton(
icon: const Icon(Icons.arrow_drop_down),
onPressed: () {
agencyFocusNode.unfocus();
},
)),
onSuggestionTap: (agency) {
agencyFocusNode.unfocus();
},
validator: (agency) {
if (agency!.isEmpty) {
return "This field is required";
}
return null;
},
emptyWidget: const Center(
child: Text("No result found..."),
)),
),
const SizedBox(
height: 20,
),
const EmptyData(
message:
"No Station available. Please click + to add."),
],
);
}
}
if (state is EstPersonStationErrorState) {
return SomethingWentWrong(
message: state.message,
onpressed: () {
context.read<RoleBloc>().add(GetRoles());
});
}
return Container();
},
),
),
);
}
}

View File

@ -2,7 +2,6 @@ import 'dart:convert';
import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart'; import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import '../../../model/rbac/rbac_station.dart'; import '../../../model/rbac/rbac_station.dart';
import '../../../model/roles/pass_check/station_assign_area.dart'; import '../../../model/roles/pass_check/station_assign_area.dart';
class RbacStationServices{ class RbacStationServices{
@ -11,7 +10,7 @@ class RbacStationServices{
String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z"; String xClientKey = "unitK3CQaXiWlPReDsBzmmwBZPd9Re1z";
String xClientKeySecret = "unitcYqAN7GGalyz"; String xClientKeySecret = "unitcYqAN7GGalyz";
Future<List<RbacStation>> getStations({required int agencyId})async{ Future<List<RbacStation>> getStations({required String agencyId})async{
List<RbacStation> stations = []; List<RbacStation> stations = [];
String path = Url.instance.getStation(); String path = Url.instance.getStation();
Map<String,String> param = {"government_agency_id":agencyId.toString()}; Map<String,String> param = {"government_agency_id":agencyId.toString()};

View File

@ -417,6 +417,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.5" version: "2.0.5"
expandable:
dependency: "direct main"
description:
name: expandable
sha256: "9604d612d4d1146dafa96c6d8eec9c2ff0994658d6d09fed720ab788c7f5afc2"
url: "https://pub.dev"
source: hosted
version: "5.0.1"
expandable_group: expandable_group:
dependency: "direct main" dependency: "direct main"
description: description:
@ -571,6 +579,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.2" version: "2.0.2"
flutter_simple_treeview:
dependency: "direct main"
description:
name: flutter_simple_treeview
sha256: ad4978d2668dd078d3a09966832da111bef9102dd636e572c50c80133b7ff4d9
url: "https://pub.dev"
source: hosted
version: "3.0.2"
flutter_spinkit: flutter_spinkit:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -87,6 +87,9 @@ dependencies:
group_list_view: ^1.1.1 group_list_view: ^1.1.1
search_page: ^2.3.0 search_page: ^2.3.0
file_picker: ^5.3.1 file_picker: ^5.3.1
expandable: ^5.0.1
flutter_simple_treeview: ^3.0.2
dev_dependencies: dev_dependencies: