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

Pass available width to YaruMasterDetailBuilder #708

Merged
merged 3 commits into from
Jun 18, 2023
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
2 changes: 1 addition & 1 deletion example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _MasterDetailPage extends StatelessWidget {
minPaneWidth: 175,
),
length: pageItems.length,
tileBuilder: (context, index, selected) => YaruMasterTile(
tileBuilder: (context, index, selected, availableWidth) => YaruMasterTile(
leading: pageItems[index].iconBuilder(context, selected),
title: buildTitle(context, pageItems[index]),
),
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/master_detail/yaru_landscape_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class _YaruLandscapeLayoutState extends State<YaruLandscapeLayout> {
selectedIndex: _selectedIndex,
onTap: _onTap,
builder: widget.tileBuilder,
availableWidth: _paneWidth!,
),
bottomNavigationBar: widget.bottomBar,
),
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/master_detail/yaru_master_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef YaruMasterDetailBuilder = Widget Function(
BuildContext context,
int index,
bool selected,
double availableWidth,
);

typedef YaruAppBarBuilder = PreferredSizeWidget? Function(BuildContext context);
Expand Down
10 changes: 8 additions & 2 deletions lib/src/widgets/master_detail/yaru_master_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class YaruMasterListView extends StatefulWidget {
required this.selectedIndex,
required this.builder,
required this.onTap,
required this.availableWidth,
});

final int length;
final YaruMasterDetailBuilder builder;
final int selectedIndex;
final ValueChanged<int> onTap;
final double availableWidth;

@override
State<YaruMasterListView> createState() => _YaruMasterListViewState();
Expand Down Expand Up @@ -44,8 +46,12 @@ class _YaruMasterListViewState extends State<YaruMasterListView> {
selected: index == widget.selectedIndex,
onTap: () => widget.onTap(index),
child: Builder(
builder: (context) =>
widget.builder(context, index, index == widget.selectedIndex),
builder: (context) => widget.builder(
context,
index,
index == widget.selectedIndex,
widget.availableWidth,
),
),
),
);
Expand Down
13 changes: 8 additions & 5 deletions lib/src/widgets/master_detail/yaru_portrait_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ class _YaruPortraitLayoutState extends State<YaruPortraitLayout> {
),
child: Scaffold(
appBar: widget.appBar,
body: YaruMasterListView(
length: widget.controller.length,
selectedIndex: _selectedIndex,
onTap: _onTap,
builder: widget.tileBuilder,
body: LayoutBuilder(
builder: (context, constraints) => YaruMasterListView(
length: widget.controller.length,
selectedIndex: _selectedIndex,
onTap: _onTap,
builder: widget.tileBuilder,
availableWidth: constraints.maxWidth,
),
),
bottomNavigationBar: widget.bottomBar,
),
Expand Down
4 changes: 2 additions & 2 deletions test/widgets/yaru_master_detail_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
),
length: 8,
appBar: AppBar(title: const Text('Master')),
tileBuilder: (context, index, selected) => YaruMasterTile(
tileBuilder: (context, index, selected, maxWidth) => YaruMasterTile(
leading: const Icon(YaruIcons.menu),
title: Text('Tile $index'),
),
Expand Down Expand Up @@ -65,7 +65,7 @@ void main() {
paneWidth: kYaruMasterDetailBreakpoint / 3,
),
appBar: AppBar(title: const Text('Master')),
tileBuilder: (context, index, selected) => YaruMasterTile(
tileBuilder: (context, index, selected, maxWidth) => YaruMasterTile(
leading: const Icon(YaruIcons.menu),
title: Text('Tile $index'),
),
Expand Down