【问题标题】:how to add a fixed to bottom container to a sliver flutter如何将固定到底部的容器添加到条子颤振中
【发布时间】:2021-04-28 18:23:32
【问题描述】:

我有一个 sliverAppbar 和一个滚动的 sliver 列表。但是,我需要在屏幕底部有一个固定容器,无论滚动位置或屏幕上的其他任何内容如何,​​它都不会移动,相当于 web CSS 中的position fixed。 我使用SliverToBoxAdapterstackpositioned 小部件来实现此功能,但它会引发错误

    Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[100],
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            primary: true,
            pinned: true,
            snap: false,
            elevation: 1.0,
            backgroundColor: Colors.blueAccent,
            floating: false,
            expandedHeight: 200.0,
            title: Text(
              "Title",
              style: TextStyle(
                  // color: Colors.grey[900]
                  ),
            ),
            flexibleSpace: FlexibleSpaceBar(
              background: Image.network(
                "https://images.pexels.com/photos/20990/pexels-photo-20990.jpeg?auto=compress&cs=tinysrgh=650&w=940",
                height: double.infinity,
                width: double.infinity,
                fit: BoxFit.cover,
              ),
            ),
          ),
          SliverList(
              delegate: SliverChildListDelegate([
            Container(color: Colors.red, height: 150.0),
            Container(color: Colors.purple, height: 150.0),
            Container(color: Colors.green, height: 150.0),
            Container(color: Colors.red, height: 150.0),
            Container(color: Colors.purple, height: 150.0),
            Container(color: Colors.green, height: 150.0),
          ])),
          SliverToBoxAdapter(
              child: Stack(
            children: [
              Positioned(
                bottom: 0,
                child: Container(
                  height: 80.0,
                  color: Colors.yellowAccent,
                ),
              ),
            ],
          )),
        ],
      ),
    );
  }

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    您可以尝试在脚手架上添加一个底部导航栏

       Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.grey[100],
          body: CustomScrollView(
            slivers: []
          ),
          bottomNavigationBar: Container(),
          
        );
      }
    ```
    

    【讨论】:

      猜你喜欢
      • 2021-05-30
      • 1970-01-01
      • 2022-11-25
      • 2017-06-27
      • 2023-03-29
      • 1970-01-01
      • 2020-02-05
      • 2018-01-15
      • 2017-07-31
      相关资源
      最近更新 更多