Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(master-detail): allow inserting spacers and dividers #736

Merged
merged 1 commit into from Jul 24, 2023
Merged

feat(master-detail): allow inserting spacers and dividers #736

merged 1 commit into from Jul 24, 2023

Conversation

jpnurmi
Copy link
Member

@jpnurmi jpnurmi commented Jul 24, 2023

A separate bottom bar works fine for about or settings dialogs and similar, but gets clumsy if one wants to have normal master tiles at the bottom. This PR makes it possible for YaruMasterDetailPage.tileBuilder to return spacers (and dividers) to make it possible to categorize master list items in any way desired.

image

final pages = <({WidgetBuilder tile, WidgetBuilder page})>[
  (
    tile: (_) => const YaruMasterTile(title: Text('Foo')),
    page: (_) => const Center(child: Text('Foo')),
  ),
  (
    tile: (_) => const YaruMasterTile(title: Text('Bar')),
    page: (_) => const Center(child: Text('Bar')),
  ),
  (
    tile: (_) => const YaruMasterTile(title: Text('Baz')),
    page: (_) => const Center(child: Text('Baz')),
  ),
  (
    tile: (_) => const YaruMasterTile(title: Text('Qux')),
    page: (_) => const Center(child: Text('Qux')),
  ),
  (
    tile: (_) => const Spacer(),
    page: (_) => const SizedBox.shrink(),
  ),
  (
    tile: (_) => const Divider(height: 1),
    page: (_) => const SizedBox.shrink(),
  ),
  (
    tile: (_) => const YaruMasterTile(title: Text('Manage')),
    page: (_) => const Center(child: Text('Manage')),
  ),
  (
    tile: (_) => const YaruMasterTile(title: Text('About')),
    page: (_) => const Center(child: Text('About')),
  ),
];

return Scaffold(
  appBar: const YaruWindowTitleBar(title: Text('YaruMasterDetailPage')),
  body: YaruMasterDetailPage(
    length: pages.length,
    tileBuilder: (context, index, selected, availableWidth) =>
        pages[index].tile(context),
    pageBuilder: (context, index) => pages[index].page(context),
  ),
);

@Feichtmeier
Copy link
Member

ah very nice! Can also use this in musicpod xD currently doing some kung fu to count the element then wrapping it in column with divider -.-

@jpnurmi
Copy link
Member Author

jpnurmi commented Jul 24, 2023

It should work fine with multiple sections/dividers too 👍

@jpnurmi jpnurmi merged commit 01d0881 into ubuntu:main Jul 24, 2023
10 checks passed
@jpnurmi jpnurmi deleted the md-spacer branch July 24, 2023 16:29
@github-actions github-actions bot mentioned this pull request Jul 24, 2023
@Jupi007
Copy link
Member

Jupi007 commented Jul 24, 2023

Awesome! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants