add structure
This commit is contained in:
155
lib/pages/storage/storage_addition.dart
Normal file
155
lib/pages/storage/storage_addition.dart
Normal file
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/storage_model.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/storage.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
class StorageAddition extends StatefulWidget {
|
||||
final Storage storage;
|
||||
|
||||
const StorageAddition({Key key, this.storage}) : super(key: key);
|
||||
@override
|
||||
_StorageAdditionState createState() => _StorageAdditionState();
|
||||
}
|
||||
|
||||
class _StorageAdditionState extends State<StorageAddition> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
TextEditingController nameController = new TextEditingController();
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.storage != null) {
|
||||
nameController.text = widget.storage.name;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(context, "storage.item.title",color: Colors.white,fontSize: 20,),
|
||||
actions: <Widget>[
|
||||
widget.storage == null
|
||||
? Container()
|
||||
: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "storage.delete_confirm", () {
|
||||
_delete(context);
|
||||
});
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.save),
|
||||
onPressed: () {
|
||||
_save(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: TextFormField(
|
||||
controller: nameController,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
decoration: new InputDecoration(
|
||||
labelText: AppTranslations.of(context)
|
||||
.text("storage.name"),
|
||||
labelStyle:
|
||||
languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Image.asset(
|
||||
"assets/inventory.png",
|
||||
color: primaryColor,
|
||||
width: 25,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return AppTranslations.of(context)
|
||||
.text("storage.form.name");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
void _save(BuildContext context) async {
|
||||
if (!_formKey.currentState.validate()) return;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
if (widget.storage != null) {
|
||||
widget.storage.name = nameController.text;
|
||||
await Provider.of<StorageModel>(context, listen: false)
|
||||
.updateStorage(widget.storage);
|
||||
} else {
|
||||
await Provider.of<StorageModel>(context, listen: false)
|
||||
.createStorage(Storage(name: nameController.text));
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _delete(BuildContext context) async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
if (widget.storage != null) {
|
||||
await Provider.of<StorageModel>(context, listen: false)
|
||||
.deleteStorage(widget.storage.id);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user