diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b7c5b4..c840247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 0.12.0 - feat: adding `NesBlinker`. + - fix: `NesRunningText` would not update its text. # 0.11.0 - feat: add ability to customize `NesContainer`s pixel sizes. diff --git a/lib/src/widgets/nes_running_text.dart b/lib/src/widgets/nes_running_text.dart index ecbe363..8adb36a 100644 --- a/lib/src/widgets/nes_running_text.dart +++ b/lib/src/widgets/nes_running_text.dart @@ -69,6 +69,17 @@ class _NesRunningTextState extends State _controller.stop(); } } + + if (widget.text != oldWidget.text) { + _characters + ..clear() + ..addAll(widget.text.split('')); + _currentChar = 0; + + if (widget.running) { + _controller.forward(from: 0); + } + } } void _nextWord() { diff --git a/test/src/widgets/nes_running_text_test.dart b/test/src/widgets/nes_running_text_test.dart index 900eee9..b813f0b 100644 --- a/test/src/widgets/nes_running_text_test.dart +++ b/test/src/widgets/nes_running_text_test.dart @@ -86,5 +86,36 @@ void main() { await tester.pumpAndSettle(); expect(find.text('The Child'), findsOneWidget); }); + + testWidgets('plays the new text when received a new one', (tester) async { + var text = 'The Child'; + await tester.pumpWidget( + MaterialApp( + theme: flutterNesTheme(), + home: StatefulBuilder( + builder: (context, setState) { + return Column( + children: [ + NesRunningText( + text: text, + ), + ElevatedButton( + onPressed: () => setState(() => text = 'The Mandalorian'), + child: const Text('Start'), + ), + ], + ); + }, + ), + ), + ); + + await tester.pumpAndSettle(); + expect(find.text('The Child'), findsOneWidget); + + await tester.tap(find.byType(ElevatedButton)); + await tester.pumpAndSettle(); + expect(find.text('The Mandalorian'), findsOneWidget); + }); }); }