繁体   English   中英

在颤振中将一个变量值传递给另一个变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM