Skip to content

Commit

Permalink
refactor: follow linting rules by Lint package (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
YDA93 committed Apr 24, 2022
1 parent e3378bb commit c5740f9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 116 deletions.
58 changes: 6 additions & 52 deletions example/pubspec.yaml
@@ -1,75 +1,29 @@
name: example
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1
publish_to: "none"

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
avatar_glow:
path: ../

cupertino_icons: ^1.0.2
flutter:
sdk: flutter

dev_dependencies:
flutter_test:
sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
assets:
- assets/images/avatar.png
- assets/images/flutter.png
- assets/images/love.png
- assets/images/dart.png

# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages
113 changes: 55 additions & 58 deletions lib/avatar_glow.dart
Expand Up @@ -38,36 +38,36 @@ class AvatarGlow extends StatefulWidget {

class _AvatarGlowState extends State<AvatarGlow>
with SingleTickerProviderStateMixin {
late final controller = AnimationController(
late final _controller = AnimationController(
duration: widget.duration,
vsync: this,
);
late final _curve = CurvedAnimation(
parent: controller,
parent: _controller,
curve: widget.curve,
);
late final Animation<double> _smallDiscAnimation = Tween(
late final _smallDiscAnimation = Tween(
begin: (widget.endRadius * 2) / 6,
end: (widget.endRadius * 2) * (3 / 4),
).animate(_curve);
late final Animation<double> _bigDiscAnimation = Tween(
late final _bigDiscAnimation = Tween(
begin: 0.0,
end: (widget.endRadius * 2),
end: widget.endRadius * 2,
).animate(_curve);
late final Animation<double> _alphaAnimation = Tween(
late final _alphaAnimation = Tween(
begin: 0.30,
end: 0.0,
).animate(controller);
).animate(_controller);

late void Function(AnimationStatus status) _statusListener = (_) async {
if (controller.status == AnimationStatus.completed) {
Future<void> _statusListener(AnimationStatus status) async {
if (_controller.status == AnimationStatus.completed) {
await Future.delayed(widget.repeatPauseDuration);
if (mounted && widget.repeat && widget.animate) {
controller.reset();
controller.forward();
_controller.reset();
_controller.forward();
}
}
};
}

@override
void initState() {
Expand All @@ -89,78 +89,75 @@ class _AvatarGlowState extends State<AvatarGlow>
super.didUpdateWidget(oldWidget);
}

void _startAnimation() async {
controller.addStatusListener(_statusListener);
Future<void> _startAnimation() async {
_controller.addStatusListener(_statusListener);
if (widget.startDelay != null) {
await Future.delayed(widget.startDelay!);
}
if (mounted) {
controller.reset();
controller.forward();
_controller.reset();
_controller.forward();
}
}

void _stopAnimation() async {
controller.removeStatusListener(_statusListener);
Future<void> _stopAnimation() async {
_controller.removeStatusListener(_statusListener);
}

@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _alphaAnimation,
child: widget.child,
builder: (context, widgetChild) {
builder: (_, widgetChild) {
final decoration = BoxDecoration(
shape: widget.shape,
// If the user picks a curve that goes below 0 or above 1
// this opacity will have unexpected effects without clamping
color: widget.glowColor.withOpacity(
_alphaAnimation.value.clamp(
0.0,
1.0,
),
_alphaAnimation.value.clamp(0.0, 1.0),
),
);
return Container(
return SizedBox(
height: widget.endRadius * 2,
width: widget.endRadius * 2,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
widget.animate ?
AnimatedBuilder(
animation: _bigDiscAnimation,
builder: (context, widget) {
// If the user picks a curve that goes below 0,
// this will throw without clamping
final num size = _bigDiscAnimation.value.clamp(
0.0,
double.infinity,
);
return Container(
height: size as double?,
width: size as double?,
decoration: decoration,
);
},
) : const SizedBox(height: 0.0, width: 0.0),
widget.animate && widget.showTwoGlows
? AnimatedBuilder(
animation: _smallDiscAnimation,
builder: (context, widget) {
final num size = _smallDiscAnimation.value.clamp(
0.0,
double.infinity,
);
if (widget.animate)
AnimatedBuilder(
animation: _bigDiscAnimation,
builder: (_, __) {
// If the user picks a curve that goes below 0,
// this will throw without clamping
final _size =
_bigDiscAnimation.value.clamp(0.0, double.infinity);

return Container(
height: _size,
width: _size,
decoration: decoration,
);
},
)
else
const SizedBox(height: 0.0, width: 0.0),
if (widget.animate && widget.showTwoGlows)
AnimatedBuilder(
animation: _smallDiscAnimation,
builder: (_, __) {
final _size =
_smallDiscAnimation.value.clamp(0.0, double.infinity);

return Container(
height: size as double?,
width: size as double?,
decoration: decoration,
);
},
)
: const SizedBox(height: 0.0, width: 0.0),
return Container(
height: _size,
width: _size,
decoration: decoration,
);
},
)
else
const SizedBox(height: 0.0, width: 0.0),
widgetChild!,
],
),
Expand All @@ -171,7 +168,7 @@ class _AvatarGlowState extends State<AvatarGlow>

@override
void dispose() {
controller.dispose();
_controller.dispose();
super.dispose();
}
}
19 changes: 13 additions & 6 deletions pubspec.lock
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.1"
version: "2.8.2"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
charcode:
dependency: transitive
description:
Expand Down Expand Up @@ -66,7 +66,14 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -127,7 +134,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.2"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -141,6 +148,6 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"

0 comments on commit c5740f9

Please sign in to comment.