【问题标题】:Flutter Have a loading icon on the fetched data instead of a whole Circular Progress Indicator screenFlutter 在获取的数据上有一个加载图标,而不是整个循环进度指示器屏幕
【发布时间】:2022-01-20 20:32:02
【问题描述】:

我有一个屏幕女巫是一个登录屏幕,在登录屏幕之后,将在另一个屏幕上获取数据。在未来的构建器中,我在获取数据时最后返回一个循环进度指示器,这个循环进度指示器占据整个屏幕,进度指示器旋转,我不希望这样,我需要用户看到屏幕,并且我希望在获取数据时有一个加载图标或加载文本,因此在获取数据之前将显示此加载图标或加载文本。所以我不想要一个加载屏幕的整个屏幕,而是我想向用户显示我想要从另一个屏幕得到的东西,并且只有一个加载图标或文本来显示数据将被获取的位置,并且只有这个加载图标直到获取数据而不是整个屏幕。

child: SafeArea(
        child: Scaffold(
            body: FutureBuilder<List<Response>>(
              future: Future.wait([futureData, futureDataForAccount]),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  List<WorkingLocationData> data1 =
                      parsedData(snapshot.data![0].body);
                  data = data1;

                  AccountData data3 =
                      AccountData.fromJson(json.decode(snapshot.data![1].body));

                  return Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Container(
                          width: width,
                          height: 50,
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Colors.black,
                              width: 4,
                            ),
                          ),
                          child: Center(
                              child: Text(
                        'Welcome ' + data3.firstName + ' ${data3.lastName}', // data being fetched
                            style: TextStyle(fontSize: 18),
                          ))),
                      const Text(
                        'Choose working location',
                        style: TextStyle(fontSize: 23),
                          value: chooseLocation,
                          hint: const Text('Select a location'),
                          isExpanded: true,
                          items: data.map((some) {
                          items: data!.map((some) {
                            return DropdownMenuItem(
                             child: Text(some.name + ' (${some.location})'), // data being fetched
                              value: some.name,
                          ),
                          onPressed: () {},
                          child: const Text(
                            'Submit',
                            'Start Work',
                            style: TextStyle(fontSize: 20),
                          ),
                        ),
                      )
                      ),
                      SizedBox(height: height* 0.001,)
                    ],
                   );
                } else if (snapshot.hasError) {
                  return Text('${snapshot.error}');
                }
              return const Center(child: CircularProgressIndicator()); // i dont want to have this
              },
            ),
            bottomNavigationBar: bottomNavigationBar1(context)),
      ),
    );
  }



【问题讨论】:

    标签: flutter dart flutter-layout flutter-dependencies


    【解决方案1】:

    snapshot.hasData ? fetchedData : CircularIndicator

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      相关资源
      最近更新 更多