mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
mobile: Use new API on selection screens
This commit is contained in:
parent
7bf99ebd07
commit
52a2d5c3ec
3 changed files with 88 additions and 85 deletions
|
|
@ -3,23 +3,42 @@ import 'package:musicus_database/musicus_database.dart';
|
|||
|
||||
import '../backend.dart';
|
||||
import '../editors/person.dart';
|
||||
import '../widgets/lists.dart';
|
||||
|
||||
import 'work.dart';
|
||||
|
||||
class PersonScreen extends StatelessWidget {
|
||||
class PersonScreen extends StatefulWidget {
|
||||
final Person person;
|
||||
|
||||
PersonScreen({
|
||||
this.person,
|
||||
});
|
||||
|
||||
@override
|
||||
_PersonScreenState createState() => _PersonScreenState();
|
||||
}
|
||||
|
||||
class _PersonScreenState extends State<PersonScreen> {
|
||||
String _search;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backend = Backend.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('${person.firstName} ${person.lastName}'),
|
||||
title: TextField(
|
||||
autofocus: true,
|
||||
onChanged: (text) {
|
||||
setState(() {
|
||||
_search = text;
|
||||
});
|
||||
},
|
||||
decoration: InputDecoration.collapsed(
|
||||
hintText:
|
||||
'Works by ${widget.person.firstName} ${widget.person.lastName}',
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
|
|
@ -28,7 +47,7 @@ class PersonScreen extends StatelessWidget {
|
|||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PersonEditor(
|
||||
person: person,
|
||||
person: widget.person,
|
||||
),
|
||||
fullscreenDialog: true,
|
||||
),
|
||||
|
|
@ -37,36 +56,22 @@ class PersonScreen extends StatelessWidget {
|
|||
),
|
||||
],
|
||||
),
|
||||
body: FutureBuilder<List<WorkInfo>>(
|
||||
future: backend.db.getWorks(person.id),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.data.length,
|
||||
itemBuilder: (context, index) {
|
||||
final work = snapshot.data[index].work;
|
||||
|
||||
return ListTile(
|
||||
title: Text(work.title),
|
||||
onTap: () async {
|
||||
final workInfo = await backend.db.getWorkInfo(work);
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => WorkScreen(
|
||||
workInfo: workInfo,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
body: PagedListView<WorkInfo>(
|
||||
search: _search,
|
||||
fetch: (page, search) async {
|
||||
return await backend.db.getWorks(widget.person.id, page, search);
|
||||
},
|
||||
builder: (context, workInfo) => ListTile(
|
||||
title: Text(workInfo.work.title),
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => WorkScreen(
|
||||
workInfo: workInfo,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue