简体   繁体   English

带有浮动操作按钮的底部导航栏 flutter

[英]bottom navigation bar with Floating Action Button flutter

I want to make a bottom navigation bar, with a Floating Action Button, in Flutter我想在 Flutter 中制作一个带有浮动操作按钮的底部导航栏

when I click the Floating Action Button, the window will appear on the screen,当我单击浮动操作按钮时,window 将出现在屏幕上,

the photo in below will help to understand my request:下面的照片将有助于理解我的要求:

在此处输入图像描述

You can copy paste run full code below您可以在下面复制粘贴运行完整代码
You can use OverlayEntry and set color您可以使用OverlayEntry并设置color

entry = OverlayEntry(
      builder: (context) {
        return Center(
          child: Container(
            height: MediaQuery.of(context).size.height,
            width: MediaQuery.of(context).size.width,
            color: Colors.black.withOpacity(0.5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                RaisedButton(
                  onPressed: () {
                    entry.remove();
                  },
                  child: Text("abc"),

working demo工作演示

在此处输入图像描述

full code完整代码

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class BottomAppBarPage extends StatefulWidget {
  @override
  _BottomAppBarPageState createState() => _BottomAppBarPageState();
}

class _BottomAppBarPageState extends State<BottomAppBarPage> {
  OverlayEntry entry;

  @override
  void initState() {
    super.initState();
    entry = OverlayEntry(
      builder: (context) {
        return Center(
          child: Container(
            height: MediaQuery.of(context).size.height,
            width: MediaQuery.of(context).size.width,
            color: Colors.black.withOpacity(0.5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                RaisedButton(
                  onPressed: () {
                    entry.remove();
                  },
                  child: Text("abc"),
                ),
                RaisedButton(
                  onPressed: () {
                    entry.remove();
                  },
                  child: Text("def"),
                ),
                RaisedButton(
                  onPressed: () {
                    entry.remove();
                  },
                  child: Text("123"),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Bottom App Bar')),
      body: ListView(
        padding: const EdgeInsets.all(8),
        children: <Widget>[
          Container(
            height: 50,
            color: Colors.amber[600],
            child: const Center(child: Text('Entry A')),
          ),
          Container(
            height: 50,
            color: Colors.amber[500],
            child: const Center(child: Text('Entry B')),
          ),
          Container(
            height: 50,
            color: Colors.amber[100],
            child: const Center(child: Text('Entry C')),
          ),
        ],
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add),
        onPressed: () {
          Overlay.of(context).insert(entry);
        },
      ),
      bottomNavigationBar: BottomAppBar(
        shape: CircularNotchedRectangle(),
        notchMargin: 4.0,
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.menu),
              onPressed: () {},
            ),
            IconButton(
              icon: Icon(Icons.search),
              onPressed: () {},
            )
          ],
        ),
      ),
    );
  }
}

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: BottomAppBarPage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

暂无
暂无

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

相关问题 底部导航栏中的可扩展浮动操作按钮 - Flutter - Expandable Floating Action button in bottom navigation bar - Flutter 导航栏中的居中浮动操作按钮 Flutter - Centering Floating Action Button in navigation bar Flutter Flutter 中的浮动底部导航栏和浮动操作按钮 - Floating Bottom Nav Bar and Floating Action Button in Flutter 如何使用浮动操作按钮自定义底部导航栏以及左右曲线设计? - How to customize a bottom navigation bar in flutter with floating action button and and also curve design to the left and right? 如何在带边框的中心底部导航栏中添加浮动操作按钮? - How to add Floating action Button in Bottom Navigation Bar in Center with border? 如何在带有缺口的底部导航栏中心添加浮动操作按钮? - How to add Floating action Button in Bottom Navigation Bar Center with notch? 如何在 Flutter 中使用浮动底部导航栏 - How to use floating bottom navigation bar in Flutter 如何删除底部导航栏中浮动操作按钮的白色背景? - How can I remove white background of floating action button in bottom navigation bar? Flutter 转换 animation 打破底部导航栏中浮动操作按钮的“按下” function。 需要解决方法 - Flutter transform animation breaks “on pressed” function of floating action button in bottom nav bar. Workaround needed 如何使用具有良好动画颤动的动态浮动动作按钮创建底部导航栏? - how to create bottom nav bar with dynamic floating action button with good animation flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM