Skip to content

Commit

Permalink
Merge pull request #3 from erickzanardo/fix/state-remount
Browse files Browse the repository at this point in the history
fix: state remount
  • Loading branch information
erickzanardo authored Feb 7, 2023
2 parents 7ac7347 + b5a44f0 commit aa60cb2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.0.3

- fix: state remount

# 0.0.2

- feat: add ticker feature
Expand Down
7 changes: 7 additions & 0 deletions lib/src/phased.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ class _PhasedState<T> extends State<Phased<T>>
});
}

@override
void didUpdateWidget(Phased<T> old) {
super.didUpdateWidget(old);
old.state.removeListener(_update);
widget.state.addListener(_update);
}

@override
void dispose() {
_ticker?.dispose();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: phased
description: Simplified state management focused on animations
repository: https://github.com/erickzanardo/phased
version: 0.0.2
version: 0.0.3

environment:
sdk: '>=2.18.0 <3.0.0'
Expand Down
46 changes: 46 additions & 0 deletions test/src/phased_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,51 @@ void main() {

expect(find.text('B'), findsOneWidget);
});

testWidgets('attaches to a new state', (tester) async {
final key = GlobalKey();
final state = PhasedState(
values: [true, false],
autostart: false,
ticker: Duration(milliseconds: 1),
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: StatefulBuilder(
builder: (context, setState) {
return Column(
children: [
ElevatedButton(
child: Text('Rebuild'),
onPressed: () {
setState(() {});
},
),
Center(
child: Blink(
key: key,
state: state,
),
),
],
);
},
),
),
),
);

expect(find.text('A'), findsOneWidget);

await tester.tap(find.text('Rebuild'));
await tester.pump();

expect(find.text('B'), findsOneWidget);

await tester.pump();

expect(find.text('A'), findsOneWidget);
});
});
}

0 comments on commit aa60cb2

Please sign in to comment.