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

CompactLayout: expose extended property #205

Merged
merged 1 commit into from
Sep 17, 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
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