Skip to content

Latest commit

 

History

History
86 lines (68 loc) · 2.07 KB

README.md

File metadata and controls

86 lines (68 loc) · 2.07 KB

pub package Codemagic build status codecov

voyager_list

Allows mapping a list of arbitrary objects to a list view.

voyager-keynote 001

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"