问题描述
我试图给它分配一个字符串 字符串变量=“'/ 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 @H_502_16@
Error: The argument type 'String' can't be assigned to the parameter type 'Route<Object>'.
列表@H_502_16@
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');