Skip to content

Commit

Permalink
change to have breadcrumb inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Osman authored and Osman committed Mar 13, 2024
1 parent 1ea85b2 commit f716ecc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
20 changes: 17 additions & 3 deletions example/lib/pages/components/breadcrumbs_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ class BreadCrumbsExample extends StatefulWidget {
}

class _BreadCrumbsExampleState extends State<BreadCrumbsExample> {
List<String> _children = [
'Icon before with seperator',
List<BreadCrumb> _children = [
BreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb " + 0.toString() + "Clicked");
},
),
];
int index = 1;

@override
Widget build(BuildContext context) {
Expand All @@ -32,7 +38,15 @@ class _BreadCrumbsExampleState extends State<BreadCrumbsExample> {
FilledButton(
onPressed: () {
setState(() {
_children.add('Icon before with seperator');
_children.add(
BreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb clicked");
},
),
);
index++;
});
},
child: Text("Add Breadcrumb"))
Expand Down
20 changes: 17 additions & 3 deletions example/widgetbook/pages/components/breadcrumbs_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ class BreadCrumbExample extends StatefulWidget {
}

class _BreadCrumbExampleState extends State<BreadCrumbExample> {
List<String> _children = [
'Icon before with seperator',
List<BreadCrumb> _children = [
BreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb " + 0.toString() + "Clicked");
},
),
];
int index = 1;

@override
Widget build(BuildContext _) {
Expand Down Expand Up @@ -58,7 +64,15 @@ class _BreadCrumbExampleState extends State<BreadCrumbExample> {
FilledButton(
onPressed: () {
setState(() {
_children.add('Icon before with seperator');
_children.add(
BreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb clicked");
},
),
);
index++;
});
},
child: Text("Add Breadcrumb"))
Expand Down
15 changes: 8 additions & 7 deletions lib/src/components/breadcrumbs/breadcrumbs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ZetaBreadCrumbs extends StatefulWidget {
});

/// Breadcrumb children
final List<String> children;
final List<BreadCrumb> children;

/// {@macro zeta-component-rounded}
final bool rounded;
Expand All @@ -29,15 +29,15 @@ class ZetaBreadCrumbs extends StatefulWidget {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(IterableProperty<String>('children', children))
..add(IterableProperty<BreadCrumb>('children', children))
..add(DiagnosticsProperty<bool?>('rounded', rounded))
..add(DiagnosticsProperty<IconData?>('activeIcon', activeIcon));
}
}

class _ZetaBreadCrumbsState extends State<ZetaBreadCrumbs> {
late int _selectedIndex;
late List<String> _children;
late List<BreadCrumb> _children;

@override
void initState() {
Expand Down Expand Up @@ -86,20 +86,21 @@ class _ZetaBreadCrumbsState extends State<ZetaBreadCrumbs> {
}

///Creates breadcumb widget
BreadCrumb createBreadCrumb(String label, int index) {
BreadCrumb createBreadCrumb(BreadCrumb input, int index) {
return BreadCrumb(
label: label,
label: input.label,
isSelected: _selectedIndex == index,
onPressed: () {
setState(() {
_selectedIndex = index;
});
input.onPressed.call();
},
activeIcon: widget.activeIcon,
);
}

List<Widget> renderedChildren(List<String> children) {
List<Widget> renderedChildren(List<BreadCrumb> children) {
final List<Widget> returnList = [];
if (children.length > 3) {
returnList.add(createBreadCrumb(children.first, 0));
Expand Down Expand Up @@ -134,7 +135,7 @@ class BreadCrumb extends StatelessWidget {
super.key,
required this.label,
this.icon,
required this.isSelected,
this.isSelected = false,
required this.onPressed,
this.activeIcon,
});
Expand Down

0 comments on commit f716ecc

Please sign in to comment.