【问题标题】:How to show a Container fixed at bottom of screen without using bottom navigation bar in Flutter?如何在不使用 Flutter 中的底部导航栏的情况下显示固定在屏幕底部的容器?
【发布时间】:2019-09-20 14:13:46
【问题描述】:

在我的颤振项目中,我有一个容器,下面有一些图标和文本。我希望将整个容器固定在屏幕底部,而不使用像下图这样的底部导航栏-

所以,我需要一个完整的示例来修复底部的容器,并使用滚动视图将我的其他组件保留在主体内。

【问题讨论】:

标签: flutter dart


【解决方案1】:

好的, 给你....

return Scaffold(
      appBar: AppBar(
        title: Text("Header"),
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: Container(
              alignment: Alignment.center,
              child: Text("Hello"),
            ),
          ),
          Container(
            height: 50,
            width: double.maxFinite,
            decoration: BoxDecoration(

            color: Colors.deepOrange,
            borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
            ),
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
                IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
                IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
                IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
              ],
            ),
          )
        ],
      ),
    );

【讨论】:

  • 非常感谢它有效。但是,如果我希望身体滚动并保持底部容器固定在那里,我会遇到另一个问题。我该怎么办?
  • 只需将Expanded 中的Container 替换为ListView
  • 需要更多建议 - 如果我想将 IconButtons 行(底部栏)包装在具有相同顶部边界半径高度的卡片中。我该怎么办?
  • 你能分享一些ui代码让我了解更多吗?
【解决方案2】:

如果你想在正文部分创建一个可滚动的项目/列表视图并想要一个固定的底部容器,你可以按照下面给出的代码:

重要提示:确保使用 Expanded 包装列表视图

导入'package:flutter/material.dart';

class ShoppingCart extends StatelessWidget {    
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[200],
        appBar: AppBar(
            backgroundColor: Colors.white,
            leading: IconButton(
              icon: Icon(Icons.arrow_back, color: Colors.black),
            ),
            actions: <Widget>[
              GestureDetector(
                  onTap: () {
                    //your code
                  },
                  child: Padding(
                    padding: const EdgeInsets.only(right: 15.0),
                    child: Icon(
                      Icons.delete_outline_sharp,
                      color: Colors.black,
                      size: 30,
                    ),
                  )),

              //Add more icon here
            ],
            elevation: 0,
            centerTitle: false,
            title:
                Text("Shopping Cart", style: TextStyle(color: Colors.black))),
        body: Column(
          children: [
            Expanded(
              child: ListView.builder(
                itemCount: shoppingCartItems.length,
                itemBuilder: (context, index) {
                  return Padding(
                    padding: const EdgeInsets.only(
                        top: 15.0, left: 12.0, right: 12.0),
                    child: Container(
                      decoration: BoxDecoration(
                          // color: Color(0xffF3F3F3),
                          color: Colors.red,
                          shape: BoxShape.rectangle,
                          borderRadius:
                              BorderRadius.all(Radius.circular(10.0))),
                      height: 120,
                      width: 360,
                    ),
                  );
                },
              ),
            ),
            Container(
              height: 150,
              width: double.maxFinite,
              decoration: BoxDecoration(
                  color: Colors.deepOrange[200],
                  borderRadius:
                      BorderRadius.vertical(top: Radius.circular(20.0))),
            )
          ],
        ));
  }
}

更新:

这是现在内置的。您可以使用 bottomNavigationBar 并自定义如下:

  bottomNavigationBar: BottomAppBar(
        child: Container(
          height: //set your height here
          width: double.maxFinite, //set your width here
          decoration: BoxDecoration(
            color: Colors.orange,
              borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
          ),
          child: Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[

              IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){
//on Presses functionaluty goes here
},),
              //add as many tabs as you want here
            ],
          ),
        ),
      ), 

【讨论】:

    【解决方案3】:
    bottomNavigationBar: BottomAppBar(
        child: Container(
          height: 50.0,
          width: double.maxFinite,
          decoration: BoxDecoration(
            color: Colors.deepOrange,
              borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
          ),
          child: Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
              IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
              IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
              IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
            ],
          ),
        ),
      ),
    

    【讨论】:

    • 请解释你的答案,添加cmets
    • 问题是没有使用bottomNavigationbar
    猜你喜欢
    • 2020-11-28
    • 2020-03-06
    • 2019-04-15
    • 2016-10-15
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多