mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Rename top level directories
This commit is contained in:
parent
256bda1b72
commit
674ce19414
90 changed files with 0 additions and 0 deletions
108
mobile/lib/selectors/instruments.dart
Normal file
108
mobile/lib/selectors/instruments.dart
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
import '../database.dart';
|
||||
import '../editors/instrument.dart';
|
||||
|
||||
class InstrumentsSelector extends StatefulWidget {
|
||||
final bool multiple;
|
||||
final List<Instrument> selection;
|
||||
|
||||
InstrumentsSelector({
|
||||
this.multiple = false,
|
||||
this.selection,
|
||||
});
|
||||
|
||||
@override
|
||||
_InstrumentsSelectorState createState() => _InstrumentsSelectorState();
|
||||
}
|
||||
|
||||
class _InstrumentsSelectorState extends State<InstrumentsSelector> {
|
||||
Set<Instrument> selection = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.selection != null) {
|
||||
selection = widget.selection.toSet();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.multiple ? 'Select instruments/roles' : 'Select instrument/role'),
|
||||
actions: widget.multiple
|
||||
? <Widget>[
|
||||
FlatButton(
|
||||
child: Text('DONE'),
|
||||
onPressed: () => Navigator.pop(context, selection.toList()),
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
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];
|
||||
|
||||
if (widget.multiple) {
|
||||
return CheckboxListTile(
|
||||
title: Text(instrument.name),
|
||||
value: selection.contains(instrument),
|
||||
checkColor: Colors.black,
|
||||
onChanged: (selected) {
|
||||
setState(() {
|
||||
if (selected) {
|
||||
selection.add(instrument);
|
||||
} else {
|
||||
selection.remove(instrument);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return ListTile(
|
||||
title: Text(instrument.name),
|
||||
onTap: () => Navigator.pop(context, 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) {
|
||||
if (widget.multiple) {
|
||||
setState(() {
|
||||
selection.add(instrument);
|
||||
});
|
||||
} else {
|
||||
Navigator.pop(context, instrument);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue