mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-12 06:08:55 +03:30
Set some save button progress bar and toast message
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:cssd/providers/items.dart';
|
||||
import 'package:cssd/widgets/ItemScreens/Add/item_save_button.dart';
|
||||
import 'package:cssd/widgets/ItemScreens/Add/upload_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:random_string/random_string.dart';
|
||||
@@ -45,14 +46,15 @@ class _ItemAddScreenState extends State<ItemAddScreen> {
|
||||
}
|
||||
|
||||
void _saveForm(String name, String size, String specific, String udi,
|
||||
String description) {
|
||||
String description, ItemProvider itemProvider) async {
|
||||
itemProvider.setLoadingButton();
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
if (!_form.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
Provider.of<ItemProvider>(context, listen: false)
|
||||
await Provider.of<ItemProvider>(context, listen: false)
|
||||
.createItemResult(
|
||||
name,
|
||||
size,
|
||||
@@ -67,37 +69,20 @@ class _ItemAddScreenState extends State<ItemAddScreen> {
|
||||
isLoading = false;
|
||||
});
|
||||
if (result == 'done') {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
content: Text('Item added.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
child: Text('Ok'),
|
||||
)
|
||||
],
|
||||
),
|
||||
).then((value) =>
|
||||
Navigator.of(context).popAndPushNamed(Routes.itemResultScreen));
|
||||
} else if (result == 'error') {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
content: Text('error.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
child: Text('Ok'),
|
||||
)
|
||||
],
|
||||
),
|
||||
Navigator.of(context).popAndPushNamed(Routes.itemResultScreen);
|
||||
Fluttertoast.showToast(
|
||||
msg: "Item added.",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
} else {
|
||||
Fluttertoast.showToast(
|
||||
msg: result,
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
}
|
||||
itemProvider.resetLoadingButton();
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -384,12 +369,12 @@ class _ItemAddScreenState extends State<ItemAddScreen> {
|
||||
ItemAddSaveButton(
|
||||
onTap: () {
|
||||
_saveForm(
|
||||
nameCTRL.text,
|
||||
sizeCTRL.text,
|
||||
specificCTRL.text,
|
||||
udiCTRL.text,
|
||||
descriptionCTRL.text,
|
||||
);
|
||||
nameCTRL.text,
|
||||
sizeCTRL.text,
|
||||
specificCTRL.text,
|
||||
udiCTRL.text,
|
||||
descriptionCTRL.text,
|
||||
itemProviderObject);
|
||||
},
|
||||
deviceBlockSize: _deviceBlockSize,
|
||||
),
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:cssd/widgets/Global/internet_error.dart';
|
||||
import 'package:cssd/widgets/LabelScreens/Detail/header.dart';
|
||||
import 'package:cssd/widgets/MyInfo/input_box.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../providers/auth.dart';
|
||||
@@ -23,6 +24,7 @@ class _MyInfoScreenState extends State<MyInfoScreen> {
|
||||
TextEditingController emailCTRL = new TextEditingController();
|
||||
|
||||
bool isInit = true;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() async {
|
||||
if (isInit) {
|
||||
@@ -48,7 +50,12 @@ class _MyInfoScreenState extends State<MyInfoScreen> {
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
titleSpacing: -10,
|
||||
title: Text('Dashboard', style: TextStyle(color: Colors.white,),),
|
||||
title: Text(
|
||||
'Dashboard',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.black,
|
||||
leading: IconButton(
|
||||
icon: Icon(
|
||||
@@ -126,55 +133,54 @@ class _MyInfoScreenState extends State<MyInfoScreen> {
|
||||
SizedBox(
|
||||
height: 40,
|
||||
),
|
||||
InkWell(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 60, vertical: 10),
|
||||
margin:
|
||||
EdgeInsets.only(top: 50, bottom: 20),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Text(
|
||||
'Save',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
await Provider.of<Auth>(context,
|
||||
listen: false)
|
||||
.setUserData(
|
||||
user!['id'],
|
||||
usernameCTRL.text,
|
||||
emailCTRL.text,
|
||||
)
|
||||
.then(
|
||||
(value) async => await showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
content: Text(
|
||||
'Info changed successfully.',
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text('Ok'),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
Consumer<Auth>(builder: (context, auth, _) {
|
||||
return InkWell(
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 60, vertical: 10),
|
||||
margin: EdgeInsets.only(
|
||||
top: 50, bottom: 20),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
borderRadius:
|
||||
BorderRadius.circular(5),
|
||||
),
|
||||
child: auth.isloading
|
||||
? Center(
|
||||
child:
|
||||
CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
'Save',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize:
|
||||
5 * _deviceBlockSize,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
)),
|
||||
onTap: () async {
|
||||
auth.setLoading();
|
||||
await Provider.of<Auth>(context,
|
||||
listen: false)
|
||||
.setUserData(
|
||||
user!['id'],
|
||||
usernameCTRL.text,
|
||||
emailCTRL.text,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
auth.resetLoading();
|
||||
Fluttertoast.showToast(
|
||||
msg: "Info changed successfully.",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user