android - 如何在带有缺口的底部导航栏中心添加 float Action 按钮?

标签 android dart flutter flutter-layout

我试图在底部导航栏的中间添加一个 float Action 按钮。问题没有出现。这是问题的图片。

Notch not showing around red fab icon

我的代码是这样的

import 'package:flutter/material.dart';

class MyHome extends StatefulWidget {
  @override
  _MyHomeState createState() => _MyHomeState();
}

class _MyHomeState extends State<MyHome> {
  int _selectedTab = 0;
  final _pageOptions = [
    Text('Item 1'),
    Text('Item 2'),
    Text('Item 3'),
    Text('Item 4'),
  ];

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primaryColor: Color(0xffFF5555),
      ),
      home: Scaffold(
        body: _pageOptions[_selectedTab],
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: Icon(Icons.add),
          backgroundColor: Colors.red,
          foregroundColor: Colors.white,
          elevation: 2.0,
        ),
        bottomNavigationBar: BottomAppBar(
          notchMargin: 2.0,
          shape: CircularNotchedRectangle(),
          child: SizedBox(
            height: 80,
            child: Theme(
              data: Theme.of(context).copyWith(
                  // sets the background color of the `BottomNavigationBar`
                  canvasColor: Color(0xff1B213B),

                  // sets the active color of the `BottomNavigationBar` if `Brightness` is light
                  primaryColor: Color(0xffFF5555),
                  textTheme: Theme.of(context)
                      .textTheme
                      .copyWith(caption: new TextStyle(color: Colors.white))),
              child: BottomNavigationBar(
                type: BottomNavigationBarType.fixed,
                currentIndex: _selectedTab,
                onTap: (int index) {
                  setState(() {
                    _selectedTab = index;
                  });
                },
                fixedColor: Color(0xffFF5555),
                items: [
                  BottomNavigationBarItem(
                      icon: Icon(Icons.tv), title: Text('')),
                  BottomNavigationBarItem(
                      icon: Icon(Icons.card_membership), title: Text('')),
                  BottomNavigationBarItem(
                      icon: Icon(Icons.share), title: Text('')),
                  BottomNavigationBarItem(
                      icon: Icon(Icons.home), title: Text('')),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

我想在中间的红色fab图标周围添加缺口。我尝试了两种形状:CircularNotchedRectangle()和AutomaticNotchedShape方法。但是没有任何效果。大多数示例显示在“BottomAppBar”内使用“Row”。但是我想使用BottomNavigationBar。请帮我找到解决方案

最佳答案

在小部件BottomAppBar()中使用此属性
clipBehavior: Clip.antiAlias,

关于android - 如何在带有缺口的底部导航栏中心添加 float Action 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55727315/

相关文章:

java - TelephonyManager 结束通话的替代方法

android - 在 NumberPicker 中显示特定值

dart - 如何将额外的变量传递给 Dart 中的回调函数

android - 如何在 flutter 中使用列中的文本时消除文本溢出

flutter - 使用 Flutter "sms 0.2.4"库接收短信后应用程序崩溃

dart - 更改 BottomSheet 的灰色叠加背景

android - 不断更新 RecyclerView 项目

android - 共享首选项android基本问题

flutter - 不能将参数类型 'jsObject'分配给 'buildContext'参数?

flutter - 如何从受 Cloudflare DDOS 保护的 URL 获取 Assets ?