voyager_list 0.0.2 voyager_list: ^0.0.2 copied to clipboard
Voyager add-on package. Facilitates dynamic mapping of a list of arbitrary objects to a ListWiew.
voyager_list #
Allows mapping a list of arbitrary objects to a list view.
Usage #
Say you have 3 different classes...
class Shoe {
final id;
final name;
Shoe(this.id, this.name);
}
class Bulb {
final id;
final name;
Bulb(this.id, this.name);
}
class Duck {
final id;
final name;
Duck(this.id, this.name);
}
...a mixed list of items of these types:
final items = [
Shoe("mk", "Mike"),
Bulb("bl", "Phillip"),
Duck("rb", "Rubber")
]
and respective widgets:
class ShoeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Shoe shoe = Provider.of<VoyagerArgument>(context).value;
return Text("Shoe: ${shoe.name}");
}
}
class DuckWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Duck duck = Provider.of<VoyagerArgument>(context).value;
return Text("Duck: ${duck.name}");
}
}
class BulbWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Bulb bulb = Provider.of<VoyagerArgument>(context).value;
return Text("Bulb: ${bulb.name}");
}
}
You can simply map your object list to a list view:
String idMapper(dynamic item) => item.id;
String objectMapper(dynamic item) =>
"/object/${item.runtimeType}";
VoyagerListView(items, idMapper, objectMapper);
provided your navigation map specifies following mapping:
'/object/:className':
type: object_item
widget: "%{className}Widget"