Skip to content

Commit

Permalink
Merge branch 'main' into search_field
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Jul 25, 2023
2 parents 1a7391d + dc4b20c commit 78beee0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
18 changes: 16 additions & 2 deletions lib/src/widgets/master_detail/yaru_master_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class YaruMasterDetailPage extends StatefulWidget {
this.emptyBuilder,
this.layoutDelegate =
const YaruMasterFixedPaneDelegate(paneWidth: _kDefaultPaneWidth),
this.breakpoint,
this.appBar,
this.appBarBuilder,
this.bottomBar,
Expand Down Expand Up @@ -93,6 +94,15 @@ class YaruMasterDetailPage extends StatefulWidget {
/// Controls the width and resizing capacity of the left pane.
final YaruMasterDetailPaneLayoutDelegate layoutDelegate;

/// The breakpoint at which `YaruMasterDetailPage` switches between portrait
/// and landscape layouts.
///
/// Set to `0` to force the landscape layout or `double.infinity` to force the
/// portrait layout regardless of the page size.
///
/// Defaults to [YaruMasterDetailThemeData.breakpoint].
final double? breakpoint;

/// An optional custom AppBar for the left pane.
///
/// See also:
Expand Down Expand Up @@ -201,10 +211,14 @@ class _YaruMasterDetailPageState extends State<YaruMasterDetailPage> {

@override
Widget build(BuildContext context) {
final breakpoint = widget.breakpoint ??
YaruMasterDetailTheme.of(context).breakpoint ??
YaruMasterDetailThemeData.fallback().breakpoint!;
return Scaffold(
body: widget.length == 0 || widget.controller?.length == 0
? widget.emptyBuilder?.call(context) ?? const SizedBox.shrink()
: _YaruMasterDetailLayoutBuilder(
breakpoint: breakpoint,
portrait: (context) => YaruPortraitLayout(
navigatorKey: _navigatorKey,
navigatorObservers: widget.navigatorObservers,
Expand Down Expand Up @@ -241,17 +255,17 @@ class _YaruMasterDetailPageState extends State<YaruMasterDetailPage> {

class _YaruMasterDetailLayoutBuilder extends StatelessWidget {
const _YaruMasterDetailLayoutBuilder({
required this.breakpoint,
required this.portrait,
required this.landscape,
});

final double breakpoint;
final WidgetBuilder portrait;
final WidgetBuilder landscape;

@override
Widget build(BuildContext context) {
final breakpoint = YaruMasterDetailTheme.of(context).breakpoint ??
YaruMasterDetailThemeData.fallback().breakpoint!;
return LayoutBuilder(
builder: (context, constraints) {
final orientation = constraints.maxWidth < breakpoint
Expand Down
47 changes: 32 additions & 15 deletions lib/src/widgets/master_detail/yaru_master_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,41 @@ class _YaruMasterListViewState extends State<YaruMasterListView> {
@override
Widget build(BuildContext context) {
final theme = YaruMasterDetailTheme.of(context);
return ListView.separated(
separatorBuilder: (_, __) => SizedBox(height: theme.tileSpacing ?? 0),
padding: theme.listPadding,
return CustomScrollView(
controller: _controller,
itemCount: widget.length,
itemBuilder: (context, index) => YaruMasterTileScope(
index: index,
selected: index == widget.selectedIndex,
onTap: () => widget.onTap(index),
child: Builder(
builder: (context) => widget.builder(
context,
index,
index == widget.selectedIndex,
widget.availableWidth,
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Padding(
padding: theme.listPadding ?? EdgeInsets.zero,
child: Column(
children: List.generate(
widget.length,
(index) => YaruMasterTileScope(
index: index,
selected: index == widget.selectedIndex,
onTap: () => widget.onTap(index),
child: Builder(
builder: (context) => widget.builder(
context,
index,
index == widget.selectedIndex,
widget.availableWidth,
),
),
),
).withSpacing(theme.tileSpacing ?? 0),
),
),
),
),
],
);
}
}

extension on List<Widget> {
List<Widget> withSpacing(double height) => expand((item) sync* {
yield SizedBox(height: height);
yield item;
}).skip(1).toList();
}

0 comments on commit 78beee0

Please sign in to comment.