forked from psk907/fluttermoji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatar_maker_reset_widget.dart
73 lines (64 loc) · 2.13 KB
/
avatar_maker_reset_widget.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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,
);
}
}