2020-03-22 14:52:56 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-04-24 22:41:52 +02:00
|
|
|
import 'package:musicus_database/musicus_database.dart';
|
2020-03-22 14:52:56 +01:00
|
|
|
|
|
|
|
|
import '../backend.dart';
|
|
|
|
|
|
|
|
|
|
class EnsembleEditor extends StatefulWidget {
|
|
|
|
|
final Ensemble ensemble;
|
|
|
|
|
|
|
|
|
|
EnsembleEditor({
|
|
|
|
|
this.ensemble,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_EnsembleEditorState createState() => _EnsembleEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _EnsembleEditorState extends State<EnsembleEditor> {
|
|
|
|
|
final nameController = TextEditingController();
|
|
|
|
|
|
2020-04-26 18:29:21 +02:00
|
|
|
bool uploading = false;
|
|
|
|
|
|
2020-03-22 14:52:56 +01:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
if (widget.ensemble != null) {
|
|
|
|
|
nameController.text = widget.ensemble.name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final backend = Backend.of(context);
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
title: Text('Ensemble'),
|
|
|
|
|
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 ensemble = Ensemble(
|
|
|
|
|
id: widget.ensemble?.id ?? generateId(),
|
|
|
|
|
name: nameController.text,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final success = await backend.client.putEnsemble(ensemble);
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
uploading = false;
|
|
|
|
|
});
|
2020-03-22 14:52:56 +01:00
|
|
|
|
2020-04-26 18:29:21 +02:00
|
|
|
if (success) {
|
|
|
|
|
Navigator.pop(context, ensemble);
|
|
|
|
|
} else {
|
|
|
|
|
Scaffold.of(context).showSnackBar(SnackBar(
|
|
|
|
|
content: Text('Failed to upload'),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
2020-03-22 14:52:56 +01:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: ListView(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: nameController,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
labelText: 'Name',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|