Flutter 未来建筑商在颤振中出现故障

Flutter 未来建筑商在颤振中出现故障,flutter,dart,flutter-layout,flutter-dependencies,Flutter,Dart,Flutter Layout,Flutter Dependencies,我是这样写我的未来建设者的 FutureBuilder( future: Future.delayed(Duration(seconds: 3)), builder: (c, s) => s.connectionState != ConnectionState.done ? Center(child: CircularProgressIndicator()) : nextPage() 虽然

我是这样写我的未来建设者的

 FutureBuilder(
        future: Future.delayed(Duration(seconds: 3)),
        builder: (c, s) =>
        s.connectionState != ConnectionState.done
            ? Center(child: CircularProgressIndicator())
            :  nextPage()
虽然工作正常,但它在几秒钟内显示了一个错误,上面说“类型‘Future’不是类型‘Widget’的子类型,而是抛出我的futureBuilder。” 接下来我把它改成了

    FutureBuilder(
  future: Future.delayed(Duration(seconds: 3)).then((response) {
    nextPage();    
  }),  
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      return null;
    } else if (snapshot.hasError)
      return Text(snapshot.error.toString());
    return CircularProgressIndicator();
  },
);
但这里的问题是我的下一页()只会闪烁并消失

有什么帮助吗

编辑: 这是我的完整代码,我的要求是在前3秒钟使用circularprogressindicator,然后是下一页()

void main()异步{
WidgetsFlutterBinding.ensureInitialized();
等待Firebase.initializeApp();
runApp(App());
}
类应用程序扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“标题”,
主页:MyApp(),
);
}
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
nextPage()异步{
bool visitedFlag=等待getVIsitingFlag();
setVIsitingFlag();
如果(visitedFlag==true){
导航器.of(上下文).push(
MaterialPage路由(生成器:(上下文)=>主屏幕());
}
否则{
导航器.of(上下文).push(
MaterialPage路由(生成器:(上下文)=>NewScreen());
}
}
@凌驾
void initState(){
Future.delayed(持续时间(秒:3))。然后((响应){
下一页();
});
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:颜色(0xFF311a2e),
正文:安全区(
儿童:
循环前进指示器();
),
);
}
}
getVIsitingFlag()异步{
SharedReferences首选项=等待SharedReferences.getInstance();
bool alreadyVisited=preferences.getBool('alreadyVisited')??false;
返回已访问;
}
setVIsitingFlag()异步{
SharedReferences首选项=等待SharedReferences.getInstance();
preferences.setBool('alreadyVisited',true);
}

既然你无论如何都不想在将来完成时显示任何小部件,只需删除
FutureBuilder
。只有当你想在未来的基础上建立一些东西时,你才需要它

initState
方法中调用您的方法:

  Future.delayed(Duration(seconds: 3)).then((response) {
    nextPage();    
  }

在没有FutureBuilder的情况下,将您的页面构建成一个进度指示器。

类型“Future”不是类型“Widget”的子类型,我一直在得到它。如果您遵循我的答案,这是不可能的。你真的删除了FutureBuilder吗?是的,让我用完整的代码编辑我的问题。你的孩子不是“下一页”,你的孩子是循环推进指示器。我告诉您应该将代码放入的
initState
方法在哪里?它不接受Future.delayed(持续时间:3秒)…方法处于init状态。
  Future.delayed(Duration(seconds: 3)).then((response) {
    nextPage();    
  }