forked from psk907/fluttermoji
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add reset button #18
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# AvatarMakerResetWidget | ||
|
||
![AvatarMakerResetWidget](https://github.com/RoadTripMoustache/avatar_maker/assets/36586573/ef052b05-1b23-4f77-8a47-1d08fc734958) | ||
|
||
Renders a reset button by default OR can be used as a [InkWell] wrapper for the [child] widget. It resets the avatar to the last avatar saved state. | ||
|
||
Additional callbacks may be triggered by passing a Function to [onTap]. | ||
|
||
## Parameters | ||
- [theme] : AvatarMakerThemeData - Pass in your `theme` to customize the appearance of the default reset button. | ||
- [onTap] : Function? - Additional callbacks to be triggered on tapping the widget after the reset operation is executed. | ||
- [child] : Widget? - A widget to render as the child of a [InkWell]. If [null], then a default reset button is shown to the user. | ||
- [splashFactory] : InteractiveInkFeatureFactory? - Defines the appearance of the splash. | ||
- [splashColor] : Color? - The splash color of the ink response. | ||
- [radius] : double? - The radius of the ink splash. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import "package:flutter/material.dart"; | ||
import "package:avatar_maker/src/core/controllers/avatar_maker_controller.dart"; | ||
import "package:avatar_maker/src/core/models/theme_data.dart"; | ||
import "package:get/get.dart"; | ||
|
||
/// Renders a reset button by default OR can be used as a [InkWell] | ||
/// wrapper for the [child] widget. | ||
/// It resets the avatar to the last avatar saved state. | ||
/// | ||
/// Additional callbacks may be triggered by passing a | ||
/// Function to [onTap]. | ||
class AvatarMakerResetWidget extends StatelessWidget { | ||
/// Pass in your `theme` to customize the appearance of the default | ||
/// reset button. | ||
final AvatarMakerThemeData theme; | ||
|
||
/// Additional callbacks to be triggered on tapping the widget | ||
/// after the reset operation is executed. | ||
/// ******* | ||
/// Example: \ | ||
/// You may pass a function that triggers a snackbar saying "Reset done!" on | ||
/// the screen. | ||
final VoidCallback? onTap; | ||
|
||
/// A widget to render as the child of a [InkWell]. | ||
/// | ||
/// If [null], then a default reset button is shown to the user. | ||
final Widget? child; | ||
|
||
/// Find an instance of the [AvatarMakerController] to use | ||
/// | ||
/// Note: This expects the controller to be added to `Get` | ||
/// previously during runtime. | ||
final avatarMakerController = Get.find<AvatarMakerController>(); | ||
|
||
/// Defines the appearance of the splash. | ||
final InteractiveInkFeatureFactory? splashFactory; | ||
|
||
/// The splash color of the ink response. | ||
final Color? splashColor; | ||
|
||
final double? radius; | ||
|
||
AvatarMakerResetWidget({ | ||
Key? key, | ||
AvatarMakerThemeData? theme, | ||
this.onTap, | ||
this.child, | ||
this.splashFactory, | ||
this.splashColor, | ||
this.radius, | ||
}) : theme = theme ?? AvatarMakerThemeData.defaultTheme, | ||
super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return InkWell( | ||
onTap: () async { | ||
avatarMakerController.restoreState(); | ||
if (onTap != null) onTap!(); | ||
}, | ||
splashFactory: splashFactory, | ||
radius: radius, | ||
splashColor: splashColor, | ||
child: child == null | ||
? Icon( | ||
Icons.replay, | ||
color: theme.iconColor, | ||
) | ||
: child, | ||
); | ||
} | ||
} |
139 changes: 139 additions & 0 deletions
139
test/src/customizer/avatar_maker_reset_widget_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import "package:avatar_maker/avatar_maker.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_test/flutter_test.dart"; | ||
import "package:get/get.dart"; | ||
import "package:mockito/annotations.dart"; | ||
import "package:mockito/mockito.dart"; | ||
|
||
import "../../helpers.dart"; | ||
@GenerateNiceMocks( | ||
[MockSpec<AvatarMakerController>(), MockSpec<InternalFinalCallback>()]) | ||
import "avatar_maker_reset_widget_test.mocks.dart"; | ||
|
||
final avatarMakerControllerMock = MockAvatarMakerController(); | ||
final internalFinalCallbackMock = MockInternalFinalCallback(); | ||
|
||
void main() { | ||
setUpAll(() async { | ||
when(avatarMakerControllerMock.onStart) | ||
.thenAnswer((_) => internalFinalCallbackMock); | ||
when(avatarMakerControllerMock.onDelete) | ||
.thenAnswer((_) => internalFinalCallbackMock); | ||
when(avatarMakerControllerMock.restoreState()).thenAnswer((_) => null); | ||
|
||
Get.put<AvatarMakerController>(avatarMakerControllerMock); | ||
}); | ||
|
||
tearDownAll(() async { | ||
Get.delete<AvatarMakerController>(); | ||
}); | ||
|
||
group("AvatarMakerResetWidget", () { | ||
group("UI", () { | ||
testWidgets("Default", (WidgetTester tester) async { | ||
await tester.pumpMaterialApp(AvatarMakerResetWidget()); | ||
|
||
final inkWellConditions = isA<InkWell>() | ||
.having((i) => i.radius, "Check radius", null) | ||
.having((i) => i.splashFactory, "Check splashFactory", null) | ||
.having((i) => i.splashColor, "Check splashColor", null); | ||
final inkwell = find.byType(InkWell); | ||
expect(inkwell, findsOneWidget); | ||
expect(inkwell.evaluate().first.widget, inkWellConditions); | ||
|
||
final iconConditions = isA<Icon>() | ||
.having((i) => i.icon, "Check save icon", Icons.replay) | ||
.having((i) => i.color, "Check save icon color", | ||
AvatarMakerThemeData.defaultTheme.iconColor); | ||
final icon = find.byType(Icon); | ||
expect(icon, findsOneWidget); | ||
expect(icon.evaluate().first.widget, iconConditions); | ||
|
||
verifyNever(avatarMakerControllerMock.restoreState()); | ||
}); | ||
testWidgets("With radius", (WidgetTester tester) async { | ||
final double radius = 12.9; | ||
await tester.pumpMaterialApp(AvatarMakerResetWidget( | ||
radius: radius, | ||
)); | ||
|
||
final inkWellConditions = isA<InkWell>() | ||
.having((i) => i.radius, "Check radius", radius) | ||
.having((i) => i.splashFactory, "Check splashFactory", null) | ||
.having((i) => i.splashColor, "Check splashColor", null); | ||
final inkwell = find.byType(InkWell); | ||
expect(inkwell, findsOneWidget); | ||
expect(inkwell.evaluate().first.widget, inkWellConditions); | ||
|
||
final iconConditions = isA<Icon>() | ||
.having((i) => i.icon, "Check save icon", Icons.replay) | ||
.having((i) => i.color, "Check save icon color", | ||
AvatarMakerThemeData.defaultTheme.iconColor); | ||
final icon = find.byType(Icon); | ||
expect(icon, findsOneWidget); | ||
expect(icon.evaluate().first.widget, iconConditions); | ||
|
||
verifyNever(avatarMakerControllerMock.restoreState()); | ||
}); | ||
testWidgets("With splashColor", (WidgetTester tester) async { | ||
final Color splashColor = Colors.green; | ||
await tester.pumpMaterialApp(AvatarMakerResetWidget( | ||
splashColor: splashColor, | ||
)); | ||
|
||
final inkWellConditions = isA<InkWell>() | ||
.having((i) => i.radius, "Check radius", null) | ||
.having((i) => i.splashFactory, "Check splashFactory", null) | ||
.having((i) => i.splashColor, "Check splashColor", splashColor); | ||
final inkwell = find.byType(InkWell); | ||
expect(inkwell, findsOneWidget); | ||
expect(inkwell.evaluate().first.widget, inkWellConditions); | ||
|
||
final iconConditions = isA<Icon>() | ||
.having((i) => i.icon, "Check save icon", Icons.replay) | ||
.having((i) => i.color, "Check save icon color", | ||
AvatarMakerThemeData.defaultTheme.iconColor); | ||
final icon = find.byType(Icon); | ||
expect(icon, findsOneWidget); | ||
expect(icon.evaluate().first.widget, iconConditions); | ||
|
||
verifyNever(avatarMakerControllerMock.restoreState()); | ||
}); | ||
testWidgets("With custom theme", (WidgetTester tester) async { | ||
await tester.pumpMaterialApp(AvatarMakerResetWidget( | ||
theme: AvatarMakerThemeData( | ||
iconColor: Colors.pink, | ||
), | ||
)); | ||
|
||
final inkWellConditions = isA<InkWell>() | ||
.having((i) => i.radius, "Check radius", null) | ||
.having((i) => i.splashFactory, "Check splashFactory", null) | ||
.having((i) => i.splashColor, "Check splashColor", null); | ||
final inkwell = find.byType(InkWell); | ||
expect(inkwell, findsOneWidget); | ||
expect(inkwell.evaluate().first.widget, inkWellConditions); | ||
|
||
final iconConditions = isA<Icon>() | ||
.having((i) => i.icon, "Check save icon", Icons.replay) | ||
.having((i) => i.color, "Check save icon color", Colors.pink); | ||
final icon = find.byType(Icon); | ||
expect(icon, findsOneWidget); | ||
expect(icon.evaluate().first.widget, iconConditions); | ||
|
||
verifyNever(avatarMakerControllerMock.restoreState()); | ||
}); | ||
}); | ||
group("On tap InkWell", () { | ||
testWidgets("Default", (WidgetTester tester) async { | ||
await tester.pumpMaterialApp(AvatarMakerResetWidget()); | ||
|
||
final inkwell = find.byType(InkWell); | ||
expect(inkwell, findsOneWidget); | ||
await tester.tap(inkwell); | ||
|
||
verify(avatarMakerControllerMock.restoreState()).called(1); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more of a suggestion, depending on wether we use the same lint rules as Kana to kanji the linter will ask for it