flutter - 如何将变量分配给颤振 Navigator.push(context, variable);
问题描述
我试图给它分配一个字符串 String variable = "'/branchHome'"; Navigator.push(上下文,变量);但它不适用于错误
Error: The argument type 'String' can't be assigned to the parameter type 'Route<Object>'.
我试着这样做
Navigator.push(context, variable as Route);
那也没用
如何在飞镖中将变量分配给路线名称
编辑: main.dart
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'",
),
];
我试过的
onTap: () {
Navigator.push(context, slides[index].url);
},
和
onTap: () {
Navigator.push(context, slides[index].url as Route);
},
解决方案
Navigator.pushNamed<dynamic>(context, slides[index].url);
这就像一个魅力
推荐阅读
- javascript - React 如何确定引用类型状态是否是新的?
- android - 如何通过android studio更改wifi状态
- javascript - 议程更改文本颜色的属性是什么
- amazon-web-services - 在 EKS 中的 Kubernetes 中运行时,如何为 Elasticsearch 节点设置“max_map_count”和“ulimit”?
- codeigniter-3 - 无法访问与您的字段名称电子邮件地址相对应的错误消息。(is_uniqe)
- python - 如何在函数python中删除数据框行
- java - 为什么它会创建 indexoutofbounds 错误,我该如何解决?
- common-lisp - 为什么这个 with-gensyms 的实现会产生一个额外的逗号?
- reactjs - REACT-拖动事件触发多次(默认阻止)
- java - JavaFx 时间线表现怪异