macosui / macos_ui

Flutter widgets and themes implementing the current macOS design language.
https://macosui.github.io/macos_ui/#/
MIT License
1.84k stars 177 forks source link

Replace ToolBar with PreferredSizeWidget #477

Open Otacon opened 1 year ago

Otacon commented 1 year ago

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

GroovinChip commented 11 months ago

Hello @Otacon and thanks for this PR. I apologize for my lateness in reviewing it.

Does this change hold any implications for SliverToolBar?

GroovinChip commented 2 weeks ago

@Otacon checking in