如何不使用Flutter中的底部导航栏在屏幕底部显示固定的Container?

时间:2019-09-20 14:13:46

标签: flutter dart

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

enter image description here

因此,我需要一个完整的示例来将该容器固定在底部,并通过滚动视图将其他组件保留在体内。

3 个答案:

答案 0 :(得分: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: (){},),
              ],
            ),
          )
        ],
      ),
    );

答案 1 :(得分:0)

bottomNavigationBar:BottomAppBar( 孩子:容器( 高度:50, 宽度:double.maxFinite, 装饰: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: (){},),
          ],
        ),
      )
    ),

答案 2 :(得分:0)

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

重要说明:确保使用 Expanded 包裹列表视图

import '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))),
            )
          ],
        ));
  }
}

enter image description here