Skip to content

Commit

Permalink
CompactLayout: expose extended property (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Sep 17, 2022
1 parent 6932b6c commit 95590d8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
26 changes: 23 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ class _HomeState extends State<Home> {
theme: context.watch<LightTheme>().value,
darkTheme: context.watch<DarkTheme>().value,
home: _compactMode
? YaruCompactLayout(
pageItems: [configItem] + examplePageItems.take(_amount).toList(),
)
? _CompactPage(configItem: configItem, amount: _amount)
: YaruMasterDetailPage(
leftPaneWidth: 280,
previousIconData: YaruIcons.go_previous,
Expand All @@ -111,6 +109,28 @@ class _HomeState extends State<Home> {
}
}

class _CompactPage extends StatelessWidget {
const _CompactPage({
Key? key,
required this.configItem,
required int amount,
}) : _amount = amount,
super(key: key);

final YaruPageItem configItem;
final int _amount;

@override
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;

return YaruCompactLayout(
extendNavigationRail: width > 1000,
pageItems: [configItem] + examplePageItems.take(_amount).toList(),
);
}
}

class TouchMouseStylusScrollBehavior extends MaterialScrollBehavior {
@override
Set<PointerDeviceKind> get dragDevices => {
Expand Down
8 changes: 8 additions & 0 deletions lib/src/pages/layouts/yaru_compact_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class YaruCompactLayout extends StatefulWidget {
this.showUnselectedLabels = true,
this.labelType = NavigationRailLabelType.none,
this.bottomNavigationBarType = BottomNavigationBarType.fixed,
this.extendNavigationRail = false,
}) : super(key: key);

/// The list of [YaruPageItem] has to be provided.
Expand All @@ -32,6 +33,10 @@ class YaruCompactLayout extends StatefulWidget {
/// Optionally control the click behavior of the [BottomNavigationBar]
final BottomNavigationBarType bottomNavigationBarType;

/// Defines if the labels are shown right to the icon
/// of the [NavigationRail] in the wide layout
final bool extendNavigationRail;

@override
State<YaruCompactLayout> createState() => _YaruCompactLayoutState();
}
Expand All @@ -57,6 +62,9 @@ class _YaruCompactLayoutState extends State<YaruCompactLayout> {
pageItems: widget.pageItems,
initialIndex: _index == -1 ? _previousIndex : _index,
onSelected: _setIndex,
extended: widget.labelType == NavigationRailLabelType.none
? widget.extendNavigationRail
: false,
)
: YaruNarrowLayout(
showSelectedLabels: widget.showSelectedLabels,
Expand Down
9 changes: 9 additions & 0 deletions lib/src/pages/layouts/yaru_wide_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ class YaruWideLayout extends StatefulWidget {
/// Optionally control the labels of the [NavigationRail]
final NavigationRailLabelType? labelType;

/// Defines if the labels are shown right to the icon
/// of the [NavigationRail]
final bool extended;

const YaruWideLayout({
Key? key,
required this.pageItems,
required this.initialIndex,
this.scrollController,
this.labelType = NavigationRailLabelType.selected,
this.extended = false,
required this.onSelected,
}) : super(key: key);

Expand Down Expand Up @@ -65,6 +70,10 @@ class _YaruWideLayoutState extends State<YaruWideLayout> {
BoxConstraints(minHeight: constraint.maxHeight),
child: IntrinsicHeight(
child: NavigationRail(
extended:
widget.labelType == NavigationRailLabelType.none
? widget.extended
: false,
unselectedIconTheme: IconThemeData(
color: unselectedTextColor,
),
Expand Down

0 comments on commit 95590d8

Please sign in to comment.