Skip to content

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

License

Notifications You must be signed in to change notification settings

vishna/voyager_list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages