Skip to content

Commit

Permalink
Migrated to NNBD (null-safety) 🎉 (#195)
Browse files Browse the repository at this point in the history
* Updated dependencies
* Minimum Dart SDK is 2.12.0-0
* Resolves #184
  • Loading branch information
SirusCodes committed Feb 22, 2021
1 parent 5bc6a0c commit e5c3b84
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 201 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.0.0

- Migrated to nnbd(null-safety)

## 3.1.2
- Fixed insecure links in readme.

Expand All @@ -11,7 +15,7 @@

## 3.0.2

- Fixed major bug [#168](https://github.com/aagarwal1012/Animated-Text-Kit/issues/168), introduced with version 3
- Fixed major bug [#168](https://github.com/aagarwal1012/Animated-Text-Kit/issues/168), introduced with version 3
- Updated the `example` app to show a _Tap Count_
- Optimized the `dispose` for `AnimatedTextKit`
- Added missing return type to `onNext` function signatures
Expand Down Expand Up @@ -147,7 +151,7 @@
- `displayFullTextOnTap` - If true, tapping the screen will stop current animated text, and display it fully.
- `stopPauseOnTap` - If true, tapping during a pause will stop it and start the next text animation.

- **Better control over Animated Texts:**
- **Better control over Animated Texts:**
Callbacks added:
- `onNext(int index, bool isLast)` - This callback will be called before the next text animation, after the previous ones pause.
- `onNextBeforePause(int index, bool isLast)` - This callback will be called before the next text animation, before the previous one's pause.
Expand Down
16 changes: 7 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ class _MyAppState extends State<MyApp> {
}

class MyHomePage extends StatefulWidget {
MyHomePage({
Key key,
}) : super(key: key);
MyHomePage({Key? key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
List<AnimatedTextExample> _examples;
late List<AnimatedTextExample> _examples;
int _index = 0;
int _tapCount = 0;

Expand Down Expand Up @@ -95,16 +93,16 @@ class _MyHomePageState extends State<MyHomePage> {

class AnimatedTextExample {
final String label;
final Color color;
final Color? color;
final Widget child;
const AnimatedTextExample({
@required this.label,
@required this.color,
@required this.child,
required this.label,
required this.color,
required this.child,
});
}

List<AnimatedTextExample> animatedTextExamples({VoidCallback onTap}) =>
List<AnimatedTextExample> animatedTextExamples({VoidCallback? onTap}) =>
<AnimatedTextExample>[
AnimatedTextExample(
label: 'Rotate',
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: example
description: An example app to show the use of Animation Text Kit.

environment:
sdk: ">=2.10.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.22.0"

dependencies:
Expand Down
48 changes: 19 additions & 29 deletions lib/src/animated_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ abstract class AnimatedText {
final Characters textCharacters;

AnimatedText({
@required this.text,
required this.text,
this.textAlign = TextAlign.start,
@required this.textStyle,
@required this.duration,
}) : assert(null != text),
assert(null != textAlign),
assert(null != textStyle),
assert(null != duration),
textCharacters = text.characters;
required this.textStyle,
required this.duration,
}) : textCharacters = text.characters;

/// Return the remaining Duration for the Animation (when applicable).
Duration get remaining => null;
Duration? get remaining => null;

/// Initialize the Animation.
void initAnimation(AnimationController controller);
Expand All @@ -58,7 +54,7 @@ abstract class AnimatedText {
Widget completeText() => textWidget(text);

/// Widget showing animated text, based on animation value(s).
Widget animatedBuilder(BuildContext context, Widget child);
Widget animatedBuilder(BuildContext context, Widget? child);
}

/// Base class for Animated Text widgets.
Expand All @@ -82,22 +78,22 @@ class AnimatedTextKit extends StatefulWidget {
final bool stopPauseOnTap;

/// Adds the onTap [VoidCallback] to the animated widget.
final VoidCallback onTap;
final VoidCallback? onTap;

/// Adds the onFinished [VoidCallback] to the animated widget.
///
/// This method will run only if [isRepeatingAnimation] is set to false.
final VoidCallback onFinished;
final VoidCallback? onFinished;

/// Adds the onNext callback to the animated widget.
///
/// Will be called right before the next text, after the pause parameter
final void Function(int, bool) onNext;
final void Function(int, bool)? onNext;

/// Adds the onNextBeforePause callback to the animated widget.
///
/// Will be called at the end of n-1 animation, before the pause parameter
final void Function(int, bool) onNextBeforePause;
final void Function(int, bool)? onNextBeforePause;

/// Set if the animation should not repeat by changing the value of it to false.
///
Expand All @@ -116,8 +112,8 @@ class AnimatedTextKit extends StatefulWidget {
final int totalRepeatCount;

const AnimatedTextKit({
Key key,
@required this.animatedTexts,
Key? key,
required this.animatedTexts,
this.pause = const Duration(milliseconds: 1000),
this.displayFullTextOnTap = false,
this.stopPauseOnTap = false,
Expand All @@ -128,14 +124,8 @@ class AnimatedTextKit extends StatefulWidget {
this.isRepeatingAnimation = true,
this.totalRepeatCount = 3,
this.repeatForever = false,
}) : assert(null != animatedTexts && animatedTexts.length > 0),
assert(null != pause),
assert(null != displayFullTextOnTap),
assert(null != stopPauseOnTap),
assert(null != isRepeatingAnimation),
assert(null != repeatForever),
assert(
!isRepeatingAnimation || null != totalRepeatCount || repeatForever),
}) : assert(animatedTexts.length > 0),
assert(!isRepeatingAnimation || totalRepeatCount > 0 || repeatForever),
assert(null == onFinished || !repeatForever),
super(key: key);

Expand All @@ -146,17 +136,17 @@ class AnimatedTextKit extends StatefulWidget {

class _AnimatedTextKitState extends State<AnimatedTextKit>
with TickerProviderStateMixin {
AnimationController _controller;
late AnimationController _controller;

AnimatedText _currentAnimatedText;
late AnimatedText _currentAnimatedText;

int _currentRepeatCount = 0;

int _index = 0;

bool _isCurrentlyPausing = false;

Timer _timer;
Timer? _timer;

@override
void initState() {
Expand Down Expand Up @@ -249,7 +239,7 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>
void _animationEndCallback(AnimationStatus state) {
if (state == AnimationStatus.completed) {
_setPause();
assert(null == _timer || !_timer.isActive);
assert(null == _timer || !_timer!.isActive);
_timer = Timer(widget.pause, _nextAnimation);
}
}
Expand All @@ -270,7 +260,7 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

_setPause();

assert(null == _timer || !_timer.isActive);
assert(null == _timer || !_timer!.isActive);
_timer = Timer(
Duration(
milliseconds: max(
Expand Down
41 changes: 23 additions & 18 deletions lib/src/colorize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,26 @@ class ColorizeAnimatedText extends AnimatedText {
ColorizeAnimatedText(
String text, {
TextAlign textAlign = TextAlign.start,
@required TextStyle textStyle,
required TextStyle textStyle,
this.speed = const Duration(milliseconds: 200),
@required this.colors,
required this.colors,
this.textDirection = TextDirection.ltr,
}) : assert(null != speed),
assert(null != colors && colors.length > 1),
}) : assert(colors.length > 1),
super(
text: text,
textAlign: textAlign,
textStyle: textStyle,
duration: speed * text.characters.length,
);

Animation<double> _colorShifter, _fadeIn, _fadeOut;
late Animation<double> _colorShifter, _fadeIn, _fadeOut;
// Copy of colors that may be reversed when RTL.
List<Color> _colors;
late List<Color> _colors;

@override
void initAnimation(AnimationController controller) {
final tuning = (300.0 * colors.length) *
(textStyle.fontSize / 24.0) *
(textStyle.fontSize! / 24.0) *
0.75 *
(textCharacters.length / 15.0);

Expand Down Expand Up @@ -93,15 +92,15 @@ class ColorizeAnimatedText extends AnimatedText {
);
return Text(
text,
style: textStyle?.merge(
style: textStyle.merge(
TextStyle(foreground: Paint()..shader = linearGradient),
),
textAlign: textAlign,
);
}

@override
Widget animatedBuilder(BuildContext context, Widget child) {
Widget animatedBuilder(BuildContext context, Widget? child) {
return Opacity(
opacity: _fadeIn.value != 1.0 ? _fadeIn.value : _fadeOut.value,
child: completeText(),
Expand All @@ -114,18 +113,18 @@ class ColorizeAnimatedText extends AnimatedText {
/// ![Colorize example](https://raw.githubusercontent.com/aagarwal1012/Animated-Text-Kit/master/display/colorize.gif)
class ColorizeAnimatedTextKit extends AnimatedTextKit {
ColorizeAnimatedTextKit({
Key key,
@required List<String> text,
Key? key,
required List<String> text,
TextAlign textAlign = TextAlign.start,
TextDirection textDirection = TextDirection.ltr,
TextStyle textStyle,
List<Color> colors,
required TextStyle textStyle,
required List<Color> colors,
Duration speed = const Duration(milliseconds: 200),
Duration pause = const Duration(milliseconds: 1000),
VoidCallback onTap,
void Function(int, bool) onNext,
void Function(int, bool) onNextBeforePause,
VoidCallback onFinished,
VoidCallback? onTap,
void Function(int, bool)? onNext,
void Function(int, bool)? onNextBeforePause,
VoidCallback? onFinished,
bool isRepeatingAnimation = true,
int totalRepeatCount = 3,
bool repeatForever = false,
Expand All @@ -134,7 +133,13 @@ class ColorizeAnimatedTextKit extends AnimatedTextKit {
}) : super(
key: key,
animatedTexts: _animatedTexts(
text, textAlign, textStyle, speed, colors, textDirection),
text,
textAlign,
textStyle,
speed,
colors,
textDirection,
),
pause: pause,
displayFullTextOnTap: displayFullTextOnTap,
stopPauseOnTap: stopPauseOnTap,
Expand Down
20 changes: 10 additions & 10 deletions lib/src/fade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FadeAnimatedText extends AnimatedText {
FadeAnimatedText(
String text, {
TextAlign textAlign = TextAlign.start,
@required TextStyle textStyle,
required TextStyle textStyle,
Duration duration = const Duration(milliseconds: 2000),
}) : super(
text: text,
Expand All @@ -17,7 +17,7 @@ class FadeAnimatedText extends AnimatedText {
duration: duration,
);

Animation<double> _fadeIn, _fadeOut;
late Animation<double> _fadeIn, _fadeOut;

@override
void initAnimation(AnimationController controller) {
Expand All @@ -40,7 +40,7 @@ class FadeAnimatedText extends AnimatedText {
Widget completeText() => SizedBox.shrink();

@override
Widget animatedBuilder(BuildContext context, Widget child) {
Widget animatedBuilder(BuildContext context, Widget? child) {
return Opacity(
opacity: _fadeIn.value != 1.0 ? _fadeIn.value : _fadeOut.value,
child: textWidget(text),
Expand All @@ -53,16 +53,16 @@ class FadeAnimatedText extends AnimatedText {
/// ![Fade example](https://raw.githubusercontent.com/aagarwal1012/Animated-Text-Kit/master/display/fade.gif)
class FadeAnimatedTextKit extends AnimatedTextKit {
FadeAnimatedTextKit({
Key key,
@required List<String> text,
Key? key,
required List<String> text,
TextAlign textAlign = TextAlign.start,
TextStyle textStyle,
required TextStyle textStyle,
Duration duration = const Duration(milliseconds: 2000),
Duration pause = const Duration(milliseconds: 500),
VoidCallback onTap,
void Function(int, bool) onNext,
void Function(int, bool) onNextBeforePause,
VoidCallback onFinished,
VoidCallback? onTap,
void Function(int, bool)? onNext,
void Function(int, bool)? onNextBeforePause,
VoidCallback? onFinished,
bool isRepeatingAnimation = true,
int totalRepeatCount = 3,
bool repeatForever = false,
Expand Down
Loading

0 comments on commit e5c3b84

Please sign in to comment.