Skip to content

Commit

Permalink
Replace isPlaying with isAnimating
Browse files Browse the repository at this point in the history
  • Loading branch information
n-bernat committed Aug 11, 2024
1 parent d5e29a2 commit d623205
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
10 changes: 5 additions & 5 deletions flutter_kanjivg/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'package:flutter_kanjivg/flutter_kanjivg.dart';

void main() {
return runApp(
MaterialApp(
home: const ExamplePage(),
const MaterialApp(
home: ExamplePage(),
),
);
}
Expand All @@ -20,7 +20,7 @@ class _ExamplePageState extends State<ExamplePage>
with TickerProviderStateMixin {
late final KanjiController controller = KanjiController(
vsync: this,
duration: const Duration(seconds: 5),
duration: const Duration(seconds: 3),
);

@override
Expand Down Expand Up @@ -52,7 +52,7 @@ class _ExamplePageState extends State<ExamplePage>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('flutter_kanjivg'),
title: const Text('flutter_kanjivg'),
),
body: Center(
child: Card(
Expand All @@ -68,7 +68,7 @@ class _ExamplePageState extends State<ExamplePage>
onPressed: controller.toggle,
child: ListenableBuilder(
listenable: controller,
builder: (context, child) => controller.isPlaying
builder: (context, child) => controller.isAnimating
? const Icon(Icons.pause)
: const Icon(Icons.play_arrow),
),
Expand Down
21 changes: 5 additions & 16 deletions flutter_kanjivg/lib/src/kanji_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,18 @@ class KanjiController extends AnimationController {
KanjiController({
required super.vsync,
super.duration = const Duration(seconds: 5),
}) : _isPlaying = false;
});

/// Currently loaded kanji character.
KvgData? get data => _data;
KvgData? _data;

/// Whether the drawing animation is currently playing.
bool get isPlaying => _isPlaying;
bool _isPlaying;

/// Toggle the current state.
@override
TickerFuture toggle({double? from}) {
if (isCompleted) {
reset();
} else if (_isPlaying) {
} else if (isAnimating) {
stop();
return TickerFuture.complete();
}
Expand All @@ -50,11 +46,8 @@ class KanjiController extends AnimationController {

@override
TickerFuture forward({double? from}) {
final future = super.forward(from: from);
_isPlaying = true;
notifyListeners();

return future;
return super.forward(from: from);
}

/// Draw the character to a specific stroke.
Expand Down Expand Up @@ -98,18 +91,14 @@ class KanjiController extends AnimationController {

@override
TickerFuture reverse({double? from}) {
final future = super.reverse(from: from);
_isPlaying = true;
notifyListeners();

return future;
return super.reverse(from: from);
}

@override
void stop({bool canceled = true}) {
_isPlaying = false;
notifyListeners();

super.stop(canceled: canceled);
return super.stop(canceled: canceled);
}
}

0 comments on commit d623205

Please sign in to comment.