关于页面跳转关闭前一页面的问题Cannot dispose a MaterialPageRoute<dynamic> twice.
来源:6-7 如何创建和使用Flutter的路由与导航?【边学边做】
慕的地1341173
2019-10-28
登录页面输入账号密码,点击登录后跳转到了一个loading的Dialog,登录成功后,关闭loading的Dialog,同时调用
Navigator.pushAndRemoveUntil(
context,
new MaterialPageRoute(builder: (context) => Home()),
(route) => route == null,
);
跳转至首页,首页有一个退出登录的地方,点出退出登录,再利用
Navigator.pushAndRemoveUntil(
context,
new MaterialPageRoute(builder: (context) => LoginPage()),
(route) => route == null,
);
此时再次登录的时候,又弹出loading的Dialog,成功后跳转首页的时候,就报了
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: ‘package:flutter/src/widgets/routes.dart’: Failed assertion: line 308 pos 12: ‘!_transitionCompleter.isCompleted’: Cannot dispose a MaterialPageRoute twice.
#0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:40:39)
#1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2 TransitionRoute.dispose (package:flutter/src/widgets/routes.dart:308:12)
#3 NavigatorState.pushAndRemoveUntil. (package:flutter/src/widgets/navigator.dart:1900:17)
#4 TickerFuture.whenCompleteOrCancel.thunk (package:flutter/src/scheduler/ticker.dart:389:15)
#5 _rootRunUnary (dart:async/zone.dart:1132:38)
#6 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#7 _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
#8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
#9 Future._propagateToListeners (dart:async/future_impl.dart:<…>
的异常。
我观察了一下,去掉loading的dialog,是可以正常跳转的,请问下老师这是什么原因,应该怎么解决?谢谢老师
下面是loading_dialog的代码
import ‘package:flutter/material.dart’;
// ignore: must_be_immutable
class LoadingDialog extends Dialog {
String text;
LoadingDialog({Key key, @required this.text}) : super(key: key);
@override
Widget build(BuildContext context) {
return new Material( //创建透明层
type: MaterialType.transparency, //透明类型
child: new Center( //保证控件居中效果
child: new SizedBox(
width: 120.0,
height: 120.0,
child: new Container(
decoration: ShapeDecoration(
color: Color(0xffffffff),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
),
),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
new CircularProgressIndicator(),
new Padding(
padding: const EdgeInsets.only(
top: 20.0,
),
child: new Text(
text,
style: new TextStyle(fontSize: 12.0),
),
),
],
),
),
),
),
);
}
}
1回答
-
亲的,问题解决了吗,如果没有,将你的完整代码以代码的格式贴出来,或者在课程群里小窗口老师我帮你调试下。
132019-11-01
相似问题