[英]'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5338 pos 12: '!_debugLocked': is not true. And this is my Code given Below
When i implement code for Splash screen page and that navigate to a login screen and rising an EXception Like this 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5338 pos 12: ':_debugLocked'.当我为启动屏幕页面实现代码并导航到登录屏幕并出现异常时,像这样'package:flutter/src/widgets/navigator.dart':断言失败:第5338行pos 12:':_debugLocked'。 is not true, the function i declared for navigating the page is not working properly but there is no compile time error.不是真的,我声明的用于导航页面的 function 无法正常工作,但没有编译时错误。 the error is only showing while run time.该错误仅在运行时显示。 I don't Know how to this Solve this Pls Anybody help我不知道如何解决这个问题请大家帮忙
import 'package:first_project_1/Screens/login.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ScreenSplash extends StatefulWidget {
const ScreenSplash({Key? key}) : super(key: key);
@override
_ScreenSplashState createState() => _ScreenSplashState();
}
class _ScreenSplashState extends State<ScreenSplash> {
@override
void initState() {
// TODO: implement initState
super.initState();
gotoLogin(context);
}
@override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Image.asset('assets/images/VDlogo.png',height: 150,),
),
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
}
Future<void> gotoLogin(BuildContext context) async {
Future.delayed(Duration(seconds: 4),);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (ctx)=> ScreenLogin(),
),
);
}
}
This is because the Navigator.pushReplacement
is called right in the initState
.这是因为在initState
中直接调用了Navigator.pushReplacement
。 Your Future.delayed
isn't await
ed, so it doesn't wait those 4 seconds for the push.您的Future.delayed
不是await
ed,因此它不会等待那 4 秒的推送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.