0

我正在尝试重新配置 BottomAppBar 类。问题是,我无法弄清楚 CircularNotchedRectangle 类如何获得 FAB 矩形位置的可见性以计算缺口。

BottomAppBar 源码在这里

CircularNotchedRectangle 源在这里

为了给出一个工作示例,我从此处获取了 _DemoBottomAppBar 的源代码,删除了所有按钮和内容,您在下面看到的是结果。如您所见,据我所知,FAB 位置和 FAB 构造都没有传递到 BottomAppBar() 或 CircularNotchedRectangle()。

重申一下,我的问题是,当没有明确传递任何内容时,_DemoBottomAppBar 类中的唯一且唯一的 CircularNotchedRectangle() 实例如何获取有关树上方 _BottomAppBarDemoState 小部件中的 FAB 的信息?

有人可以帮忙吗?真的很感激……</p>

import 'package:flutter/material.dart';

void main() {
  runApp(const BottomAppBarDemo());
}

class BottomAppBarDemo extends StatefulWidget {
  const BottomAppBarDemo({Key? key}) : super(key: key);
  @override
  State createState() => _BottomAppBarDemoState();
}

class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          automaticallyImplyLeading: false,
          title: const Text('Bottom App Bar Demo'),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: const Icon(Icons.add),
          tooltip: 'Create',
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        bottomNavigationBar: _DemoBottomAppBar(
        ),
      ),
    );
  }
}

class _DemoBottomAppBar extends StatelessWidget {
  const _DemoBottomAppBar();
  @override
  Widget build(BuildContext context) {
    return BottomAppBar(
      shape: CircularNotchedRectangle(),
      color: Colors.blue,
      child: IconTheme(
        data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary),
        child: Row(
          children: <Widget>[
            IconButton(
              tooltip: 'Open navigation menu',
              icon: const Icon(Icons.menu),
              onPressed: () {},
            ),
          ],
        ),
      ),
    );
  }

编辑...

好的,所以我想我会发布更新,因为我想我可能已经解决了。如果我是对的,那么答案很简单。

本质上,我们将 CircularNotchedRectangle() 类传递给 BottomAppBar 构造函数,以便可以在绑定到 BottomAppBar 类的某些方法中访问 CircularNotchedRectangle.getOuterPath()。这就是 CircularNotchedRectangle 可以访问未专门传递给其构造函数的变量的方式。

希望这可以帮助任何可能感兴趣的人。

4

0 回答 0