mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Add instrument editor
This commit is contained in:
parent
b1ed4fe747
commit
63fd75c0a4
1 changed files with 66 additions and 0 deletions
66
lib/editors/instrument.dart
Normal file
66
lib/editors/instrument.dart
Normal file
|
|
@ -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<InstrumentEditor> {
|
||||||
|
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: <Widget>[
|
||||||
|
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: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: TextField(
|
||||||
|
controller: nameController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Name',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue