Giter Site home page Giter Site logo

filiph / state_experiments Goto Github PK

View Code? Open in Web Editor NEW
908.0 29.0 134.0 285 KB

Companion repository to the "Build reactive mobile apps in Flutter" talk

Home Page: https://www.youtube.com/watch?v=RS36gBEp8OI

Kotlin 1.31% Swift 1.50% Objective-C 0.14% Dart 96.90% Shell 0.16%

state_experiments's Introduction

Build Status

Welcome to the companion repository to the Google I/O 2018 talk by @mjohnsullivan and @filiph called Build reactive mobile apps with Flutter.

The meat of this repo is in the shared/ directory. That contains our shopping app example built in many different architectural patterns. The app decides in runtime (in lib/main.dart) which pattern it's going to use. The architectures themselves are in subdirectories of lib/src/.

The two hello_world*/ directories are the incrementer app before the live coding session and after it.

This is not an official Google product.

state_experiments's People

Contributors

filiph avatar mjohnsullivan avatar renannprado avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

state_experiments's Issues

Scrolling up when CatalogPages are already deleted

I've used this very beautiful piece of code and adopted it into my project. I used it for an infinite news feed. The problem I am facing now is, when you scroll down a few hundred posts the first will get deleted. When you then scroll up again, it has to reload the posts and the ListView will jump to the very first post in the loaded page, so it skips 10 posts. How would I go to implement the ListView staying at the current scrolling position and just add the loaded page above?

PS: Thanks for the awesome talk at Google I/O!

License

What software license is this code under?

Question regarding Singleton

Hello,

i saw your video about state management and came here afterwards. (Great video, learned a lot and got a lot more questions)

Are there any drawbacks on using the inherited widgets as Providers for the BLoC's instead of a singleton? I just learned dart has any easy way to create singletons with factory constructors, so this seems like another (maybe good) way to go?

I have seen that you have one part of this repo which is called singleton, so i assume you did experiment with them. But why exactly do you seem to prefer the InheritedWidget way instead of the singleton?

I cannot find any questions anywhere concerning singletons vs InheritedWidget.

Thanks in advance for any answer :-)

JC

[question] Testing blocs

I really love this example for blocs. Just wondering if you know any good resources or have any examples for unit testing the blocs, and the widgets that use StreamBuilder?

What's another way mechanism to pass blocs down the tree?

In your bloc_complex example, you force the bloc provider to form a tree, even though they may not be...

Widget build(BuildContext context) {
    // Here we're providing the catalog component ...
    return CatalogProvider(
      catalog: catalog,
      // ... and the cart component via InheritedWidget like so.
      // But BLoC works with any other mechanism, including passing
      // down the widget tree.
      child: CartProvider(
      //...

I understand it's implemented this way because we have to make provider as an ancestor of the children widget. What's an alternative implementation?

Question regarding bloc_complex and the ProductSquareBloc

The ProductSquareBloc has its own StreamController for the cartItems. In its constructor it sets up a listener to that stream, to be able to update the isInCard stream:

ProductSquareBloc(Product product) {
  _cartItemsController.stream
    .map((list) => list.any((item) => item.product == product))
    .listen((isInCart) => _isInCartSubject.add(isInCart));
}

then the ProductSquare feeds that _cartItemsController in the _createBloc method:

 _bloc = ProductSquareBloc(widget.product);
_subscription = widget.itemsStream.listen(_bloc.cartItems.add);

My question is this:

Why doesn't the ProductSquareBloc simply get the widget.itemsStream directly?

It could be like this:

/// Creating the bloc
_bloc = ProductSquareBloc(widget.product, onItems: widget.itemsStream);

and inside the bloc's constructor:

ProductSquareBloc(Product product, {Stream onItems}) {
  onItems
    .map((list) => list.any((item) => item.product == product))
    .listen((isInCart) => _isInCartSubject.add(isInCart));
}

What is the advantage of managing it's own controller and stream like this?

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.