This commit is contained in:
erfan hayat'bakhsh
2020-08-01 14:16:20 +04:30
parent 30f10dca2e
commit e4d29c4e3c
71 changed files with 5018 additions and 2319 deletions
+104 -91
View File
@@ -4,6 +4,7 @@ import 'package:cssd/providers/test_results.dart';
import 'package:cssd/widgets/TestResultScreens/Add/form_creator.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:random_string/random_string.dart';
class FormPage extends StatefulWidget {
final String name;
@@ -26,39 +27,41 @@ class _FormPageState extends State<FormPage> {
List<Map<String, dynamic>> formInputs;
void _saveForm() {
final batchId = randomString(10);
formatData(formInputs);
if (this.widget.testResultId != null && this.widget.testResultId !=''){
var prvObject = Provider.of<TestResultsProvider>(context, listen: false);
if (this.widget.testResultId != null && this.widget.testResultId != '') {
values['_method'] = 'put';
TestResultsProvider.updateTestResult(this.widget.testResultId, values).then((_){
TestResultsProvider.updateTestResult(this.widget.testResultId, values)
.then((_) {
Navigator.of(context).pop();
});
} else {
setState(() {
_isLoading = true;
});
TestResultsProvider.createTestResult(values).then((_) {
prvObject.createTestResult(values, batchId).then((result) {
setState(() {
_isLoading = false;
});
showDialog(
context: context,
builder: (ctx) => AlertDialog(
content: Text('Test added.'),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(ctx).pop();
},
child: Text('Ok'),
)
],
),
).then((_) {
Navigator.of(context).popAndPushNamed(Routes.testResultScreen);
});
if (result == 'done') {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
content: Text('Test added.'),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(ctx).pop();
},
child: Text('Ok'),
)
],
),
).then((value) =>
Navigator.of(context).popAndPushNamed(Routes.testResultScreen));
}
});
}
}
@@ -70,11 +73,10 @@ class _FormPageState extends State<FormPage> {
});
Provider.of<Inputs>(context)
.getInputs(
testResultId: this.widget.testResultId ?? "",
name: this.widget.name ?? "",
uniqueCode: this.widget.uniqueCode ?? "",
testTypeId: this.widget.testTypeId ?? ""
)
testResultId: this.widget.testResultId ?? "",
name: this.widget.name ?? "",
uniqueCode: this.widget.uniqueCode ?? "",
testTypeId: this.widget.testTypeId ?? "")
.then((_) {
setState(() {
_isLoading = false;
@@ -87,81 +89,93 @@ class _FormPageState extends State<FormPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Add Test Result'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.save),
return WillPopScope(
onWillPop: () async {
Navigator.pushReplacementNamed(
context,
Routes.testResultAddScreen,
);
return true;
},
child: Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Add Test Result'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.save),
onPressed: () {
_saveForm();
},
)
],
leading: IconButton(
icon: Icon(
Icons.keyboard_arrow_left,
size: 35,
),
onPressed: () {
_saveForm();
Navigator.of(context).popAndPushNamed(Routes.testResultScreen);
},
)
],
leading: IconButton(
icon: Icon(
Icons.keyboard_arrow_left,
size: 35,
),
onPressed: () {
Navigator.of(context).popAndPushNamed(Routes.testResultScreen);
},
),
),
body: Column(
children: <Widget>[
Expanded(
child: _isLoading
? Center(child: CircularProgressIndicator())
: Form(
key: _form,
child: Consumer<Inputs>(
builder: (context, inputs, _) {
formInputs = inputs.inputItems;
// print(formInputs);
return formInputs.length != 0 ? FormCreator(
form: inputs.inputItems,
onChanged: (value) {
formInputs = value;
},
) : Center(child: Text('An error happen!!!'),);
},
body: Column(
children: <Widget>[
Expanded(
child: _isLoading
? Center(child: CircularProgressIndicator())
: Form(
key: _form,
child: Consumer<Inputs>(
builder: (context, inputs, _) {
formInputs = inputs.inputItems;
return formInputs.length != 0
? FormCreator(
form: inputs.inputItems,
onChanged: (value) {
formInputs = value;
},
)
: Center(
child: Text('An error happen!!!'),
);
},
),
),
),
),
// https://www.cssd-doc.com/api/GetInfo
// InkWell(
// onTap: () {
// _saveForm();
// },
// child: Container(
// padding: EdgeInsets.symmetric(horizontal: 60, vertical: 15),
// margin: EdgeInsets.symmetric(vertical: 20, horizontal: 50),
// decoration: BoxDecoration(
// gradient: LinearGradient(colors: [Colors.blue, Colors.green]),
// borderRadius: BorderRadius.circular(10),
// ),
// child: Text(
// 'Save',
// style: TextStyle(color: Colors.white, fontSize: 17),
// textAlign: TextAlign.center,
// ),
// ),
// ),
],
));
),
// https://www.cssd-doc.com/api/GetInfo
// InkWell(
// onTap: () {
// _saveForm();
// },
// child: Container(
// padding: EdgeInsets.symmetric(horizontal: 60, vertical: 15),
// margin: EdgeInsets.symmetric(vertical: 20, horizontal: 50),
// decoration: BoxDecoration(
// gradient: LinearGradient(colors: [Colors.blue, Colors.green]),
// borderRadius: BorderRadius.circular(10),
// ),
// child: Text(
// 'Save',
// style: TextStyle(color: Colors.white, fontSize: 17),
// textAlign: TextAlign.center,
// ),
// ),
// ),
],
)),
);
}
void formatData(inputs) {
for (var input in inputs) {
if(input['type'] != 'Form') {
if(input['key'] == 'result') {
if (input['type'] != 'Form') {
if (input['key'] == 'result') {
values[input["key"]] = input["value"] ? "Accept" : "Reject";
// print('${input["key"]} : ${input["value"] ? "Accept" : "Reject"}');
} else if(input['key'] == 'date') {
} else if (input['key'] == 'date') {
var date = input["value"];
values[input["key"]] = "${date.year}-${date.month}-${date.day}";
} else {
values[input["key"]] = input["value"];
@@ -172,7 +186,6 @@ class _FormPageState extends State<FormPage> {
formatData(input['children']);
}
}
print(values);
print(values);
}
}