Giter VIP home page Giter VIP logo

bloc_getit_sample's Introduction

BLOC & get_it Sample

This source is based on this repository and update to understand GetIt.

The original repo author is also introduced own idea in this Qiita article. (Only Japanese)

Why I create this?

I'm learning and developing Flutter app. Recently I was struggling with DI in my flutter app. In internet, there are many info for DI on flutter and the majority seems provider packege and InheritedWidget. However, I was having some strange feeling for them because they seemed tightly integrated Widget tree. And I don't want to think the context of the widget tree when obtaining an instance which is widely needed from any widget or business logic.

One day, I found get_it packege ad another candidate for DI in my flutter app.

Thus, I tried to understand to update from an example app which is using InheritedWidget to new way using get_it package.

App UI

Startup Name Generator Page

This is 1st screen of this app. User can see random words in the list and can mark as "Favorite".

User can see total number of favorites on the navigation bar and it will be updated by adding or removing favorites.

From an icon button on the navigation bar, user can move 2nd page: Your Favorite page.

Your Favorite page

User can review own favorite words in the list. As default, the list include a dummy suggestion item at the first place of the list. Also, dummy ad Views will be shown as items of the list.

User can disable to show the dummy suggestion item and dummy ad views by using a switch on the navigation bar.

Also, user can remove favorites from the delete icon button for each favorite item, if user doesn't like it any more.

What I updated from the original repo.

  1. File structure upadte.
  2. Add some debug log.
  3. Use get_it package
    1. Add initialization step in main.dart.
    2. Remove logic using WordBlocProvider class which was a subclass of InheritedWidget.
    3. Use GetIt.I<WordBloc>() instead of the Provider class.
    4. Refactor some methods to not use WordBloc as an argument because any logic can get WordBloc instance from GetIt.
  4. In Your Favorite Page, added delete icon button for each ListTile and call remove function of WordBloc when tapped.
  5. Add new getter itemsWithInfo in WordBloc to provide Stream for prividing a list including all of favorited words, one suggestion and ads. This stream is created by transforming streams, from the original stream: Stream<List<WordItem>>.

bloc_getit_sample's People

Contributors

gki avatar

Watchers

 avatar  avatar

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.