自定义FutureBuilder +将目标数据传递到snapshot.data

时间:2019-05-27 22:06:26

标签: flutter dart

我正在尝试创建一个CustomFutureBuilder。我想将targetItem传递给snapshot.data,当我打电话时,它会从大小写变为另一个。我试图将它们串联起来,但没有用,请在下面查看我的附加代码:

import 'package:flutter/material.dart';

class CustomFutureBuilder extends StatelessWidget {
 final BuildContext context;
 final Future future;
 final Widget returnedWidget;
 final bool enableLoading;
 final Widget loadingWidget;
 final String loadingMessage;
 final String targetItem;

  CustomFutureBuilder(
      {this.context,
      this.future,
      this.returnedWidget,
      this.enableLoading = true,
      this.loadingWidget,
      this.loadingMessage,
      this.targetItem,
      });

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: this.future,
        builder: (context, snapshot) {
          switch (snapshot.connectionState) {
            case ConnectionState.none:
            case ConnectionState.waiting:
              return Center(child: CircularProgressIndicator());
            default:
                return Text(snapshot.data.targetItem); 

          }

        });
  }
}

0 个答案:

没有答案