Skip to content

Commit

Permalink
chore: Updating changelog and minor improvement in the icon button lo…
Browse files Browse the repository at this point in the history
…gic + tests (#106)
  • Loading branch information
erickzanardo authored Dec 19, 2023
1 parent 58a2a56 commit 7d7a9bd
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- feat: add `NesIcons.owl`
- feat: add `NesIconBadge`
- feat: add `NesIcons.letter`
- feat: adding arrow direction to `NesTooltip`
- fix: Icon button disabled property

# 0.10.0
- feat: add `NesIcons.user`
Expand Down
6 changes: 5 additions & 1 deletion example/lib/gallery/sections/icon_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ class _IconEntry extends StatelessWidget {
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8),
child: NesIconButton(icon: data, onPress: () {}, disabled: disabled, ),
child: NesIconButton(
icon: data,
onPress: () {},
disabled: disabled,
),
);
}
}
5 changes: 3 additions & 2 deletions lib/src/widgets/nes_icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class NesIconButton extends StatelessWidget {
final bool? disabled;

bool _isDisabled() =>
(disabled ?? false) ||
onPress == null && onPressStart == null && onPressEnd == null;

@override
Expand All @@ -53,9 +54,9 @@ class NesIconButton extends StatelessWidget {
onPress: onPress,
onPressStart: onPressStart,
onPressEnd: onPressEnd,
disabled: disabled ?? false || _isDisabled(),
disabled: _isDisabled(),
child: Opacity(
opacity: (disabled ?? false || _isDisabled()) ? .2 : 1.0,
opacity: _isDisabled() ? .2 : 1.0,
child: NesIcon(
iconData: icon,
size: size,
Expand Down
100 changes: 100 additions & 0 deletions test/src/widgets/nes_icon_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,105 @@ void main() {

expect(calls, equals(1));
});

testWidgets('is disabled when there is no listener', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: flutterNesTheme(),
home: Scaffold(
body: NesIconButton(
icon: NesIcons.add,
),
),
),
);

final nesPressable = tester.widget<NesPressable>(
find.byType(NesPressable),
);
expect(nesPressable.disabled, isTrue);
});

testWidgets('is not disabled when there is is a onPress', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: flutterNesTheme(),
home: Scaffold(
body: NesIconButton(
onPress: () {},
icon: NesIcons.add,
),
),
),
);

final nesPressable = tester.widget<NesPressable>(
find.byType(NesPressable),
);
expect(nesPressable.disabled, isFalse);
});

testWidgets(
'is not disabled when there is is a onPressStart',
(tester) async {
await tester.pumpWidget(
MaterialApp(
theme: flutterNesTheme(),
home: Scaffold(
body: NesIconButton(
onPressStart: () {},
icon: NesIcons.add,
),
),
),
);

final nesPressable = tester.widget<NesPressable>(
find.byType(NesPressable),
);
expect(nesPressable.disabled, isFalse);
},
);

testWidgets('is not disabled when there is is a onPressEnd',
(tester) async {
await tester.pumpWidget(
MaterialApp(
theme: flutterNesTheme(),
home: Scaffold(
body: NesIconButton(
onPressEnd: () {},
icon: NesIcons.add,
),
),
),
);

final nesPressable = tester.widget<NesPressable>(
find.byType(NesPressable),
);
expect(nesPressable.disabled, isFalse);
});

testWidgets('is disabled when there is is a listener but disabled = true',
(tester) async {
await tester.pumpWidget(
MaterialApp(
theme: flutterNesTheme(),
home: Scaffold(
body: NesIconButton(
onPressEnd: () {},
disabled: true,
icon: NesIcons.add,
),
),
),
);

final nesPressable = tester.widget<NesPressable>(
find.byType(NesPressable),
);
expect(nesPressable.disabled, isTrue);
});
});
}

0 comments on commit 7d7a9bd

Please sign in to comment.