This repository has been archived by the owner on Jan 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#53. Completing example with receipt CRUD
- Loading branch information
Showing
10 changed files
with
268 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Dart", | ||
"program": "example/lib/main.dart", | ||
"request": "launch", | ||
"type": "dart" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,191 @@ | ||
|
||
import 'package:example/main.adapter.g.m8.dart'; | ||
import 'package:example/models/receipt.dart'; | ||
import 'package:example/models/receipt.g.m8.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ReceiptEditPage extends StatefulWidget { | ||
final Receipt currentReceipt; | ||
|
||
ReceiptEditPage({this.currentReceipt}); | ||
|
||
_ReceiptEditPageState createState() => _ReceiptEditPageState(currentReceipt); | ||
} | ||
|
||
class _ReceiptEditPageState extends State<ReceiptEditPage> { | ||
final _formKey = GlobalKey<FormState>(); | ||
|
||
Receipt _stateReceipt; | ||
String title; | ||
|
||
DatabaseHelper _db = DatabaseHelper(); | ||
|
||
_ReceiptEditPageState(this._stateReceipt); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_stateReceipt = _stateReceipt ?? | ||
ReceiptProxy( | ||
isBio: true, | ||
expirationDate: null, | ||
quantity: null, | ||
numberOfItems: null, | ||
storageTemperature: null, | ||
description: null); | ||
} | ||
|
||
Future<void> submit() async { | ||
if (this._formKey.currentState.validate()) { | ||
_formKey.currentState.save(); | ||
|
||
_db = DatabaseHelper(); | ||
|
||
int id = await _db.updateReceipt(_stateReceipt); | ||
_stateReceipt.id = id; | ||
|
||
Navigator.of(context).pop(_stateReceipt); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(this.title ?? "Edit Receipt"), | ||
actions: <Widget>[ | ||
IconButton( | ||
icon: Icon(Icons.check), | ||
onPressed: submit, | ||
), | ||
], | ||
), | ||
body: Stack( | ||
children: <Widget>[ | ||
Container( | ||
padding: EdgeInsets.all(20.0), | ||
child: Form( | ||
autovalidate: false, | ||
key: _formKey, | ||
child: ListView( | ||
shrinkWrap: true, | ||
children: <Widget>[ | ||
TextFormField( | ||
initialValue: _stateReceipt.description, | ||
decoration: InputDecoration( | ||
hintText: "Description", | ||
labelText: "Description*", | ||
), | ||
validator: (value) { | ||
if (value.isEmpty) { | ||
return "Please enter description"; | ||
} | ||
}, | ||
onSaved: (String value) { | ||
_stateReceipt.description = value; | ||
}, | ||
), | ||
// TextFormField( | ||
// decoration: new InputDecoration( | ||
// hintText: "decomposing Duration as Duration", | ||
// labelText: "decomposing Duration*", | ||
// ), | ||
// validator: (value) { | ||
// if (value.isEmpty) { | ||
// return "Please enter decomposingDuration"; | ||
// } | ||
// }, | ||
// onSaved: (String value) { | ||
// _stateReceipt.decomposingDuration = | ||
// Duration(hours: int.parse(value)); | ||
// }, | ||
// ), | ||
TextFormField( | ||
initialValue: _stateReceipt.expirationDate.toIso8601String(), | ||
decoration: InputDecoration( | ||
hintText: "expiration Date (format: 2071-05-30 17:50:03)", | ||
labelText: "expiration Date*", | ||
), | ||
validator: (value) { | ||
if (value.isEmpty) { | ||
return "Please enter expirationDate"; | ||
} | ||
}, | ||
onSaved: (String value) { | ||
_stateReceipt.expirationDate = DateTime.parse(value); | ||
}, | ||
), | ||
SwitchListTile( | ||
title: const Text('Is Bio'), | ||
value: _stateReceipt.isBio, | ||
onChanged: (bool val) => | ||
setState(() => _stateReceipt.isBio = val)), | ||
TextFormField( | ||
initialValue: _stateReceipt.numberOfItems.toString(), | ||
decoration: InputDecoration( | ||
hintText: "number of Items as int", | ||
labelText: "number of Items*", | ||
), | ||
validator: (value) { | ||
if (value.isEmpty) { | ||
return "Please enter numberOfItems"; | ||
} | ||
}, | ||
onSaved: (String value) { | ||
_stateReceipt.numberOfItems = int.parse(value); | ||
}, | ||
), | ||
// TextFormField( | ||
// decoration: new InputDecoration( | ||
// hintText: "numberOfMolecules as bigInt", | ||
// labelText: "numberOfMolecules*", | ||
// ), | ||
// validator: (value) { | ||
// if (value.isEmpty) { | ||
// return "Please enter numberOfMolecules"; | ||
// } | ||
// }, | ||
// onSaved: (String value) { | ||
// _stateReceipt.numberOfMolecules = BigInt.parse(value); | ||
// }, | ||
// ), | ||
TextFormField( | ||
initialValue: _stateReceipt.quantity.toString(), | ||
decoration: InputDecoration( | ||
hintText: "quantity as double", | ||
labelText: "quantity*", | ||
), | ||
validator: (value) { | ||
if (value.isEmpty) { | ||
return "Please enter quantity"; | ||
} | ||
}, | ||
onSaved: (String value) { | ||
_stateReceipt.quantity = double.parse(value); | ||
}, | ||
), | ||
TextFormField( | ||
initialValue: _stateReceipt.storageTemperature.toString(), | ||
decoration: InputDecoration( | ||
hintText: "storage Temperature as num", | ||
labelText: "storage Temperature*", | ||
), | ||
validator: (value) { | ||
if (value.isEmpty) { | ||
return "Please enter storage Temperature"; | ||
} | ||
}, | ||
onSaved: (String value) { | ||
_stateReceipt.storageTemperature = num.parse(value); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.