2019-12-03 12:47:23 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-06-02 16:47:46 +02:00
|
|
|
import 'package:musicus_client/musicus_client.dart';
|
2019-12-03 12:47:23 +01:00
|
|
|
|
|
|
|
|
import '../backend.dart';
|
|
|
|
|
|
|
|
|
|
class InstrumentEditor extends StatefulWidget {
|
|
|
|
|
final Instrument instrument;
|
|
|
|
|
|
|
|
|
|
InstrumentEditor({
|
|
|
|
|
this.instrument,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_InstrumentEditorState createState() => _InstrumentEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _InstrumentEditorState extends State<InstrumentEditor> {
|
|
|
|
|
final nameController = TextEditingController();
|
|
|
|
|
|
2020-04-26 18:29:21 +02:00
|
|
|
bool uploading = false;
|
2020-07-17 20:13:55 +02:00
|
|
|
bool _sync = true;
|
2020-04-26 18:29:21 +02:00
|
|
|
|
2019-12-03 12:47:23 +01:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
if (widget.instrument != null) {
|
|
|
|
|
nameController.text = widget.instrument.name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-05-04 21:49:44 +02:00
|
|
|
final backend = MusicusBackend.of(context);
|
2019-12-03 12:47:23 +01:00
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2020-03-31 15:49:15 +02:00
|
|
|
title: Text('Instrument/Role'),
|
2019-12-03 12:47:23 +01:00
|
|
|
actions: <Widget>[
|
2020-04-26 18:29:21 +02:00
|
|
|
uploading
|
|
|
|
|
? Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
width: 24.0,
|
|
|
|
|
height: 24.0,
|
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
|
strokeWidth: 2.0,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
: FlatButton(
|
|
|
|
|
child: Text('DONE'),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
setState(() {
|
|
|
|
|
uploading = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final instrument = Instrument(
|
|
|
|
|
id: widget.instrument?.id ?? generateId(),
|
|
|
|
|
name: nameController.text,
|
2020-07-17 20:13:55 +02:00
|
|
|
sync: _sync,
|
|
|
|
|
synced: false,
|
2020-04-26 18:29:21 +02:00
|
|
|
);
|
|
|
|
|
|
2020-07-17 20:24:37 +02:00
|
|
|
await backend.db.updateInstrument(instrument);
|
2020-04-26 18:29:21 +02:00
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
uploading = false;
|
|
|
|
|
});
|
2019-12-03 12:47:23 +01:00
|
|
|
|
2020-07-17 20:24:37 +02:00
|
|
|
Navigator.pop(context, instrument);
|
2020-04-26 18:29:21 +02:00
|
|
|
},
|
|
|
|
|
),
|
2019-12-03 12:47:23 +01:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: ListView(
|
|
|
|
|
children: <Widget>[
|
2020-07-17 20:13:55 +02:00
|
|
|
SwitchListTile(
|
|
|
|
|
title: Text('Synchronize changes'),
|
|
|
|
|
subtitle: Text(_sync
|
|
|
|
|
? 'Publish changes on the server'
|
|
|
|
|
: 'Keep changes private'),
|
|
|
|
|
value: _sync,
|
|
|
|
|
onChanged: (value) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_sync = value;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
2019-12-03 12:47:23 +01:00
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: nameController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: 'Name',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|