mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Add instruments selector
This also adds a tile to the temporary home screen for debugging purposes.
This commit is contained in:
parent
ab7dd8dc00
commit
d9149d2ff2
2 changed files with 87 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../backend.dart';
|
import '../backend.dart';
|
||||||
import '../selectors/person.dart';
|
import '../selectors/person.dart';
|
||||||
|
import '../selectors/instruments.dart';
|
||||||
|
|
||||||
class HomeScreen extends StatelessWidget {
|
class HomeScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
|
|
@ -32,6 +33,15 @@ class HomeScreen extends StatelessWidget {
|
||||||
fullscreenDialog: true,
|
fullscreenDialog: true,
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Text('Select instrument'),
|
||||||
|
onTap: () => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InstrumentsSelector(),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
)),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
77
lib/selectors/instruments.dart
Normal file
77
lib/selectors/instruments.dart
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../backend.dart';
|
||||||
|
import '../database.dart';
|
||||||
|
import '../editors/instrument.dart';
|
||||||
|
|
||||||
|
class InstrumentsSelector extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_InstrumentsSelectorState createState() => _InstrumentsSelectorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InstrumentsSelectorState extends State<InstrumentsSelector> {
|
||||||
|
Set<Instrument> selection = {};
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final backend = Backend.of(context);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text('Select instruments'),
|
||||||
|
actions: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
child: Text('DONE'),
|
||||||
|
onPressed: () => Navigator.pop(context, selection.toList()),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: StreamBuilder(
|
||||||
|
stream: backend.db.allInstruments().watch(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: snapshot.data.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final instrument = snapshot.data[index];
|
||||||
|
|
||||||
|
return CheckboxListTile(
|
||||||
|
title: Text(instrument.name),
|
||||||
|
value: selection.contains(instrument),
|
||||||
|
onChanged: (selected) {
|
||||||
|
setState(() {
|
||||||
|
if (selected) {
|
||||||
|
selection.add(instrument);
|
||||||
|
} else {
|
||||||
|
selection.remove(instrument);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
floatingActionButton: FloatingActionButton(
|
||||||
|
child: const Icon(Icons.add),
|
||||||
|
onPressed: () async {
|
||||||
|
final Instrument instrument = await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => InstrumentEditor(),
|
||||||
|
fullscreenDialog: true,
|
||||||
|
));
|
||||||
|
|
||||||
|
if (instrument != null) {
|
||||||
|
setState(() {
|
||||||
|
selection.add(instrument);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue