|
|
|
|
@ -27,12 +27,13 @@ import 'package:test_sa/views/widgets/status/gas_refill/gas_type.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/titles/app_sub_title.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../../controllers/localization/localization.dart';
|
|
|
|
|
import '../../../../controllers/providers/api/hospitals_provider.dart';
|
|
|
|
|
import '../../../../models/enums/user_types.dart';
|
|
|
|
|
|
|
|
|
|
class RequestGasRefill extends StatefulWidget {
|
|
|
|
|
static const String id = "/request-gas-refill";
|
|
|
|
|
|
|
|
|
|
const RequestGasRefill({Key key}) : super(key: key);
|
|
|
|
|
final GasRefillModel gasRefillModel;
|
|
|
|
|
const RequestGasRefill({this.gasRefillModel, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<RequestGasRefill> createState() => _RequestGasRefillState();
|
|
|
|
|
@ -47,10 +48,19 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
|
|
|
|
|
GasRefillProvider _gasRefillProvider;
|
|
|
|
|
GasRefillDetails _currentDetails = GasRefillDetails();
|
|
|
|
|
final TextEditingController _requestedQuantityController = TextEditingController();
|
|
|
|
|
final GasRefillModel _formModel = GasRefillModel(details: []);
|
|
|
|
|
GasRefillModel _formModel = GasRefillModel(details: []);
|
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
|
final GlobalKey _DetailsKey = GlobalKey<FormState>();
|
|
|
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
|
bool _firstTime = true;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
if (widget.gasRefillModel != null) {
|
|
|
|
|
_formModel = widget.gasRefillModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void setState(VoidCallback fn) {
|
|
|
|
|
@ -64,11 +74,25 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
|
|
|
|
|
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
setState(() {});
|
|
|
|
|
if (widget.gasRefillModel != null) {
|
|
|
|
|
if (!_formModel.validate()) {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
setState(() {});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int status = await _gasRefillProvider.createModel(
|
|
|
|
|
int status = widget.gasRefillModel == null
|
|
|
|
|
? await _gasRefillProvider.createModel(
|
|
|
|
|
user: _userProvider.user,
|
|
|
|
|
host: _settingProvider.host,
|
|
|
|
|
model: _formModel,
|
|
|
|
|
)
|
|
|
|
|
: await _gasRefillProvider.updateModel(
|
|
|
|
|
user: _userProvider.user,
|
|
|
|
|
host: _settingProvider.host,
|
|
|
|
|
oldModel: widget.gasRefillModel,
|
|
|
|
|
newModel: _formModel,
|
|
|
|
|
);
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
setState(() {});
|
|
|
|
|
@ -121,7 +145,21 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
|
|
|
|
|
_gasRefillProvider = Provider.of<GasRefillProvider>(context, listen: false);
|
|
|
|
|
_gasRefillProvider.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (widget.gasRefillModel != null && _firstTime) {
|
|
|
|
|
_formModel = widget.gasRefillModel;
|
|
|
|
|
HospitalsProvider().getHospitalsListByVal(searchVal: widget.gasRefillModel.clientName).then((value) {
|
|
|
|
|
_gasRefillProvider.hospital = value?.firstWhere((element) => element.name == widget.gasRefillModel.clientName, orElse: () => null);
|
|
|
|
|
print(_gasRefillProvider.hospital?.buildings?.length);
|
|
|
|
|
print(widget.gasRefillModel?.building?.name);
|
|
|
|
|
_gasRefillProvider.building = _gasRefillProvider.hospital?.buildings?.firstWhere((element) => element.name == widget.gasRefillModel?.building?.name, orElse: () => null);
|
|
|
|
|
_gasRefillProvider.floor = _gasRefillProvider.building?.floors?.firstWhere((element) => element.name == widget.gasRefillModel?.floor?.name, orElse: () => null);
|
|
|
|
|
_gasRefillProvider.department = _gasRefillProvider.floor?.departments?.firstWhere((element) => element.name == widget.gasRefillModel?.department?.departmentName, orElse: () => null);
|
|
|
|
|
_gasRefillProvider.startDate = widget.gasRefillModel?.startDate;
|
|
|
|
|
_gasRefillProvider.endDate = widget.gasRefillModel?.endDate;
|
|
|
|
|
_firstTime = false;
|
|
|
|
|
setState(() {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return Scaffold(
|
|
|
|
|
key: _scaffoldKey,
|
|
|
|
|
body: Form(
|
|
|
|
|
@ -141,7 +179,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
"Request Gas Refill",
|
|
|
|
|
"${widget.gasRefillModel == null ? "Request" : "Update"} Gas Refill",
|
|
|
|
|
style: Theme.of(context).textTheme.headline5.copyWith(color: Theme.of(context).primaryColor, fontSize: 28, fontWeight: FontWeight.bold),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -408,7 +446,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
|
|
|
|
|
}),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
AButton(
|
|
|
|
|
text: _subtitle.submit,
|
|
|
|
|
text: widget.gasRefillModel == null ? _subtitle.submit : _subtitle.update,
|
|
|
|
|
onPressed: _onSubmit,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
|