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

YaruCompactLayout: Allow optional Widgets as Icons #143

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions example/lib/example_page_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ const _lorem =

final examplePageItems = <YaruPageItem>[
YaruPageItem(
titleBuilder: (context) => Text('YaruRow'),
iconData: YaruIcons.format_unordered_list,
builder: (_) => YaruPage(children: [RowList()]),
),
titleBuilder: (context) => Text('YaruRow'),
iconData: YaruIcons.format_unordered_list,
builder: (_) => YaruPage(children: [RowList()]),
itemWidget: SizedBox(
height: 20,
child: YaruCircularProgressIndicator(strokeWidth: 2),
)),
YaruPageItem(
titleBuilder: (context) => Text('YaruExtraOptionRow'),
iconData: YaruIcons.settings_filled,
Expand Down
10 changes: 7 additions & 3 deletions lib/src/yaru_narrow_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ class _YaruNarrowLayoutState extends State<YaruNarrowLayout> {
items: widget.pageItems
.map(
(pageItem) => BottomNavigationBarItem(
icon: Icon(pageItem.iconData),
activeIcon: pageItem.selectedIconData != null
? Icon(pageItem.selectedIconData)
icon: pageItem.itemWidget != null
? pageItem.itemWidget!
: Icon(pageItem.iconData),
activeIcon: pageItem.selectedItemWidget != null
? pageItem.selectedItemWidget!
: (pageItem.selectedIconData != null
? Icon(pageItem.selectedIconData)
: Icon(pageItem.iconData)),
label: convertWidgetToString(
pageItem.titleBuilder(context))),
)
Expand Down
4 changes: 4 additions & 0 deletions lib/src/yaru_page_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ class YaruPageItem {
required this.iconData,
this.selectedIconData,
this.searchMatches,
this.itemWidget,
this.selectedItemWidget,
});
final WidgetBuilder titleBuilder;
final WidgetBuilder builder;
final IconData iconData;
final Widget? itemWidget;
final Widget? selectedItemWidget;
final IconData? selectedIconData;
final bool Function(String value, BuildContext context)? searchMatches;
}
12 changes: 8 additions & 4 deletions lib/src/yaru_wide_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ class _YaruWideLayoutState extends State<YaruWideLayout> {
destinations: widget.pageItems
.map(
(pageItem) => NavigationRailDestination(
icon: Icon(pageItem.iconData),
icon: pageItem.itemWidget != null
? pageItem.itemWidget!
: Icon(pageItem.iconData),
selectedIcon:
pageItem.selectedIconData != null
? Icon(pageItem.selectedIconData)
: Icon(pageItem.iconData),
pageItem.selectedItemWidget != null
? pageItem.selectedItemWidget!
: (pageItem.selectedIconData != null
? Icon(pageItem.selectedIconData)
: Icon(pageItem.iconData)),
label: pageItem.titleBuilder(context),
),
)
Expand Down