add station for establishment point person and superadmin

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-08-17 10:49:33 +08:00
parent de4107e4e8
commit 14dd524c71
12 changed files with 925 additions and 263 deletions

View File

@ -2,7 +2,9 @@ import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/rbac/rbac_station.dart';
import 'package:unit2/sevices/roles/rbac_operations/station_services.dart';
import '../../../../model/rbac/station_type.dart';
import '../../../../model/utils/agency.dart';
import '../../../../model/utils/position.dart';
import '../../../../utils/profile_utilities.dart';
part 'station_event.dart';
part 'station_state.dart';
@ -11,6 +13,8 @@ class StationBloc extends Bloc<StationEvent, StationState> {
StationBloc() : super(StationInitial()) {
List<RbacStation> stations = [];
List<Agency> agencies = [];
List<StationType> stationTypes = [];
List<PositionTitle> positions = [];
on<GetStations>((event, emit) async {
emit(StationLoadingState());
try {
@ -22,13 +26,41 @@ class StationBloc extends Bloc<StationEvent, StationState> {
await ProfileUtilities.instance.getAgecies();
agencies = newAgencies;
}
emit(StationLoadedState(stations: stations, agencies: agencies));
if (stationTypes.isEmpty) {
stationTypes = await RbacStationServices.instance.getStationTypes();
}
if (positions.isEmpty) {
positions = await RbacStationServices.instance.getPositionTitle();
}
emit(StationLoadedState(
stations: stations,
agencies: agencies,
stationTypes: stationTypes,
positions: positions));
} catch (e) {
emit(StationErrorState(message: e.toString()));
}
});
on<FilterStation>((event, emit)async {
// emit(StationLoadingState());
on<AddRbacStation>((event, emit) async {
emit(StationLoadingState());
try {
Map<dynamic, dynamic> statusResponse = await RbacStationServices
.instance
.addStation(station: event.station);
if (statusResponse['success']) {
RbacStation newStation = RbacStation.fromJson(statusResponse['data']);
stations.add(newStation);
emit(RbacStationAddedState(response: statusResponse));
} else {
emit(RbacStationAddedState(response: statusResponse));
}
} catch (e) {
emit(StationErrorState(message: e.toString()));
}
});
on<FilterStation>((event, emit) async {
emit(StationLoadingState());
try {
stations = await RbacStationServices.instance
.getStations(agencyId: event.agencyId.toString());
@ -38,10 +70,16 @@ class StationBloc extends Bloc<StationEvent, StationState> {
await ProfileUtilities.instance.getAgecies();
agencies = newAgencies;
}
emit(StationLoadedState(stations: stations, agencies: agencies));
emit(StationLoadedState(
stations: stations,
agencies: agencies,
positions: positions,
stationTypes: stationTypes));
} catch (e) {
emit(StationErrorState(message: e.toString()));
}
});
}
}

View File

@ -10,9 +10,17 @@ abstract class StationEvent extends Equatable {
class GetStations extends StationEvent {
final int agencyId;
const GetStations({required this.agencyId});
@override
List<Object> get props => [agencyId];
}
class FilterStation extends StationEvent {
final int agencyId;
const FilterStation({required this.agencyId});
@override
List<Object> get props => [agencyId];
}
class AddRbacStation extends StationEvent {
final RbacStation station;
const AddRbacStation({required this.station});
}

View File

@ -12,9 +12,11 @@ class StationInitial extends StationState {}
class StationLoadedState extends StationState {
final List<Agency> agencies;
final List<RbacStation> stations;
const StationLoadedState({required this.stations, required this.agencies});
final List<StationType> stationTypes;
final List<PositionTitle> positions;
const StationLoadedState({required this.stations, required this.agencies,required this.positions, required this.stationTypes});
@override
List<Object> get props => [agencies,stations];
List<Object> get props => [agencies,stations,stationTypes,positions];
}
class StationLoadingState extends StationState {}
@ -27,6 +29,17 @@ class StationErrorState extends StationState {
}
class FilterStationState extends StationState {
final int agencyId;
const FilterStationState({required this.agencyId});
final List<Agency> agencies;
final List<RbacStation> stations;
final List<StationType> stationTypes;
final List<PositionTitle> positions;
const FilterStationState({required this.stations, required this.agencies,required this.positions, required this.stationTypes});
@override
List<Object> get props => [agencies,stations,stationTypes,positions];
}
class RbacStationAddedState extends StationState{
final Map<dynamic,dynamic> response;
const RbacStationAddedState({required this.response});
}

View File

@ -1,14 +1,10 @@
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/roles/pass_check/station_assign_area.dart';
import 'package:unit2/model/utils/position.dart';
import '../../../../../model/rbac/rbac_station.dart';
import '../../../../../model/utils/agency.dart';
import '../../../../../model/rbac/station_type.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';
@ -43,7 +39,7 @@ class EstPointPersonStationBloc
});
on<AddEstPointPersonStation>((event, emit) async {
emit(EstPersonStationLoadingState());
// try {
try {
Map<dynamic, dynamic> statusResponse = await RbacStationServices
.instance
.addStation(station: event.station);
@ -54,9 +50,9 @@ class EstPointPersonStationBloc
} else {
emit(EstPointPersonAddedState(response: statusResponse));
}
// } catch (e) {
// emit(EstPersonStationErrorState(message: e.toString()));
// }
} catch (e) {
emit(EstPersonStationErrorState(message: e.toString()));
}
});
}
}

View File

@ -4,6 +4,7 @@
import 'package:unit2/model/rbac/station_type.dart';
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
class RbacStation {

View File

@ -0,0 +1,40 @@
// To parse this JSON data, do
//
// final rbacStationType = rbacStationTypeFromJson(jsonString);
class StationType {
final int? id;
final String? typeName;
final String? color;
final int? order;
final bool? isActive;
final String? group;
StationType({
required this.id,
required this.typeName,
required this.color,
required this.order,
required this.isActive,
required this.group,
});
factory StationType.fromJson(Map<String, dynamic> json) => StationType(
id: json["id"],
typeName: json["type_name"],
color: json["color"],
order: json["order"],
isActive: json["is_active"],
group: json["group"],
);
Map<String, dynamic> toJson() => {
"id": id,
"type_name": typeName,
"color": color,
"order": order,
"is_active": isActive,
"group": group,
};
}

View File

@ -3,6 +3,7 @@
// final assignArea = assignAreaFromJson(jsonString);
import '../../rbac/rbac_station.dart';
import '../../rbac/station_type.dart';
class StationAssignArea {
final bool? isactive;
@ -132,38 +133,4 @@ class ChildStationInfo {
}
class StationType {
final int? id;
final String? typeName;
final String? color;
final int? order;
final bool? isActive;
final String? group;
StationType({
required this.id,
required this.typeName,
required this.color,
required this.order,
required this.isActive,
required this.group,
});
factory StationType.fromJson(Map<String, dynamic> json) => StationType(
id: json["id"],
typeName: json["type_name"],
color: json["color"],
order: json["order"],
isActive: json["is_active"],
group: json["group"],
);
Map<String, dynamic> toJson() => {
"id": id,
"type_name": typeName,
"color": color,
"order": order,
"is_active": isActive,
"group": group,
};
}

View File

@ -1,4 +1,3 @@
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';
@ -9,29 +8,57 @@ import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/rbac/rbac_operations/role/role_bloc.dart';
import 'package:unit2/bloc/rbac/rbac_operations/station/station_bloc.dart';
import 'package:unit2/model/rbac/rbac_station.dart';
import 'package:unit2/screens/superadmin/role/shared_pop_up_menu.dart';
import 'package:unit2/model/roles/pass_check/station_assign_area.dart';
import 'package:unit2/model/utils/agency.dart';
import 'package:unit2/model/utils/position.dart';
import 'package:unit2/widgets/Leadings/add_leading.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/alerts.dart';
import '../../../../bloc/role/pass_check/est_point_person/est_point_person_station/est_point_person_station_bloc.dart';
import '../../../../model/rbac/station_type.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/alerts.dart';
import '../../../../utils/global.dart';
import '../../../../widgets/empty_data.dart';
import '../../../utils/formatters.dart';
import '../../../utils/global.dart';
import '../../../widgets/empty_data.dart';
import '../../profile/shared/add_for_empty_search.dart';
class RbacStationScreen extends StatelessWidget {
final int id;
const RbacStationScreen({super.key, required this.id});
class RbacStationScreen extends StatefulWidget {
final int agencyId;
const RbacStationScreen({
required this.agencyId,
super.key,
});
@override
State<RbacStationScreen> createState() => _RbacStationScreenState();
}
class _RbacStationScreenState extends State<RbacStationScreen> {
@override
Widget build(BuildContext context) {
final agencyFocusNode = FocusNode();
final rbacStationBloc = BlocProvider.of<StationBloc>(context);
List<RbacStation> stations = [];
final formKey = GlobalKey<FormBuilderState>();
Agency selectedAgency;
List<Map<dynamic, dynamic>> hierarchy = [];
bool mainParent = false;
bool isWithinParent = true;
bool isHospital = false;
List<StationType> stationTypes = [];
List<PositionTitle> positions = [];
List<RbacStation> mainParentStations = [];
List<RbacStation> parentStations = [];
List<Agency> agencies = [];
RbacStation? selectedMainParentStation;
RbacStation? selectedParentStation;
StationType? selectedStationType;
PositionTitle? selectedPositiontitle;
int selectedAgencyId = widget.agencyId;
final addStationTypeController = TextEditingController();
final stationTypeFocusNode = FocusNode();
final agencyFocusNode = FocusNode();
return Scaffold(
appBar: AppBar(
centerTitle: true,
@ -40,43 +67,297 @@ class RbacStationScreen extends StatelessWidget {
actions: [
AddLeading(onPressed: () {
BuildContext parent = context;
mainParentStations = [];
mainParent = stations.isEmpty ? true : false;
for (RbacStation station in stations) {
if (station.hierarchyOrderNo == 1) {
mainParentStations.add(station);
}
}
/////Add new tation
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("Add New Station"),
content: FormBuilder(
content: SingleChildScrollView(
child: FormBuilder(
key: formKey,
child: Column(
child: StatefulBuilder(builder: (context, setState) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
FormBuilderTextField(
name: "object_name",
////is main parent
FormBuilderSwitch(
initialValue: mainParent,
activeColor: second,
onChanged: (value) {
setState(() {
mainParent = !mainParent;
});
},
decoration: normalTextFieldStyle(
"Role name *", "Role name "),
"is Main Parent?", 'is Main Parent?'),
name: 'main-parent',
title: Text(mainParent ? "YES" : "NO"),
validator: FormBuilderValidators.required(
errorText: "This field is required"),
),
const SizedBox(
height: 8,
SizedBox(
height: mainParent ? 0 : 8,
),
FormBuilderTextField(
name: "slug",
decoration: normalTextFieldStyle("Slug ", "Slug"),
//// selected main parent
SizedBox(
child: mainParent == true
? const SizedBox.shrink()
: FormBuilderDropdown<RbacStation>(
decoration: normalTextFieldStyle(
"Main Parent Station",
"Main Parent Station"),
name: "parent-stations",
items: mainParentStations.isEmpty
? []
: mainParentStations.map((e) {
return DropdownMenuItem(
value: e,
child: Text(e.stationName!),
);
}).toList(),
onChanged: (RbacStation? e) {
setState(() {
selectedMainParentStation = e;
parentStations = [];
for (RbacStation station
in stations) {
if (station.mainParentStation ==
selectedMainParentStation!
.id) {
parentStations.add(station);
}
}
parentStations.add(
selectedMainParentStation!);
});
},
validator:
FormBuilderValidators.required(
errorText:
"This field is required"),
),
const SizedBox(
height: 8,
),
FormBuilderTextField(
validator: FormBuilderValidators.maxLength(50,
errorText: "Max characters only 50"),
name: "shorthand",
decoration:
normalTextFieldStyle("Shorthand ", "Shorthand"),
SizedBox(
height: mainParent ? 0 : 8,
),
////parent station
SizedBox(
child: mainParent == true
? const SizedBox.shrink()
: FormBuilderDropdown<RbacStation>(
decoration: normalTextFieldStyle(
"Parent Station", "Parent Station"),
name: "parent-stations",
onChanged: (RbacStation? e) {
setState(() {
selectedParentStation = e;
});
},
items: parentStations.isEmpty
? []
: parentStations.map((e) {
return DropdownMenuItem(
value: e,
child: Text(e.stationName!),
);
}).toList(),
validator:
FormBuilderValidators.required(
errorText:
"This field is required"),
),
),
const SizedBox(
height: 12,
),
////Station Type
SearchField(
itemHeight: 50,
suggestionsDecoration: box1(),
suggestions: stationTypes
.map((StationType stationType) =>
SearchFieldListItem(
stationType.typeName!,
item: stationType,
child: Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 10),
child: ListTile(
title: Text(
stationType.typeName!,
overflow: TextOverflow.visible,
)),
)))
.toList(),
validator: (station) {
if (station!.isEmpty) {
return "This field is required";
}
return null;
},
focusNode: stationTypeFocusNode,
searchInputDecoration:
normalTextFieldStyle("Station Type *", "")
.copyWith(
suffixIcon: GestureDetector(
onTap: () => stationTypeFocusNode.unfocus(),
child: const Icon(Icons.arrow_drop_down),
)),
onSuggestionTap: (position) {
setState(() {
selectedStationType = position.item!;
stationTypeFocusNode.unfocus();
});
},
emptyWidget: EmptyWidget(
title: "Add StationType",
controller: addStationTypeController,
onpressed: () {
setState(() {
StationType stationType = StationType(
id: null,
typeName:
addStationTypeController.text,
color: null,
order: null,
isActive: null,
group: null);
stationTypes.add(stationType);
Navigator.pop(context);
});
}),
),
const SizedBox(
height: 12,
),
////Position title
FormBuilderDropdown(
decoration: normalTextFieldStyle(
"Head Position", "Head Position"),
name: "head-position",
items: positions.map((e) {
return DropdownMenuItem(
value: e,
child: Text(e.title!),
);
}).toList(),
onChanged: (title) {
selectedPositiontitle = title;
},
),
const SizedBox(
height: 12,
),
////is within parent
FormBuilderSwitch(
initialValue: true,
activeColor: second,
onChanged: (value) {
setState(() {
isWithinParent = value!;
});
},
decoration: normalTextFieldStyle(
"Location of the station within this parent?",
'Location of the station within this parent?'),
name: 'isWithinParent',
title: Text(isWithinParent ? "YES" : "NO"),
),
const SizedBox(
height: 12,
),
Row(
//// Station Name
children: [
Flexible(
child: FormBuilderTextField(
validator:
FormBuilderValidators.required(
errorText:
"This Field is required"),
decoration: normalTextFieldStyle(
"Station name", "Station name"),
name: "station-name"),
),
const SizedBox(
width: 12,
),
//// Acronym
Flexible(
child: FormBuilderTextField(
validator:
FormBuilderValidators.required(
errorText:
"This Field is required"),
decoration: normalTextFieldStyle(
"Acronym", "Acronym"),
name: "acronym"),
),
],
),
const SizedBox(
height: 12,
),
FormBuilderTextField(
////Description
decoration: normalTextFieldStyle(
"Station description",
"Station description"),
name: "station-description"),
const SizedBox(
height: 12,
),
Row(
children: [
Flexible(
////Code
child: FormBuilderTextField(
decoration: normalTextFieldStyle(
"Code", "Code"),
name: "code"),
),
const SizedBox(
width: 12,
),
Flexible(
//// Full Code
child: FormBuilderTextField(
decoration: normalTextFieldStyle(
"Full Code", "Full Code"),
name: "fullcode"),
),
],
),
const SizedBox(
height: 12,
),
////is Hospital
FormBuilderSwitch(
initialValue: isHospital,
activeColor: second,
onChanged: (value) {
setState(() {
isHospital = !isHospital;
});
},
decoration:
normalTextFieldStyle("Is Hospital", ''),
name: 'isHospital',
title: Text(isHospital == true ? "YES" : "NO"),
),
const SizedBox(
height: 20,
),
SizedBox(
width: double.infinity,
height: 50,
@ -84,51 +365,91 @@ class RbacStationScreen extends StatelessWidget {
style: mainBtnStyle(
primary, Colors.transparent, second),
onPressed: () {
RbacStation? newStation;
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));
String? stationName = formKey
.currentState!
.value['station-name'];
String? acronym = formKey
.currentState!.value['acronym'];
String? code = formKey
.currentState!.value['code'];
String? fullcode = formKey
.currentState!.value['fullcode'];
String? description = formKey
.currentState!
.value['station-description'];
newStation = RbacStation(
id: null,
stationName: stationName,
stationType: selectedStationType,
hierarchyOrderNo: mainParent
? 1
: selectedParentStation!
.hierarchyOrderNo! +
1,
headPosition:
selectedPositiontitle?.title,
governmentAgency:
GovernmentAgency(
agencyid:
selectedAgencyId,
agencyname: null,
agencycatid: null,
privateEntity: null,
contactinfoid: null),
acronym: acronym,
parentStation: mainParent
? null
: selectedParentStation!.id!,
code: code,
fullcode: fullcode,
childStationInfo: null,
islocationUnderParent:
isWithinParent,
mainParentStation: mainParent
? null
: selectedMainParentStation!
.id!,
description: description,
ishospital: isHospital,
isactive: true,
sellingStation: null);
Navigator.pop(context);
rbacStationBloc.add(AddRbacStation(
station: newStation));
}
},
child: const Text("Add"))),
],
);
}),
),
),
);
});
})
],
}),
////Filter
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text(
"Select agency to filter stations",
textAlign: TextAlign.center,
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocConsumer<StationBloc, StationState>(
listener: (context, state) {},
builder: (context, state) {
final parent = context;
if (state is StationLoadedState) {
stations = state.stations;
if (state.stations.isNotEmpty) {
return Column(
children: [
content: SizedBox(
child: // //// Filter Agencies
Padding(
padding: const EdgeInsets.all(8),
child: SearchField(
inputFormatters: [UpperCaseTextFormatter()],
itemHeight: 70,
itemHeight: 100,
focusNode: agencyFocusNode,
suggestions: state.agencies
suggestions: agencies
.map((Agency agency) =>
SearchFieldListItem(agency.name!,
item: agency,
@ -141,7 +462,6 @@ class RbacStationScreen extends StatelessWidget {
.toList(),
searchInputDecoration:
normalTextFieldStyle("Filter", "").copyWith(
prefixIcon: const Icon(Icons.filter_list),
suffixIcon: IconButton(
icon: const Icon(Icons.arrow_drop_down),
onPressed: () {
@ -150,9 +470,12 @@ class RbacStationScreen extends StatelessWidget {
)),
onSuggestionTap: (agency) {
agencyFocusNode.unfocus();
selectedAgency = agency.item!;
parent.read<StationBloc>().add(
FilterStation(agencyId: selectedAgency.id!));
selectedAgencyId = agency.item!.id!;
print(selectedAgencyId);
Navigator.pop(context);
rbacStationBloc.add(FilterStation(
agencyId: selectedAgencyId));
},
validator: (agency) {
if (agency!.isEmpty) {
@ -164,12 +487,97 @@ class RbacStationScreen extends StatelessWidget {
child: Text("No result found..."),
)),
),
),
);
});
},
icon: const Icon(Icons.filter_list))
],
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocConsumer<StationBloc, StationState>(
listener: (context, state) {
if (state is StationLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is RbacStationAddedState) {
if (state.response['success']) {
successAlert(
context, "Adding Successfull!", state.response['message'],
() {
Navigator.of(context).pop();
context
.read<StationBloc>()
.add(GetStations(agencyId: selectedAgencyId));
});
} else {
errorAlert(context, "Adding Failed", state.response['message'],
() {
Navigator.of(context).pop();
context
.read<StationBloc>()
.add(GetStations(agencyId: selectedAgencyId));
});
}
}
if (state is StationLoadedState ||
state is RbacStationAddedState ||
state is StationErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
builder: (context, state) {
final parent = context;
if (state is StationLoadedState) {
stations = state.stations;
stationTypes = state.stationTypes;
positions = state.positions;
agencies = state.agencies;
int max = 0;
hierarchy = [];
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 (stations.isNotEmpty && hierarchy[0][1].isNotEmpty) {
return Column(
children: [
Expanded(
child: ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: state.stations.length,
itemCount: hierarchy[0][1].length,
itemBuilder: (BuildContext context, int index) {
List<RbacStation> second = [];
if (max >= 2) {
for (var rbacStation in hierarchy[1][2]) {
if (rbacStation.parentStation ==
hierarchy[0][1][index].id) {
second.add(rbacStation);
}
}
}
return Column(
children: [
Container(
@ -182,15 +590,15 @@ class RbacStationScreen extends StatelessWidget {
Expanded(
child: Row(
children: [
CircleAvatar(
child: Text('${index + 1}'),
const CircleAvatar(
child: Text('1'),
),
const SizedBox(
width: 12,
),
Flexible(
child: Text(
state.stations[index]
hierarchy[0][1][index]
.stationName!,
style: Theme.of(context)
.textTheme
@ -205,69 +613,261 @@ class RbacStationScreen extends StatelessWidget {
],
),
),
////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()
.copyWith(
boxShadow: []),
padding:
const EdgeInsets
.only(
left: 30),
child: Row(
children: [
Expanded(
child: Row(
children: [
Padding(
padding:
const EdgeInsets.all(
6),
child:
Text(
"2",
style: Theme.of(context)
.textTheme
.bodyLarge,
selectionColor:
Colors.redAccent,
)),
const SizedBox(
height: 3,
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()
.copyWith(boxShadow: []),
padding: const EdgeInsets
.only(
left:
50),
child:
Row(
children: [
Expanded(
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(6),
child: Text(
"3",
style: Theme.of(context).textTheme.bodyLarge,
selectionColor: Colors.redAccent,
)),
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().copyWith(boxShadow: []),
padding: const EdgeInsets.only(left: 80),
child: Row(
children: [
Expanded(
child: Row(
children: [
Padding(
padding: const EdgeInsets.all(6),
child: Text(
"4",
style: Theme.of(context).textTheme.bodyLarge,
selectionColor: Colors.redAccent,
)),
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.agencies
.map((Agency agency) =>
SearchFieldListItem(agency.name!,
item: agency,
child: ListTile(
title: Text(
agency.name!,
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();
selectedAgency = agency.item!;
parent.read<StationBloc>().add(
FilterStation(agencyId: selectedAgency.id!));
},
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."),
],
);
return const EmptyData(
message: "No Station available. Please click + to add.");
}
}
if (state is StationErrorState) {
@ -277,9 +877,7 @@ class RbacStationScreen extends StatelessWidget {
context.read<RoleBloc>().add(GetRoles());
});
}
if (state is StationLoadingState) {
return CircularProgressIndicator();
}
return Container();
},
),

View File

@ -204,6 +204,7 @@ class _DashBoardState extends State<DashBoard> {
);
}));
}
////Station
if (e.object.name == 'Station') {
showDialog(
context: context,
@ -227,8 +228,13 @@ class _DashBoardState extends State<DashBoard> {
onChanged: (value) {
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) {
return BlocProvider(
create: (context) => EstPointPersonStationBloc()..add( EstPointPersonGetStations(agencyId: value.areaid!,)),
child: EstPointPersonStationScreen(agencyId: value!.areaid!,),
create: (context) => EstPointPersonStationBloc()
..add(EstPointPersonGetStations(
agencyId: value.areaid!,
)),
child: EstPointPersonStationScreen(
agencyId: value!.areaid!,
),
);
}));
})

View File

@ -198,26 +198,15 @@ class SuperAdminMenu extends StatelessWidget {
);
}));
}
if (object.object.name == 'Station') {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => StationBloc()
..add(const GetStations(agencyId: 1)),
child: RbacStationScreen(
id: id,
),
);
}));
}
if (object.object.name == 'Station') {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => StationBloc()
..add(const GetStations(agencyId: 1)),
child: RbacStationScreen(
id: id,
child: const RbacStationScreen(
agencyId: 1,
),
);
}));

View File

@ -12,6 +12,7 @@ import 'package:unit2/model/utils/position.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/rbac/station_type.dart';
import '../../../../theme-data.dart/box_shadow.dart';
import '../../../../theme-data.dart/btn-style.dart';
import '../../../../theme-data.dart/colors.dart';
@ -57,11 +58,13 @@ class EstPointPersonStationScreen extends StatelessWidget {
AddLeading(onPressed: () {
BuildContext parent = context;
mainParentStations = [];
mainParent = stations.isEmpty?true:false;
for (RbacStation station in stations) {
if (station.hierarchyOrderNo == 1) {
mainParentStations.add(station);
}
}
//// Add New Station
showDialog(
context: context,
builder: (BuildContext context) {
@ -90,8 +93,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
validator: FormBuilderValidators.required(
errorText: "This field is required"),
),
const SizedBox(
height: 8,
SizedBox(
height: mainParent?0: 8,
),
//// selected main parent
SizedBox(
@ -132,8 +135,8 @@ class EstPointPersonStationScreen extends StatelessWidget {
"This field is required"),
),
),
const SizedBox(
height: 12,
SizedBox(
height: mainParent?0: 8,
),
////parent station
SizedBox(
@ -370,7 +373,7 @@ class EstPointPersonStationScreen extends StatelessWidget {
id: null,
stationName: stationName,
stationType: selectedStationType,
hierarchyOrderNo:
hierarchyOrderNo:mainParent?1:
selectedParentStation!
.hierarchyOrderNo! +
1,
@ -385,15 +388,15 @@ class EstPointPersonStationScreen extends StatelessWidget {
privateEntity: null,
contactinfoid: null),
acronym: acronym,
parentStation:
selectedParentStation!.id!,
parentStation: mainParent?null: selectedParentStation!.id!,
code: code,
fullcode: fullcode,
childStationInfo: null,
islocationUnderParent:
isWithinParent,
mainParentStation:
selectedMainParentStation!
mainParent?null:selectedMainParentStation!
.id!,
description: description,
ishospital: isHospital,
@ -489,12 +492,14 @@ class EstPointPersonStationScreen extends StatelessWidget {
itemCount: hierarchy[0][1].length,
itemBuilder: (BuildContext context, int index) {
List<RbacStation> second = [];
if(max >=2){
for (var rbacStation in hierarchy[1][2]) {
if (rbacStation.parentStation ==
hierarchy[0][1][index].id) {
second.add(rbacStation);
}
}
}
return Column(
children: [
Container(

View File

@ -4,6 +4,7 @@ import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart';
import 'package:http/http.dart' as http;
import '../../../model/rbac/rbac_station.dart';
import '../../../model/rbac/station_type.dart';
import '../../../model/roles/pass_check/station_assign_area.dart';
class RbacStationServices {
@ -99,12 +100,12 @@ class RbacStationServices {
};
String path = Url.instance.postStation();
// try {
try {
Map body = {
"station_name": station.stationName,
"acronym": station.acronym,
"station_type_id": station.stationType?.id,
"_station_type_name": station.stationType?.typeName,
"_station_type_name": station.stationType?.id != null?null:station.stationType?.typeName,
"parent_station_id": station.parentStation,
"hierarchy_order_no": station.hierarchyOrderNo,
"agency_id": station.governmentAgency!.agencyid,
@ -129,9 +130,9 @@ class RbacStationServices {
{'success': false},
);
}
// } catch (e) {
// throw e.toString();
// }
} catch (e) {
throw e.toString();
}
return statusResponse;
}
}