Hello.
import 'package:example/models.dart';
import 'package:flutter/material.dart';
import 'package:queries/collections.dart';
import 'package:smart_select/smart_select.dart';
class AddBook extends StatefulWidget {
final Book book;
const AddBook({Key key, this.book}) : super(key: key);
@override
_AddBookState createState() => _AddBookState();
}
class _AddBookState extends State<AddBook> {
Color get primaryColor => Theme.of(context).primaryColor;
final List<SelectListItem<ELiteraryGenre>> literaryGenres = [
new SelectListItem<ELiteraryGenre>(ELiteraryGenre.poetry, 'Poetry'),
new SelectListItem<ELiteraryGenre>(ELiteraryGenre.drama, 'Drama'),
new SelectListItem<ELiteraryGenre>(ELiteraryGenre.prose, 'Prose'),
new SelectListItem<ELiteraryGenre>(ELiteraryGenre.fiction, 'Fiction'),
new SelectListItem<ELiteraryGenre>(
ELiteraryGenre.non_fiction, 'Non-fiction'),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Add book"),
),
body: Padding(
padding: EdgeInsets.all(5.0),
child: Column(
children: [
getLiteraryGenres(),
],
),
),
);
}
Widget getLiteraryGenres() => new SmartSelect<ELiteraryGenre>.multiple(
title: 'Literary genres',
value: widget.book.literaryGenres.value,
choiceItems: S2Choice.listFrom<ELiteraryGenre, Map>(
source: Collection(this.literaryGenres)
.select((arg1) => {'key': arg1.value, 'value': arg1.text})
.toList(),
value: (index, item) => item['key'],
title: (index, item) => item['value'],
),
onChange: (state) =>
setState(() => widget.book.literaryGenres.value = state.value),
modalType: S2ModalType.bottomSheet,
modalConfirm: true,
modalFilter: true,
choiceGrouped: true,
tileBuilder: (context, state) {
return Card(
elevation: 3,
margin: const EdgeInsets.all(5),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
),
child: S2Tile.fromState(
state,
hideValue: true,
title: const Text('Literary genres'),
trailing: const Icon(Icons.add_circle_outline),
body: S2TileChips(
chipLength: state.valueObject.length,
chipLabelBuilder: (context, i) {
return Text(state.valueObject[i].title);
},
chipOnDelete: (i) {
setState(() => widget.book.literaryGenres.value
.remove(state.valueObject[i].value));
},
chipColor: primaryColor,
),
),
);
},
);
}