【问题标题】:How retrieve two classes Flutter如何检索两个类 Flutter
【发布时间】:2021-05-05 22:03:49
【问题描述】:

我很害怕,我有一个快速的问题,想检索两个类SearchBar() & HomeView(),但它只允许检索一个类。我了解缺少某些内容,我想听听您的建议以便更好地学习。

    return Scaffold(
        appBar: AppBar(
          title: Text(title),
          actions: <Widget>[
            IconButton(
                icon: Icon(
                  Icons.add_box,
                  color: Colors.white,
                ),
                onPressed: () {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) =>
                              AddBookPage(uid: this.widget.uid)));
                })
          ],
        ),
        body: SearchBar(),
        body: HomeView(),
        drawer: NavigateDrawer(uid: this.widget.uid));
  }

Here is the picture how i would like make it look like

I get Search Bar overflowed by Infinity pixels on the bottom

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    使用Column:

    Scaffold(
      body: Column(
        children: [
          SearchBar(),
          SizedBox(height: 20),
          Expanded(
            child: HomeView(),
          )
        ],
      ),
      // ... your other code
    )
    

    【讨论】:

    • 感谢@CopsOnRoad 的帮助,我非常感谢它,但我收到另一个错误,因为它被底部的无限像素溢出。我还添加了额外的屏幕截图
    • @Chorche 我不知道你的SearchBar 里有什么。但是,要测试上面的代码,请将您的 SearchBar 包装在 SizedBox 中,并为该框指定 height,例如 200
    • 再次感谢,祝您有美好的一天:)
    【解决方案2】:

    使用Column 可能是最好的方法。 溢出错误可能是由SearchBar() 小部件没有定义的高度引起的。 Column 小部件不能有一个无限高的孩子。

    【讨论】:

    • Grazie,对于信息丰富的答案,我会检查一下。
    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 2019-11-14
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多