Set some save button progress bar and toast message

This commit is contained in:
fhkhd
2024-01-28 03:27:43 +03:30
parent f07050c299
commit 8cb5900977
15 changed files with 610 additions and 505 deletions
+37 -24
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart';
import 'package:random_string/random_string.dart';
@@ -22,6 +23,7 @@ class FormPage extends StatefulWidget {
class _FormPageState extends State<FormPage> {
bool _isInit = true;
bool _isLoading = false;
bool _isLoadingButton = false;
bool isAdding = false;
final _form = GlobalKey<FormState>();
Map<String, dynamic> values = {};
@@ -39,29 +41,26 @@ class _FormPageState extends State<FormPage> {
});
} else {
setState(() {
_isLoading = true;
_isLoadingButton = true;
});
prvObject.createTestResult(values, batchId).then(
(result) {
setState(() {
_isLoading = false;
_isLoadingButton = false;
});
if (result == 'done') {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
content: Text('Test added.'),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(ctx).pop();
},
child: Text('Ok'),
)
],
),
).then((value) =>
Navigator.of(context).popAndPushNamed(Routes.testResultScreen));
Navigator.of(context).popAndPushNamed(Routes.testResultScreen);
Fluttertoast.showToast(
msg: "Test added.",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
} else {
Fluttertoast.showToast(
msg: result,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
}
},
);
@@ -109,15 +108,29 @@ class _FormPageState extends State<FormPage> {
child: Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('Add Test Result', style: TextStyle(color: Colors.white,),),
title: Text(
'Add Test Result',
style: TextStyle(
color: Colors.white,
),
),
backgroundColor: Colors.black,
actions: <Widget>[
IconButton(
icon: Icon(Icons.save, color: Colors.white,),
onPressed: () {
_saveForm();
},
)
_isLoadingButton
? Center(
child: CircularProgressIndicator(
color: Colors.white,
),
)
: IconButton(
icon: Icon(
Icons.save,
color: Colors.white,
),
onPressed: () {
_saveForm();
},
)
],
leading: IconButton(
icon: Icon(