alibaba / fish-redux

An assembled flutter application framework.
https://github.com/alibaba/fish-redux
Apache License 2.0
7.33k stars 843 forks source link

FutureBuilder rendering after an async request #697

Open henry-hz opened 4 years ago

henry-hz commented 4 years ago

Is your feature request related to a problem? Please describe. I'm always frustrated when rendering the view widget after an async call see this example code,

  ctx.dispatch(CheckOutPageActionCreator.loading(true));

I am also using this strategy for this moment, of having a reducer to manage the loading state....

Describe the solution you'd like I would like a mechanism to trigger render that listen a state variable if its not null and render the view, without creating the reducer/action/state for an 'onloading' . In the example below, we should think about the 'future' function that will trigger the snapshot state... I have no clue on how to use it with fish-redux.... in fact, maybe it's only a question of adding how to do it into the docs... or implementing it :)

  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: Theme.of(context).textTheme.headline2,
      textAlign: TextAlign.center,
      child: FutureBuilder<String>(
        future: _calculation, // a previously-obtained Future<String> or null
        builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
          List<Widget> children;
          if (snapshot.hasData) {
            children = <Widget>[
              Icon(
                Icons.check_circle_outline,
                color: Colors.green,
                size: 60,
              ),

Describe alternatives you've considered Considered using the FutureBuilder, but it didn't work when 'listening the state'

Thanks for the amazing lib !

dddrop commented 4 years ago

there is a ShouldUpdate<T> shouldUpdate, parameter of page/component which let you to define your view rebuild timing.

henry-hz commented 4 years ago

@DDDrop thanks for dedicating your time to reply me ! Do you think the same strategy would fit for a stream subscription (like the one with make with graphql) ? See that it's possible to use a Flutter lib or a pure Dart option in this examples.

dddrop commented 4 years ago

@henry-hz I think they are different things. shouldUpdate is for how to update(rebuild) view, and stream subscription is like when to update state.