You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
224 lines
8.7 KiB
Dart
224 lines
8.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:test_sa/controllers/api_routes/http_status_manger.dart';
|
|
import 'package:test_sa/controllers/localization/localization.dart';
|
|
import 'package:test_sa/controllers/providers/api/gas_refill_provider.dart';
|
|
import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
|
import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
|
|
import 'package:test_sa/models/enums/user_types.dart';
|
|
import 'package:test_sa/models/gas_refill/gas_refill_model.dart';
|
|
import 'package:test_sa/models/subtitle.dart';
|
|
import 'package:test_sa/views/app_style/sizing.dart';
|
|
import 'package:test_sa/views/widgets/buttons/app_back_button.dart';
|
|
import 'package:test_sa/views/widgets/buttons/app_button.dart';
|
|
import 'package:test_sa/views/widgets/buttons/app_icon_button.dart';
|
|
import 'package:test_sa/views/widgets/gas_refill/gas_refill_create_details_item.dart';
|
|
import 'package:test_sa/views/widgets/gas_refill/gas_refill_update_details_item.dart';
|
|
import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
|
|
import 'package:test_sa/views/widgets/requests/info_row.dart';
|
|
import 'package:test_sa/views/widgets/requests/request_status.dart';
|
|
import 'package:test_sa/views/widgets/status/gas_refill/gas_status.dart';
|
|
import 'package:test_sa/views/widgets/titles/app_sub_title.dart';
|
|
|
|
import '../../../app_style/colors.dart';
|
|
class GasRefillDetails extends StatefulWidget {
|
|
final GasRefillModel model;
|
|
const GasRefillDetails({Key key, this.model}) : super(key: key);
|
|
|
|
@override
|
|
State<GasRefillDetails> createState() => _GasRefillDetailsState();
|
|
}
|
|
|
|
class _GasRefillDetailsState extends State<GasRefillDetails> {
|
|
|
|
final GasRefillModel _model = GasRefillModel();
|
|
bool _enableEdit = false;
|
|
bool _validate = false;
|
|
UserProvider _userProvider;
|
|
SettingProvider _settingProvider;
|
|
GasRefillProvider _gasRefillProvider;
|
|
bool _isLoading = false;
|
|
Subtitle _subtitle;
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
_update() async {
|
|
_validate = true;
|
|
if(!_formKey.currentState.validate()){
|
|
setState(() {});
|
|
return false;
|
|
}
|
|
_formKey.currentState.save();
|
|
|
|
_isLoading =true;
|
|
setState(() {});
|
|
int status = await _gasRefillProvider.updateModel(
|
|
user: _userProvider.user,
|
|
host: _settingProvider.host,
|
|
newModel: _model,
|
|
oldModel: widget.model
|
|
);
|
|
_isLoading =false;
|
|
setState(() {});
|
|
if(status >= 200 && status < 300){
|
|
Fluttertoast.showToast(
|
|
msg: _subtitle.requestCompleteSuccessfully,
|
|
);
|
|
_enableEdit = false;
|
|
_validate = false;
|
|
//Navigator.of(context).pop();
|
|
}else{
|
|
String errorMessage = HttpStatusManger.getStatusMessage(
|
|
status: status, subtitle: _subtitle);
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
errorMessage
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
_model.fromGasRefillModel(widget.model);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
_subtitle = AppLocalization.of(context).subtitle;
|
|
_userProvider = Provider.of<UserProvider>(context);
|
|
_settingProvider = Provider.of<SettingProvider>(context);
|
|
_gasRefillProvider = Provider.of<GasRefillProvider>(context);
|
|
return Scaffold(
|
|
key: _scaffoldKey,
|
|
body: SafeArea(
|
|
child: Form(
|
|
key: _formKey,
|
|
child: LoadingManager(
|
|
isLoading: _isLoading,
|
|
isFailedLoading: false,
|
|
stateCode: 200,
|
|
onRefresh: () async {},
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
color: Theme.of(context).colorScheme.primary,
|
|
padding: const EdgeInsets.symmetric(horizontal: 0,vertical: 4),
|
|
child: Row(
|
|
children: [
|
|
const ABackButton(),
|
|
Expanded(
|
|
child: Center(
|
|
child: Text(
|
|
_subtitle.details,
|
|
style: Theme.of(context).textTheme.headline6.copyWith(
|
|
color: AColors.white,
|
|
fontStyle: FontStyle.italic
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if(_userProvider.user.type == UsersTypes.engineer)
|
|
AIconButton(
|
|
iconData: _enableEdit ? Icons.cancel : Icons.edit,
|
|
color: Theme.of(context).colorScheme.onPrimary,
|
|
buttonSize: 42,
|
|
backgroundColor: AColors.green,
|
|
onPressed: () async {
|
|
_enableEdit = !_enableEdit;
|
|
_model.fromGasRefillModel(widget.model);
|
|
setState(() {});
|
|
},
|
|
),
|
|
const SizedBox(width: 16,)
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
padding: EdgeInsets.all(16*AppStyle.getScaleFactor(context)),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
RequestInfoRow(
|
|
title: _subtitle.title,
|
|
info: _model.title,
|
|
),
|
|
RequestInfoRow(
|
|
title: _subtitle.hospital,
|
|
info: _model.clientName,
|
|
),
|
|
_enableEdit ?
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const SizedBox(height: 8,),
|
|
ASubTitle(_subtitle.status),
|
|
if(_validate && _model.status == null)
|
|
ASubTitle(_subtitle.requiredWord,color: Colors.red,),
|
|
const SizedBox(height: 4,),
|
|
GasStatusMenu(
|
|
initialValue: _model.status,
|
|
onSelect: (status){
|
|
_model.status = status;
|
|
},
|
|
)
|
|
],
|
|
):
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
"${_subtitle.status} : ",
|
|
style: Theme.of(context).textTheme.subtitle2,
|
|
textScaleFactor: AppStyle.getScaleFactor(context),
|
|
),
|
|
),
|
|
if(_model.status?.id != null)
|
|
StatusLabel(label: _model.status.name,
|
|
color: AColors.getGasStatusColor(_model.status.id)
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8,),
|
|
const ASubTitle("Gas Requests"),
|
|
const SizedBox(height: 8,),
|
|
ListView.builder(
|
|
shrinkWrap: true,
|
|
physics: const ClampingScrollPhysics(),
|
|
itemCount: _model.details.length,
|
|
itemBuilder: (context,index){
|
|
final details = _model.details[index];
|
|
return GasRefillUpdateDetailsItem(
|
|
details: details,
|
|
validate: _validate,
|
|
enableEdit: _enableEdit,
|
|
);
|
|
}
|
|
),
|
|
if(_enableEdit)
|
|
Column(
|
|
children: [
|
|
const SizedBox(height: 16,),
|
|
AButton(
|
|
text: _subtitle.update,
|
|
onPressed: _update,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|