Replace ToolBar with PreferredSizeWidget
TL;DR
As per SOLID principles, MacOsScaffold's toolBar should be a PreferredSizeWidget.
The longer story.
Hello guys, hope you are well. I was going to write an app for MacOS. I have adopted this amazing library.
However, I have hit a wall with this scenario:
My MainScreen contains a MacOsScaffold, which contains a ToolBar and many children:
MacosScaffold(
toolBar: const ToolBar(),
children: [
...
],
);
My ToolBar has many options, conditions and buttons, so I would like to create a separate Widget to deal with those.
However, the MacosScaffold doesn't accept anything else that is not a ToolBar.
Other frameworks (e.g. Material) accepts a PreferredSizeWidget, which allows me to write
import 'package:macos_ui/macos_ui.dart'; //kToolbarHeight is now publicly available!
class MyToolbar extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
return ToolBar(
actions: [
...
],
)
}
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}
And this solves my problem.
BONUS: this respect's Flutter's phylosophy of composition over inheritance.
Pre-launch Checklist
- [x] I have incremented the package version as appropriate and updated
CHANGELOG.mdwith my changes - [x] I have added/updated relevant documentation
- [x] I have run "optimize/organize imports" on all changed files
- [x] I have addressed all analyzer warnings as best I could
Hello @Otacon and thanks for this PR. I apologize for my lateness in reviewing it.
Does this change hold any implications for SliverToolBar?