如何解决如何为flutter分配变量Navigator.pushcontext,variable;
我试图给它分配一个字符串 字符串变量=“'/ branchHome'”; Navigator.push(上下文,变量); 但这不适用于错误
self.move
我尝试这样做
Traceback (most recent call last):
File "<console>",line 1,in <module>
File "/home/.../lib/python3.8/site-packages/wagtail/core/models.py",line 1381,in move
super().move(target,pos=pos)
File "/home/.../lib/python3.8/site-packages/treebeard/mp_tree.py",line 1095,in move
return MP_MoveHandler(self,target,pos).process()
File "/home/.../lib/python3.8/site-packages/treebeard/mp_tree.py",line 472,in process
if self.target.is_descendant_of(self.node):
AttributeError: 'NoneType' object has no attribute 'is_descendant_of'
那也不起作用
如何在dart中为“路线名称”分配变量
编辑: main.dart
Error: The argument type 'String' can't be assigned to the parameter type 'Route<Object>'.
列表
Navigator.push(context,variable as Route);
我尝试了什么
void main() {
runApp(MaterialApp(
initialRoute: '/',routes: {
'/': (context) => Loading(),'/home': (context) => Home(),'/studentHome': (context) => studentHome(),'/getAllstudents': (context) => getAllStudent(),'/examHome': (context) => getAllBranch(),'/branchHome': (context) => branchHome(),'/subjectHome': (context) => subjectHome(),},));
}
和
List<Info> slides = [
Info(
1,name: 'Branches',desc: "branches info",url: "'/branchHome'",),Info(
2,name: 'Exams',desc: "exam info",url: "'/examHome'",];
解决方法
Navigator.pushNamed<dynamic>(context,slides[index].url);
这就像一个魅力
,尝试执行以下代码。
Navigator.of(context).pushNamed('/branchHome');
在 main.dart 文件中,您必须先提供路由字符串的引用。
例如
return new MaterialApp(
title: "MyApp",home: new HomePage(),routes: <String,WidgetBuilder> {
'/home': (BuildContext context) => new HomePage(),},
,
在您main.dar
中添加以下行
void main() {
runApp(MaterialApp(
title: 'Named Routes Demo',initialRoute: '/',routes: {
'/': (context) => FirstScreen(),'/second': (context) => SecondScreen(),'/third': (context) => thirdScreen(),));
}
在导航路线中
Navigator.pushNamed(context,'/second');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。