简体   繁体   English

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

[英]How to show a Container fixed at bottom of screen without using bottom navigation bar in Flutter?

In my flutter project, I have a container with some icons and text below them.在我的 flutter 项目中,我有一个容器,下面有一些图标和文本。 I want this entire container to be fixed at bottom of the screen without using bottom navigation bar like the below image-我希望将整个容器固定在屏幕底部,而不使用下图所示的底部导航栏-

在此处输入图像描述

So, I need an entire example to fix that container at bottom and keep my other components inside body with a scroll view.因此,我需要一个完整的示例来修复底部的容器,并使用滚动视图将我的其他组件保留在主体内。

Ok, Here you go....好的,给你 go....

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: (){},),
              ],
            ),
          )
        ],
      ),
    );
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: (){},),
        ],
      ),
    ),
  ),

If you want to make a scrollable item/listview in the body section and want a fixed bottom container you can follow this code given below:如果你想在正文部分创建一个可滚动的项目/列表视图并想要一个固定的底部容器,你可以按照下面给出的代码:

important note: Make sure wrap the listview with Expanded重要说明:确保使用 Expanded 包装列表视图

import 'package:flutter/material.dart';导入“包:颤振/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))),
            )
          ],
        ));
  }
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 如何将相同的底部导航栏显示到子屏幕 - Flutter how to show the same bottom navigation bar to a sub screen 如何在容器底部显示 Snackbar 而不是屏幕 flutter - How to show Snackbar at the bottom of container and not screen flutter 如何在flutter中不在导航项列表中的页面中显示底部导航栏? - How to show bottom navigation bar in page that is not in the navigation item list in flutter? 底部导航栏中的容器占据整个屏幕 - Container in Bottom Navigation Bar taking whole screen 如何根据flutter中底部导航栏的索引更改容器? - How to change the container according to the index of a bottom navigation bar in flutter? 底部导航栏隐藏屏幕 - Flutter - Bottom Navigation Bar hides the screen - Flutter 如何使用底部导航栏导航到特定屏幕 - How can you navigate to a specific screen in flutter with the bottom navigation bar 在flutter中如何使底部导航栏在访问前不加载屏幕 - How to make bottom navigation bar not to load the screen before visiting in flutter 如何通过传递选定的索引在 flutter 底部导航栏上打开屏幕 - How to open a screen on flutter bottom navigation bar by passing selected index 如何在 flutter 的新屏幕上隐藏底部导航栏? - how to hide Bottom Navigation Bar on new screen in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM