作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
你好,当我导航到应用程序中的另一个页面时出现此错误
我不知道为什么这个错误出现
#0 _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1 Route.didComplete
package:flutter/…/widgets/navigator.dart:203
#2 NavigatorState.pushReplacement.<anonymous closure>
package:flutter/…/widgets/navigator.dart:1861
#3 TickerFuture.whenCompleteOrCancel.thunk
package:flutter/…/scheduler/ticker.dart:389
#4 _rootRunUnary (dart:async/zone.dart:1132:38)
#5 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#6 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
#7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
#8 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#9 Future._completeWithValue (dart:async/future_impl.dart:522:5)
#10 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:552:7)
#11 _rootRun (dart:async/zone.dart:1124:13)
#12 <…>
Navigator.pop(context);
Navigator.pushReplacementNamed(context, '/NavigationBar');
routes: {
"/": (BuildContext context) => LoginPage(),
"/NavigationBar": (BuildContext context) => NavigationBarPage(),
},
最佳答案
我已经用官方示例重现了此错误
删除Navigator.pop(context);
效果很好
在演示中,第一屏单击按钮转到第二屏。
您不需要Navigator.pop(context);
只是Navigator.pushReplacementNamed(context, '/second');
就可以了
程式码片段
onPressed: () {
//Navigator.pop(context); remove this line
// Navigate to the second screen using a named route.
Navigator.pushReplacementNamed(context, '/second');
},
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Named Routes Demo',
// Start the app with the "/" named route. In this case, the app starts
// on the FirstScreen widget.
initialRoute: '/',
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/': (context) => FirstScreen(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/second': (context) => SecondScreen(),
},
));
}
class FirstScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen'),
),
body: Center(
child: RaisedButton(
child: Text('Launch screen'),
onPressed: () {
//Navigator.pop(context); remove this line
// Navigate to the second screen using a named route.
Navigator.pushReplacementNamed(context, '/second');
},
),
),
);
}
}
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Screen"),
),
body: Center(
child: RaisedButton(
onPressed: () {
// Navigate back to the first screen by popping the current route
// off the stack.
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}
关于flutter - 未处理的异常:不良状态: future 已经 flutter 朔迷离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59128675/
我是一名优秀的程序员,十分优秀!