简体   繁体   English

Flutter_bloc 包中的 FutureBuilder 和 Snapshot

[英]FutureBuilder and Snapshot in Flutter_bloc package

How do i implement futurebuilder and snapshot in blocbuilder by using flutter_bloc package.我如何使用 flutter_bloc 包在 blocbuilder 中实现 futurebuilder 和快照。 I am a bit beginner in bloc, so i need an example for futurebuilder in bloc.我是 bloc 的初学者,所以我需要一个 bloc 中的 futurebuilder 示例。

Please add more details of what you are trying to do.请添加您正在尝试执行的操作的更多详细信息。 FutureBuilder is a widget so you can return it inside of the builder property of BlocBuilder like this: FutureBuilder是一个小部件,因此您可以像这样在BlocBuilderbuilder属性中返回它:

Widget build(BuildContext context) {
    return BlocBuilder(
      builder: (context, state) {
        // here you should check about the state that is being provided
        return FutureBuilder(
          future: _future,
          builder: (context, snapshot) {
            //here you should check snapshot.connectionState
            return SizedBox();
          },
        );
      },
    );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM