-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a78aa8
commit 28c61c2
Showing
7 changed files
with
131 additions
and
126 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:yaru_widgets/yaru_widgets.dart'; | ||
|
||
/// A responsive layout switching between [YaruWideLayout] | ||
/// and [YaruNarrowLayout] depening on the screen width. | ||
class YaruCompactLayout extends StatefulWidget { | ||
const YaruCompactLayout({ | ||
Key? key, | ||
required this.pageItems, | ||
this.narrowLayoutMaxWidth = 600, | ||
}) : super(key: key); | ||
|
||
/// The list of [YaruPageItem] has to be provided. | ||
final List<YaruPageItem> pageItems; | ||
|
||
/// The max width after the layout switches to the [YaruWideLayout], defaults to 600. | ||
final double narrowLayoutMaxWidth; | ||
|
||
@override | ||
State<YaruCompactLayout> createState() => _YaruCompactLayoutState(); | ||
} | ||
|
||
class _YaruCompactLayoutState extends State<YaruCompactLayout> { | ||
var _index = -1; | ||
var _previousIndex = 0; | ||
|
||
void _setIndex(int index) { | ||
_previousIndex = _index; | ||
_index = index; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SafeArea( | ||
child: Scaffold( | ||
body: LayoutBuilder( | ||
builder: (context, constraints) => | ||
constraints.maxWidth > widget.narrowLayoutMaxWidth | ||
? YaruWideLayout( | ||
labelType: NavigationRailLabelType.none, | ||
pageItems: widget.pageItems, | ||
initialIndex: _index == -1 ? _previousIndex : _index, | ||
onSelected: _setIndex, | ||
) | ||
: YaruNarrowLayout( | ||
showSelectedLabels: false, | ||
pageItems: widget.pageItems, | ||
initialIndex: _index == -1 ? _previousIndex : _index, | ||
onSelected: _setIndex, | ||
)), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters