From 6bfa3cf60b8d8f5ad68298e276a3384d9fc11907 Mon Sep 17 00:00:00 2001 From: Daniel Eshkeri Date: Mon, 18 Nov 2024 11:28:45 +0000 Subject: [PATCH] fix: breadcrumb select index --- .../pages/components/breadcrumb_example.dart | 111 +++--------------- lib/src/components/breadcrumb/breadcrumb.dart | 2 +- .../breadcrumb/breadcrumb_test.dart | 1 - 3 files changed, 20 insertions(+), 94 deletions(-) diff --git a/example/lib/pages/components/breadcrumb_example.dart b/example/lib/pages/components/breadcrumb_example.dart index 5bd82f19..948f0ceb 100644 --- a/example/lib/pages/components/breadcrumb_example.dart +++ b/example/lib/pages/components/breadcrumb_example.dart @@ -18,55 +18,14 @@ class _BreadcrumbExampleState extends State { 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: () {}), ]; } @@ -77,52 +36,20 @@ class _BreadcrumbExampleState extends State { 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), + ), + ), ), ), ); diff --git a/lib/src/components/breadcrumb/breadcrumb.dart b/lib/src/components/breadcrumb/breadcrumb.dart index cc76efd1..d914f750 100644 --- a/lib/src/components/breadcrumb/breadcrumb.dart +++ b/lib/src/components/breadcrumb/breadcrumb.dart @@ -124,7 +124,7 @@ class _ZetaBreadcrumbsState extends State { .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) { diff --git a/test/src/components/breadcrumb/breadcrumb_test.dart b/test/src/components/breadcrumb/breadcrumb_test.dart index 9fe86950..bff2fc5f 100644 --- a/test/src/components/breadcrumb/breadcrumb_test.dart +++ b/test/src/components/breadcrumb/breadcrumb_test.dart @@ -68,7 +68,6 @@ void main() { await tester.pumpWidget( TestApp( home: ZetaBreadcrumb( - maxItemsShown: maxItemsShown, children: children, ), ),