如何解决如何使用Shimmer在Flutter App中增加X持续时间的延迟?
我正在Flutter应用程序上工作,我想在其中显示加载选项5秒钟,并在5秒钟后显示“未找到结果”。
CODE
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"
有人知道如何在上面的代码中添加计时器/持续时间/延迟吗,所以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();
}
},)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。