Skip to content

Commit

Permalink
Respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Osman authored and Osman committed Mar 15, 2024
1 parent f716ecc commit 497164a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 56 deletions.
6 changes: 3 additions & 3 deletions example/lib/pages/components/breadcrumbs_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class BreadCrumbsExample extends StatefulWidget {
}

class _BreadCrumbsExampleState extends State<BreadCrumbsExample> {
List<BreadCrumb> _children = [
BreadCrumb(
List<ZetaBreadCrumb> _children = [
ZetaBreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb " + 0.toString() + "Clicked");
Expand All @@ -39,7 +39,7 @@ class _BreadCrumbsExampleState extends State<BreadCrumbsExample> {
onPressed: () {
setState(() {
_children.add(
BreadCrumb(
ZetaBreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb clicked");
Expand Down
28 changes: 5 additions & 23 deletions example/widgetbook/pages/components/breadcrumbs_widgetbook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:widgetbook/widgetbook.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../test/test_components.dart';
import '../../utils/utils.dart';

Widget breadCrumbsUseCase(BuildContext context) => WidgetbookTestWidget(
widget: Center(
Expand All @@ -18,8 +19,8 @@ class BreadCrumbExample extends StatefulWidget {
}

class _BreadCrumbExampleState extends State<BreadCrumbExample> {
List<BreadCrumb> _children = [
BreadCrumb(
List<ZetaBreadCrumb> _children = [
ZetaBreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb " + 0.toString() + "Clicked");
Expand All @@ -37,26 +38,7 @@ class _BreadCrumbExampleState extends State<BreadCrumbExample> {
ZetaBreadCrumbs(
children: _children,
rounded: widget.c.knobs.boolean(label: 'Rounded'),
activeIcon: widget.c.knobs.list(
label: 'ActiveIcon',
options: [
ZetaIcons.star_round,
ZetaIcons.add_alert_round,
ZetaIcons.add_box_round,
ZetaIcons.barcode_round,
],
labelBuilder: (value) {
if (value == ZetaIcons.star_round)
return 'ZetaIcons.star_round';
if (value == ZetaIcons.add_alert_round)
return 'ZetaIcons.add_alert_round';
if (value == ZetaIcons.add_box_round)
return 'ZetaIcons.add_box_round';
if (value == ZetaIcons.barcode_round)
return 'ZetaIcons.barcode_round';
return '';
},
),
activeIcon: iconKnob(context),
),
SizedBox(
height: 50,
Expand All @@ -65,7 +47,7 @@ class _BreadCrumbExampleState extends State<BreadCrumbExample> {
onPressed: () {
setState(() {
_children.add(
BreadCrumb(
ZetaBreadCrumb(
label: 'Icon before with seperator',
onPressed: () {
print("Breadcrumb clicked");
Expand Down
88 changes: 58 additions & 30 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<BreadCrumb> children;
final List<ZetaBreadCrumb> 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<BreadCrumb>('children', children))
..add(IterableProperty<ZetaBreadCrumb>('children', children))
..add(DiagnosticsProperty<bool?>('rounded', rounded))
..add(DiagnosticsProperty<IconData?>('activeIcon', activeIcon));
}
}

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

@override
void initState() {
Expand All @@ -46,7 +46,6 @@ class _ZetaBreadCrumbsState extends State<ZetaBreadCrumbs> {
_children = [...widget.children];
}

// TODO: Optimize so we don't call set state each time. OldWidget stays the same as current widget
@override
void didUpdateWidget(ZetaBreadCrumbs oldWidget) {
if (widget.children.length != _children.length) {
Expand Down Expand Up @@ -86,8 +85,8 @@ class _ZetaBreadCrumbsState extends State<ZetaBreadCrumbs> {
}

///Creates breadcumb widget
BreadCrumb createBreadCrumb(BreadCrumb input, int index) {
return BreadCrumb(
ZetaBreadCrumb createBreadCrumb(ZetaBreadCrumb input, int index) {
return ZetaBreadCrumb(
label: input.label,
isSelected: _selectedIndex == index,
onPressed: () {
Expand All @@ -100,7 +99,7 @@ class _ZetaBreadCrumbsState extends State<ZetaBreadCrumbs> {
);
}

List<Widget> renderedChildren(List<BreadCrumb> children) {
List<Widget> renderedChildren(List<ZetaBreadCrumb> children) {
final List<Widget> returnList = [];
if (children.length > 3) {
returnList.add(createBreadCrumb(children.first, 0));
Expand Down Expand Up @@ -128,10 +127,10 @@ class _ZetaBreadCrumbsState extends State<ZetaBreadCrumbs> {
}
}

/// Class for untruncated [BreadCrumb].
class BreadCrumb extends StatelessWidget {
///Constructor for [BreadCrumb]
const BreadCrumb({
/// Class for untruncated [ZetaBreadCrumb].
class ZetaBreadCrumb extends StatefulWidget {
///Constructor for [ZetaBreadCrumb]
const ZetaBreadCrumb({
super.key,
required this.label,
this.icon,
Expand All @@ -140,47 +139,74 @@ class BreadCrumb extends StatelessWidget {
this.activeIcon,
});

/// [BreadCrumb] label.
/// [ZetaBreadCrumb] label.
final String label;

/// Selected icon.
final IconData? icon;

/// Is [BreadCrumb] selected.
/// Is [ZetaBreadCrumb] selected.
final bool isSelected;

/// Handles press for [BreadCrumb]
/// Handles press for [ZetaBreadCrumb]
final VoidCallback onPressed;

/// Active icon for [BreadCrumb]
/// Active icon for [ZetaBreadCrumb]
final IconData? activeIcon;

@override
State<ZetaBreadCrumb> createState() => _ZetaBreadCrumbState();

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(ObjectFlagProperty<VoidCallback>.has('onPressed', onPressed))
..add(StringProperty('label', label))
..add(DiagnosticsProperty<IconData?>('icon', icon))
..add(DiagnosticsProperty<bool>('isSelected', isSelected))
..add(DiagnosticsProperty<IconData?>('activeIcon', activeIcon));
}
}

class _ZetaBreadCrumbState extends State<ZetaBreadCrumb> {
final controller = MaterialStatesController();

@override
void initState() {
super.initState();
controller.addListener(() {
if (context.mounted && mounted) {
setState(() {});
}
});
}

@override
Widget build(BuildContext context) {
final controller = MaterialStatesController();
final colors = Zeta.of(context).colors;
return Material(
color: Colors.transparent,
child: InkWell(
statesController: controller,
onTap: onPressed,
onTap: widget.onPressed,
enableFeedback: false,
splashColor: Colors.transparent,
overlayColor: MaterialStateProperty.resolveWith((states) {
return Colors.transparent;
}),
child: Row(
children: [
if (isSelected)
if (widget.isSelected)
Icon(
activeIcon ?? ZetaIcons.star_round,
widget.activeIcon ?? ZetaIcons.star_round,
color: getColor(controller.value, colors),
),
const SizedBox(
width: ZetaSpacing.xs,
),
Text(
label,
widget.label,
style: TextStyle(color: getColor(controller.value, colors)),
),
],
Expand All @@ -192,21 +218,21 @@ class BreadCrumb extends StatelessWidget {
/// Get color of breadcrumb based on state.
Color getColor(Set<MaterialState> states, ZetaColors colors) {
if (states.contains(MaterialState.hovered)) {
return colors.blue.shade100;
return colors.blue;
}
if (isSelected) return colors.black;
if (widget.isSelected) return colors.black;
return colors.textSubtle;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(ObjectFlagProperty<VoidCallback>.has('onPressed', onPressed))
..add(StringProperty('label', label))
..add(DiagnosticsProperty<IconData?>('icon', icon))
..add(DiagnosticsProperty<bool>('isSelected', isSelected))
..add(DiagnosticsProperty<IconData?>('activeIcon', activeIcon));
properties.add(
DiagnosticsProperty<MaterialStatesController>(
'controller',
controller,
),
);
}
}

Expand Down Expand Up @@ -290,8 +316,10 @@ class _BreadCrumbsTruncatedState extends State<BreadCrumbsTruncated> {
minimumSize: MaterialStateProperty.all(Size.zero),
elevation: const MaterialStatePropertyAll(0),
),
child: const Icon(
ZetaIcons.more_horizontal_round,
child: Icon(
widget.rounded
? ZetaIcons.more_horizontal_round
: ZetaIcons.more_horizontal_sharp,
size: ZetaSpacing.x4,
)
.paddingHorizontal(ZetaSpacing.xs)
Expand Down

0 comments on commit 497164a

Please sign in to comment.