如何使用 Shimmer 在 Flutter App 中添加 X 持续时间的延迟?

How to add delay of X duration in Flutter App using Shimmer?

我正在开发 Flutter 应用程序,我想在其中显示加载选项 5 秒,5 秒后它将显示“未找到结果”。

代码

Widget Loading(){
 return Center(
  child: Shimmer.fromColors(
  baseColor: Colors.blueAccent,
  highlightColor: Colors.red,
  child:Text("Loading...",style: TextStyle(
      fontWeight: FontWeight.w900,
      fontSize: 50),
    textAlign: TextAlign.center,),
  period: Duration(seconds: 2),

  ),

 );
}

/// Use of Loading() in flutter pages

 body: (Details == null||Details.isEmpty)?
      Loading()
      : new SizedBox(.............)

// In this case, if "Details" has some data it automatically displays on-screen else, continuously loading(), I want after 5 seconds it displays "No Data Found"

有人知道如何在上面的代码中添加 Timer/Duration/Delay 吗?这样 5 秒后屏幕上会显示消息“找不到数据”。

您可以为此使用 FutureBuilder。这是一个例子:

这是 FutureBuilder 的未来功能。在此功能中,您可以构建自己的逻辑。

Future<bool> _future = Future<bool>.delayed(
    Duration(seconds: 5),
    () {
      //do something here
      return true;
    },
  );

FutureBuilder 应该是这样的

FutureBuilder<bool>(
      future: _future,
      builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
        if (snapshot.hasData) {
          return snapshot.data ? SizedBox(.............) : Text("No data found");
        } else {
          return Loading();
        }
      },
    )