Skip to content

Commit

Permalink
feat: Add BreadcrumbBar.chevronIconBuilder and `BreadcrumbBar.chevr…
Browse files Browse the repository at this point in the history
…onIconSize` (Fixes #1111)
  • Loading branch information
bdlukaa committed Sep 29, 2024
1 parent 23f32e8 commit 8f108bd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
## 4.9.3

- fix : The EditableComboBox is missing the part that applies the style to the TextBox, so add it.

## 4.9.2

- feat: `NavigationAppBar` `leading` widget is now a minimum of `kCompactNavigationPaneWidth` width instead of being fixed to this width ([#1103](https://github.com/bdlukaa/fluent_ui/pull/1103))
- feat: Add `TabView.stripBuilder` ([#1106](https://github.com/bdlukaa/fluent_ui/issues/1106))
- fix : The EditableComboBox is missing the part that applies the style to the TextBox, so add it.
- feat: Add `BreadcrumbBar.chevronIconBuilder` and `BreadcrumbBar.chevronIconSize` ([#1111](https://github.com/bdlukaa/fluent_ui/issues/1111))

## 4.9.1

Expand Down
57 changes: 43 additions & 14 deletions lib/src/controls/navigation/breadcrumb_bar.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/rendering.dart';

typedef ChevronIconBuilder<T> = Widget Function(
BuildContext context,
int index,
);

class BreadcrumbItem<T> {
/// The label of the item
///
Expand Down Expand Up @@ -80,12 +85,25 @@ class BreadcrumbBar<T> extends StatefulWidget {
/// Called when an item is pressed.
final ValueChanged<BreadcrumbItem<T>>? onItemPressed;

/// The builder for the chevron icon.
///
/// The [index] is the index of the item in the list. If the index is -1,
/// the chevron is attached to the overflow button.
final ChevronIconBuilder chevronIconBuilder;

/// The size of the chevron icon.
///
/// Defaults to 8.0
final double chevronIconSize;

/// Creates a breadcrumb bar.
const BreadcrumbBar({
super.key,
required this.items,
this.overflowButtonBuilder = _defaultOverflowButtonBuilder,
this.onItemPressed,
this.chevronIconBuilder = _defaultChevronBuilder,
this.chevronIconSize = 8.0,
});

/// The default overflow button builder.
Expand All @@ -111,6 +129,20 @@ class BreadcrumbBar<T> extends StatefulWidget {
);
}

static Widget _defaultChevronBuilder(BuildContext context, int index) {
final theme = FluentTheme.of(context);
final textDirection = Directionality.of(context);
return Padding(
padding: const EdgeInsetsDirectional.symmetric(horizontal: 6.0),
child: Icon(
textDirection == TextDirection.ltr
? FluentIcons.chevron_right
: FluentIcons.chevron_left,
color: theme.resources.textFillColorPrimary,
),
);
}

@override
State<BreadcrumbBar<T>> createState() => BreadcrumbBarState();
}
Expand Down Expand Up @@ -164,23 +196,11 @@ class BreadcrumbBarState<T> extends State<BreadcrumbBar<T>> {
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
assert(debugCheckHasDirectionality(context));
final theme = FluentTheme.of(context);
final textDirection = Directionality.of(context);

final isReversed = textDirection == TextDirection.rtl;
final items = isReversed ? widget.items.reversed.toList() : widget.items;

final chevron = Padding(
padding: const EdgeInsetsDirectional.symmetric(horizontal: 6.0),
child: Icon(
textDirection == TextDirection.ltr
? FluentIcons.chevron_right
: FluentIcons.chevron_left,
size: 8.0,
color: theme.resources.textFillColorPrimary,
),
);

return _BreadcrumbBar(
items: items,
textDirection: textDirection,
Expand All @@ -194,7 +214,10 @@ class BreadcrumbBarState<T> extends State<BreadcrumbBar<T>> {
controller: flyoutController,
child: widget.overflowButtonBuilder(context, showFlyout),
),
chevron,
IconTheme.merge(
data: IconThemeData(size: widget.chevronIconSize),
child: widget.chevronIconBuilder(context, -1),
),
]),
children: List.generate(items.length, (index) {
final item = items[index];
Expand Down Expand Up @@ -225,7 +248,13 @@ class BreadcrumbBarState<T> extends State<BreadcrumbBar<T>> {
final isLastItem = isReversed ? index == 0 : index == items.length - 1;
if (isLastItem) return label;

return Row(mainAxisSize: MainAxisSize.min, children: [label, chevron]);
return Row(mainAxisSize: MainAxisSize.min, children: [
label,
IconTheme.merge(
data: IconThemeData(size: widget.chevronIconSize),
child: widget.chevronIconBuilder(context, index),
),
]);
}),
);
}
Expand Down

0 comments on commit 8f108bd

Please sign in to comment.