【问题标题】:loading a new page using material button in flutter [duplicate]使用颤振中的材料按钮加载新页面[重复]
【发布时间】:2020-08-22 17:19:59
【问题描述】:

我使用这段代码来加载一个新页面,但它什么也没做! 它与StatefulWidget有关吗? (MaterialButton 在一个 stful 小部件下)

                          MaterialButton(
                            onPressed: () {
                              titlenote = titleinput.text;
                              subtitlenote = subtitleinput.text;
                              Navigator.of(context).pop();
                              new MaterialPageRoute(builder: (context) {
                                return notes();
                              });
                            },

这是 newpage stless 小部件:

class notes extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: new Column(children: <Widget>[
        new Container(
          padding: EdgeInsets.fromLTRB(8, 20, 8, 20),
          color: Colors.transparent,
          child: new CheckboxListTile(
            value: true,
            onChanged: (bool a) {},
            title: Text("$titlenote"),
            selected: true,
            checkColor: Colors.green,
            activeColor: Colors.black,
            tristate: true,
            subtitle: Text("$subtitlenote"),
          ),
          alignment: Alignment.center,
        )
      ]),
    );
  }

}

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    您创建了一个MaterialPageRoute,但您从未使用导航器推送它。顺便说一句,您可以使用pushReplacement 同时poppush

    Navigator.of(context).pushReplacement(
        MaterialPageRoute(builder: (context) {
            return notes();
    }));
    

    注意:关键字new 从 Dart 2 开始就没用了,每次看到都可以删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-17
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-09
      • 2020-12-04
      • 1970-01-01
      相关资源
      最近更新 更多