Giter Site home page Giter Site logo

mi-sch-ka / array-object-adapter Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 144 KB

Adapter that is similar to the ObjectAdapter (ArrayObjectAdapter) from the Android Leanback support library.

License: Apache License 2.0

Kotlin 0.86% Swift 2.81% Objective-C 0.26% Dart 96.06%
dart flutter flutter-package pattern hacktoberfest

array-object-adapter's Introduction

Pub

Adapter that is similar to the ObjectAdapter (ArrayObjectAdapter) from the Android Leanback support library.

Example Project

There is a pretty sweet example project in the example folder. Check it out. Otherwise, keep reading to get up and running.

Adapter

An array-based data source that provides access to a data model and is decoupled from the presentation of the items via Presenter/PresenterSelector. As the adapter implements the dart stream interface, you can simply observe the data set.

adapter.listen((_) { 
    // data set changed
});
@override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: _adapter,
      builder: (context, snapshot) {},);
  } 

Presenter

Split presenter logic from adapter logic. Presenter that will create Views/Widgets and bind object.

/// A simple example where a string is represented as a text widget.
/// But imagine for example a user object, which is represented with a thumbnail, name and address etc.
class TextPresenter extends Presenter {
  
  @override
  Widget createView(BuildContext context, Object item) {
    final value = item as String;
    return Text(value);
  }
}

To use multiple viewTypes use PresenterSelector.

final classPresenterSelector = ClassPresenterSelector()
      ..addClassPresenter(int, IntPresenter())
      ..addClassPresenter(String, TextPresenter());

final adapter = ArrayObjectAdapter(presenterSelector: classPresenterSelector);

final items = <dynamic>[];
// create your content
...

adapter.setItems(items);

Attach an adapter for the data to displayed to your view

@override
  Widget build(BuildContext context) {
    return ListView.separated(
      itemCount: adapter.itemCount(),
      itemBuilder: (BuildContext context, int index) {
        final item = adapter.get(index);
        final presenter = adapter.getPresenter(item);
        return presenter.createView(context, item);
      },
      separatorBuilder: (BuildContext context, int index) => Divider(),
    );
  }

array-object-adapter's People

Contributors

mi-sch-ka avatar galmkr avatar brainshaker95 avatar

Stargazers

 avatar Arnie Le Mesch avatar Anthony Bryan Gavilan Vinces avatar Steffen Müller avatar  avatar

Watchers

 avatar

Forkers

brainshaker95

array-object-adapter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.