alibaba/fish-redux

FutureBuilder rendering after an async request

Opened this issue · 3 comments

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 !

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

@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.

@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.