繁体   English   中英

如何在卡片中将数据从卡传递到新页面

[英]How to pass data from card to new page in flutter

我想将数据从卡传递到新页面,该数据有两个名称START,卡上的STOP下方。当用户单击卡时,“ START”数据应传递到新页面。下面是代码

class MyList extends StatefulWidget {
  @override
  _MyListState createState() => _MyListState();
}

class _MyListState extends State<MyList> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: Text("List"),
      ),
      body: new Container(
        padding: new EdgeInsets.only(left: 5.0,top: 20.0,right: 5.0),
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            GestureDetector(
              onTap: (){

              },
              child: new Card(
                child:
                new Column(
                  children: <Widget>[
                    new Text('START'),
                    new Text('STOP')
                  ],
                ),
              ),
            ),

新的一页

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("New page"),
      ),
      body:Container(
child:Center(
new Text('textview'))

您的新页面MyHomePage应该接受所需的输入作为参数,例如

class MyHomePage extends StatefulWidget {
  final String startText;
  final String stopText;
  MyHomePage(this.startText, this.stopText);
  ....
}
.....

onTap应该使用此数据创建MyHomePage的新实例,然后像启动页面一样

Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => MyHomePage("start", "stop"),
      ),
    );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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