【问题标题】:Notch in BottomAppBar for custom FABBottomAppBar 中用于自定义 FAB 的缺口
【发布时间】:2019-01-24 10:34:58
【问题描述】:

我正在使用 unicorndial 包中的 UnicornDialer 在我的应用主页上创建 Material 快速拨号体验,但如果我将 shape 属性设置为定义缺口,则不会绘制缺口正确:

我注意到在另一个包 (flutter_speed_dial) 上明确提到这不起作用:

SpeedDial 小部件是为放置在 floatingActionButton 中而构建的 Scaffold 小部件的参数。无法设置它 使用 Scaffold.floatingActionButtonLocation 参数定位 尽管。可以与 Scaffold.bottomNavigationBar 一起使用,但 浮动按钮将放置在栏上方,没有 可以放置一个缺口。

UnicornDialer 的情况下,build 方法返回的小部件是标准的 FloatingActionButton 并且已经浏览了 ScaffoldBottomAppBar 的代码我无法弄清楚为什么缺口被破坏像这样。

我曾尝试使用标准 FAB(但透明)来创建缺口,然后将 ScaffoldUnicornDialer 包装在 Stack 中以定位所有内容,这工作正常,但是当您显示 @987654335 @ UnicornDialer 不动,所以我又回到需要 BottomAppBar 来正确处理自定义 FAB 以进行缺口计算。有什么想法吗?

【问题讨论】:

  • 我发布了较早的答案,该答案暗示了负缺口边距,但很快意识到我确实间接删除了缺口,因此我删除了先前的答案,但当前的答案实际上工作正常。希望有所帮助。

标签: flutter floating-action-button android-bottomappbar


【解决方案1】:

你需要用容器包裹 UnicornDialer 并控制缺口边距, 请注意,notchMargin 可以取负值,

bottomAppBar 的凹口的渲染器似乎无法从原始 UnicornDialer 正确计算 Besier 曲线。

您可以使用以下代码作为指导。它运行良好

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

void main() =>
    runApp(new MaterialApp(debugShowCheckedModeBanner: false, home: Example()));

class Example extends StatefulWidget {
  _Example createState() => _Example();
}

class _Example extends State<Example> {
  @override
  Widget build(BuildContext context) {
    var childButtons = List<UnicornButton>();

    childButtons.add(UnicornButton(
        hasLabel: true,
        labelText: "Choo choo",
        currentButton: FloatingActionButton(

          heroTag: "train",
          backgroundColor: Colors.redAccent,
          mini: true,
          child: Icon(Icons.train),
          onPressed: () {},
        )));

    childButtons.add(UnicornButton(
        currentButton: FloatingActionButton(
            heroTag: "airplane",
            backgroundColor: Colors.greenAccent,
            mini: true,
            child: Icon(Icons.airplanemode_active))));

    childButtons.add(UnicornButton(
        currentButton: FloatingActionButton(
            heroTag: "directions",
            backgroundColor: Colors.blueAccent,
            mini: true,
            child: Icon(Icons.directions_car))));

    return Scaffold(

      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: new BottomAppBar(
        shape: CircularNotchedRectangle(),


        notchMargin: -10.0,

        color: Colors.blue,
        child: new Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.menu),
              onPressed: () {},
            ),
            IconButton(
              icon: Icon(Icons.search),
              onPressed: () {},
            ),
          ],
        ),
      ),
      //floatingActionButton: FloatingActionButton(onPressed: (){}),
      floatingActionButton: Container(
        width: 100.0,
        height: 100.0,
        child: UnicornDialer(
            hasNotch: true,
            //hasBackground: false,
            backgroundColor: Color.fromRGBO(255, 255, 255, 0.0),
            parentButtonBackground: Colors.redAccent,
            orientation: UnicornOrientation.VERTICAL,
            parentButton: Icon(Icons.add),
            childButtons: childButtons),
      ),
      appBar: AppBar(),
      body: Container(

        child: Center(
          child: RaisedButton(
            onPressed: () {
              setState(() {});
            },
          ),
        ),
      ),
    );
  }
}

【讨论】:

  • 是的,这似乎可行,尽管设置容器的大小会影响 FAB 的大小。你知道尺寸应该是多少才能满足材料准则 (56dp) 吗?
  • 最小宽度 56dp 最小高度 112dp ,超过这些阈值只会影响缺口而不影响晶圆厂
  • 经过更多调查,正确的最小宽度应为 56dp,最小高度应为 56*1.5,即 84dp
  • 谢谢。 1.5 乘数从何而来?如果是圆形FAB,为什么最小高度大于最小宽度?
  • 这个“乘数”仅在主晶圆厂有子代的情况下才需要,如果没有,每个子代将是 56dp,但将子代添加到主晶圆厂会添加难以跟踪的内部交叉轴填充,但我想总共大约 28dp。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-05-20
  • 1970-01-01
  • 2021-05-19
  • 1970-01-01
  • 1970-01-01
  • 2019-03-06
  • 1970-01-01
相关资源
最近更新 更多