gpt4 book ai didi

view - Flutter - 不同 View 之间的路由

转载 作者:IT老高 更新时间:2023-10-28 12:37:14 33 4
gpt4 key购买 nike

所以,我有这个文件:

import 'package:flutter/material.dart';
import "calculateDerivations.dart";
import "calculateRoots.dart";

void main() {
runApp(new MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Ableitungen berechnen'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {

return new Scaffold(
appBar: new AppBar(title: new Text(config.title)),
body: new Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
new InputWidget(),
]
),
);
}
}

class InputWidget extends StatefulWidget {
@override
InputWidgetState createState() => new InputWidgetState();
}

class InputWidgetState extends State<InputWidget> {

InputValue val = new InputValue(text: "");
String ersteAbleitung = "";
String zweiteAbleitung = "";
String dritteAbleitung = "";
String roots = "";
String function = "";

void _submitted(){
setState((){
/*
* Redirect here
*/
});
}

@override
Widget build(BuildContext context) {

return new Column(
children: [
new Input(
value: val,
labelText: 'Funktion hier eingeben',
onChanged: (InputValue newInputValue) {
setState(() {
val = newInputValue;
});
}),
new IconButton(
icon: new Icon(Icons.check),
onPressed: _submitted,
)
]
);
}
}

一旦用户现在单击 IconButton(调用 _submitted),我希望他被重定向到新的 View (小部件)。在 Flutter 中如何解决这个路由问题?

提前致谢

最佳答案

正常的路线导航可能如下所示:

new IconButton(
icon: new Icon(Icons.check),
onPressed: () {
Navigator.push(context, new MaterialPageRoute(
builder: (_) => new MyCustomView(),
);
)
)

您还可以通过将 WidgetBuilder 的映射作为 MaterialApproutes 构造函数参数来使用命名路由,或者通过传递onGenerateRoute 处理程序。有一个example Flutter 库中的命名路由。

如果您不希望有动画,请参阅我对 this question 的回答.

关于view - Flutter - 不同 View 之间的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43683216/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com