【问题标题】:flutter, next page with a variable controller颤动,带有变量控制器的下一页
【发布时间】:2021-06-06 23:04:53
【问题描述】:

对不起,伙计们,我正在尝试构建一个新页面,但其中包含变量“nextcode”。所以在新页面中,它将显示下一个代码文本

                    onTap: () {
                      Navigator.push(
                          context,
                          MaterialPageRoute(
                              builder: (context) => Lemari(nextcode)));
                    },

但在“Widget build(String Kode) {”行中必须是这样的“Widget build(BuildContext context) {”

class Lemari extends StatelessWidget {

  @override
   Widget build(String Kode) {
    return Scaffold(
        appBar: AppBar(
           backgroundColor: Colors.blue[900],
           title: Text('this is th next page'),

        ),
         backgroundColor: Colors.white,
         body: Center(
          child: Column(
            children: [
            Container(height: 100, width: 100, color: Colors.red, child: Text('hhe'),),
            ]
          ),
         ),
    );
  }
}

那么有谁能帮助我吗?请:(

【问题讨论】:

    标签: android flutter dart statelesswidget


    【解决方案1】:

    您不必更改构建方法参数,而是应该在小部件中添加一个新参数并要求它

    示例 const MyPageView({Key?key}) : super(key: key);

    在这里您可以添加另一个参数。 然后在类中定义该参数.. 所以当你创建一个新的 MyPageView 时,你必须传递新添加的参数

    再见:)

    【讨论】:

      【解决方案2】:

      您的代码应该有编译器错误

      在 Lemari 中,你永远不会声明 nextcode 并且构造函数也没有参数 nextcode。

      你可以这样试试,加

      class Lemari extends StatelessWidget {
        final String nextcode;
        const Lemari({Key key, this.nextcode}) : super(key: key);
      
        @override
        Widget build(BuildContext context) {}
      }
      

      如果你的nextcode 是String

      【讨论】:

        猜你喜欢
        • 2021-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-21
        相关资源
        最近更新 更多