From 63fd75c0a4961d2cc2f86b812504a4d9a2fa570a Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Tue, 3 Dec 2019 12:47:23 +0100 Subject: [PATCH] Add instrument editor --- lib/editors/instrument.dart | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lib/editors/instrument.dart diff --git a/lib/editors/instrument.dart b/lib/editors/instrument.dart new file mode 100644 index 0000000..8777415 --- /dev/null +++ b/lib/editors/instrument.dart @@ -0,0 +1,66 @@ +import 'package:flutter/material.dart'; + +import '../backend.dart'; +import '../database.dart'; + +class InstrumentEditor extends StatefulWidget { + final Instrument instrument; + + InstrumentEditor({ + this.instrument, + }); + + @override + _InstrumentEditorState createState() => _InstrumentEditorState(); +} + +class _InstrumentEditorState extends State { + final nameController = TextEditingController(); + + @override + void initState() { + super.initState(); + + if (widget.instrument != null) { + nameController.text = widget.instrument.name; + } + } + + @override + Widget build(BuildContext context) { + final backend = Backend.of(context); + + return Scaffold( + appBar: AppBar( + title: Text('Instrument'), + actions: [ + FlatButton( + child: Text('DONE'), + onPressed: () async { + final instrument = Instrument( + id: widget.instrument?.id ?? generateId(), + name: nameController.text, + ); + + await backend.db.updateInstrument(instrument); + Navigator.pop(context, instrument); + }, + ) + ], + ), + body: ListView( + children: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: TextField( + controller: nameController, + decoration: InputDecoration( + labelText: 'Name', + ), + ), + ), + ], + ), + ); + } +}