Skip to content

Commit

Permalink
fix: breadcrumb select index
Browse files Browse the repository at this point in the history
  • Loading branch information
DE7924 committed Nov 18, 2024
1 parent bdcbe67 commit 6bfa3cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 94 deletions.
111 changes: 19 additions & 92 deletions example/lib/pages/components/breadcrumb_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,14 @@ class _BreadcrumbExampleState extends State<BreadcrumbExample> {
void initState() {
super.initState();
_children = [
ZetaBreadcrumbItem(
label: 'Breadcrumb',
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(
label: 'Item 1',
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(
label: 'Item 2',
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(
label: 'Item 3',
icon: ZetaIcons.star,
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(
label: 'Item 4',
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(
label: 'Item 5',
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(
label: 'Item 6',
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(
label: 'Item 7',
onPressed: () {
print("Breadcrumb clicked");
},
),
ZetaBreadcrumbItem(label: 'Breadcrumb', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 1', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 2', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 3', icon: ZetaIcons.star, onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 4', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 5', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 6', onPressed: () {}),
ZetaBreadcrumbItem(label: 'Item 7', onPressed: () {}),
];
}

Expand All @@ -77,52 +36,20 @@ class _BreadcrumbExampleState extends State<BreadcrumbExample> {
child: Center(
child: SingleChildScrollView(
child: SizedBox(
width: double.infinity,
child: Column(children: [
width: double.infinity,
child: Column(
children: [
ZetaBreadcrumb(children: _children.sublist(0, 1)),
SizedBox(
height: 50,
),
ZetaBreadcrumb(children: _children.sublist(0, 2)),
SizedBox(
height: 50,
),
ZetaBreadcrumb(children: _children.sublist(0, 3)),
SizedBox(
height: 50,
),
ZetaBreadcrumb(
children: _children.sublist(0, 4),
maxItemsShown: 3,
),
SizedBox(
height: 50,
),
ZetaBreadcrumb(
children: _children.sublist(0, 5),
maxItemsShown: 4,
),
SizedBox(
height: 50,
),
ZetaBreadcrumb(
children: _children.sublist(0, 6),
maxItemsShown: 3,
),
SizedBox(
height: 50,
),
ZetaBreadcrumb(
children: _children.sublist(0, 7),
),
SizedBox(
height: 50,
),
ZetaBreadcrumb(
children: _children,
maxItemsShown: 1,
),
])),
ZetaBreadcrumb(children: _children.sublist(0, 4), maxItemsShown: 3),
ZetaBreadcrumb(children: _children.sublist(0, 5), maxItemsShown: 5),
ZetaBreadcrumb(children: _children.sublist(0, 6), maxItemsShown: 3),
ZetaBreadcrumb(children: _children.sublist(0, 7)),
ZetaBreadcrumb(children: _children, maxItemsShown: 1),
].gap(50),
),
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/breadcrumb/breadcrumb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class _ZetaBreadcrumbsState extends State<ZetaBreadcrumb> {
.add(_TruncatedItem(semanticLabel: widget.moreSemanticLabel ?? 'View More', children: truncatedChildren));

for (final (index, element) in children.sublist(children.length - (widget.maxItemsShown - 1)).indexed) {
returnList.add(createBreadCrumb(element, index + children.length - (widget.maxItemsShown)));
returnList.add(createBreadCrumb(element, index + children.length - (widget.maxItemsShown) + 1));
}
} else {
for (final (index, element) in children.indexed) {
Expand Down
1 change: 0 additions & 1 deletion test/src/components/breadcrumb/breadcrumb_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ void main() {
await tester.pumpWidget(
TestApp(
home: ZetaBreadcrumb(
maxItemsShown: maxItemsShown,
children: children,
),
),
Expand Down

0 comments on commit 6bfa3cf

Please sign in to comment.