![](/img/trans.png)
[英]Cannot pass variable value from one stateless Widget to another in Flutter
[英]pass one variables value to another variable in flutter
在我的 flutter 應用程序中,我創建了變量var from, to;
並將它們及其值傳遞到下一頁。 我將它與widget.from
& widget.to
。 但是我怎么能把這個widget.from
& widget.to
變量傳遞給var newFrom, newTo;
這些變量?
class FirstPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var from = "Five", to = "Ten";
return SecondPage(from: from, to: to);
}
}
class SecondPage extends StatefulWidget {
final from, to;
const SecondPage({Key key, this.from, this.to}) : super(key: key);
@override
_SecondPageState createState() => _SecondPageState();
}
class _SecondPageState extends State<SecondPage> {
var newFrom = "", newTo = "";
@override
void initState() {
setState(() {
newFrom = widget.from;
newTo = widget.to;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
child: Text("$newFrom $newTo"),
);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.