Flutter 尝试根据按下的按钮推送到不同的视图控制器/视图
我是一个新手,正在为一件看似简单的事情而挣扎 我的视图中有几个按钮,每个按钮对应一个不同的(视图控制器)小部件。根据按下的按钮,我想导航到相应的视图 请参阅下文以获得更好的解释Flutter 尝试根据按下的按钮推送到不同的视图控制器/视图,flutter,dart,Flutter,Dart,我是一个新手,正在为一件看似简单的事情而挣扎 我的视图中有几个按钮,每个按钮对应一个不同的(视图控制器)小部件。根据按下的按钮,我想导航到相应的视图 请参阅下文以获得更好的解释 Future navigateToPage(context, vc) async { Navigator.push(context, MaterialPageRoute(builder: (context) => vc())); } class CircularView extends StatelessW
Future navigateToPage(context, vc) async {
Navigator.push(context, MaterialPageRoute(builder: (context) => vc()));
}
class CircularView extends StatelessWidget {
@override
Widget build(BuildContext context) {
StatelessWidget vc;
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
Widget bigCircle = Container(
width: (width * 0.9),
height: (height * 0.5),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
);
return Material(
color: Colors.white,
child: Center(
child: Stack(
children: <Widget>[
bigCircle,
Positioned(
child: CustomFloatingActionButton(
onPressed: () {
vc = MoneyView(); // < -- Here is where I am assigning the vc variable to a view.
navigateToPage(context, vc);
},
buttonType: ButtonType.money,
buttonImage: FontAwesomeIcons.moneyBill,
label: '',
),
top: ((height * 0.5) * 0.175),
left: ((width * 0.9) * 0.12),
),
Positioned(
child: CustomFloatingActionButton(
onPressed: () {
vc = SchedulesView(); // < ---- And here
navigateToPage(context, vc);
},
buttonType: ButtonType.schedules,
buttonImage: FontAwesomeIcons.database,
label: '',
),
top: ((height * 0.5) * 0.123),
left: ((width * 0.9) * 0.559),
),
Positioned(
child: CustomFloatingActionButton(
onPressed: () {
vc = VisitsView; // < ---- And here
navigateToPage(context, vc);
},
buttonType: ButtonType.keyDates,
buttonImage: FontAwesomeIcons.calendar,
label: '',
),
top: ((height * 0.5) * 0.434),
left: ((width * 0.9) * 0.729),
),
Positioned(
child: CustomFloatingActionButton(
onPressed: () {
vc = RequestsView(); // < ---- And here
navigateToPage(context, vc);
},
buttonType: ButtonType.requests,
buttonImage: FontAwesomeIcons.question,
label: '',
),
top: ((height * 0.5) * 0.687),
left: ((width * 0.76) * 0.53),
),
Positioned(
child: CustomFloatingActionButton(
onPressed: () {
vc = KeyDatesView(); // < ---- And here
navigateToPage(context, vc);
},
buttonType: ButtonType.visits,
buttonImage: FontAwesomeIcons.handshake,
label: '',
),
top: ((height * 0.5) * 0.53),
left: ((width * 0.76) * 0.051),
),
],
),
),
);
}
}
未来导航页面(上下文,vc)异步{
push(context,materialpage(builder:(context)=>vc());
}
类CircularView扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
无状态vc;
double width=MediaQuery.of(context).size.width;
double height=MediaQuery.of(context).size.height;
Widget bigCircle=容器(
宽度:(宽度*0.9),
高度:(高度*0.5),
装饰:盒子装饰(
颜色:颜色,白色,
形状:BoxShape.circle,
),
);
退货(
颜色:颜色,白色,
儿童:中心(
子:堆栈(
儿童:[
大圈子,
定位(
子项:CustomFloatingActionButton(
onPressed:(){
vc=MoneyView();//<--这里是我将vc变量赋值给视图的地方。
导航页面(上下文,vc);
},
buttonType:buttonType.money,
buttonImage:FontAwesomeIcons.moneyBill,
标签:“”,
),
顶部:((高度*0.5)*0.175),
左:((宽度*0.9)*0.12),
),
定位(
子项:CustomFloatingActionButton(
已按下:(){
vc=SchedulesView();//<----这里
导航页面(上下文,vc);
},
buttonType:buttonType.schedules,
buttonImage:FontAwesomeIcons.database,
标签:“”,
),
顶部:((高度*0.5)*0.123),
左:((宽度*0.9)*0.559),
),
定位(
子项:CustomFloatingActionButton(
已按下:(){
vc=VisitsView;//<----这里
导航页面(上下文,vc);
},
buttonType:buttonType.keyDates,
buttonImage:FontAwesomeIcons.calendar,
标签:“”,
),
顶部:((高度*0.5)*0.434),
左:((宽度*0.9)*0.729),
),
定位(
子项:CustomFloatingActionButton(
已按下:(){
vc=RequestsView();//<----这里
导航页面(上下文,vc);
},
buttonType:buttonType.requests,
buttonImage:FontAwesomeIcons.question,
标签:“”,
),
顶部:((高度*0.5)*0.687),
左:((宽度*0.76)*0.53),
),
定位(
子项:CustomFloatingActionButton(
已按下:(){
vc=KeyDatesView();//<----这里
导航页面(上下文,vc);
},
buttonType:buttonType.visions,
buttonImage:FontAwesomeIcons.handshake,
标签:“”,
),
顶部:((高度*0.5)*0.53),
左:((宽度*0.76)*0.051),
),
],
),
),
);
}
}
我在模拟器上收到的错误表明,没有这样的方法错误:“MoneyView”没有实例方法“call”
因此,也许我在“MoneyView”课程中做错了什么
谢谢你能提供的任何帮助
作为建议,您可以在方法和函数中使用命名参数。它将简化你未来的生活:)为什么只有
MoneyView
有括号()
?我唯一能找到的就是这个,你可能想看看这个。抱歉,我已经把它们编辑回来了(它们被正式注释掉了)。