-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rebuild RearchElement when its widget updates (#164)
Fixes #163
- Loading branch information
1 parent
aaf4f26
commit 211e918
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_rearch/flutter_rearch.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:rearch/rearch.dart'; | ||
|
||
void main() { | ||
testWidgets('RearchConsumer rebuilds when constructor params change (#163)', | ||
(tester) async { | ||
await tester.pumpWidget( | ||
const RearchBootstrapper( | ||
child: MaterialApp(home: Scaffold(body: ParentConsumer())), | ||
), | ||
); | ||
expect(find.text('0'), findsOneWidget); | ||
expect(find.text('1'), findsNothing); | ||
await tester.tap(find.byType(TextButton)); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('0'), findsNothing); | ||
expect(find.text('1'), findsOneWidget); | ||
}); | ||
} | ||
|
||
class ParentConsumer extends RearchConsumer { | ||
const ParentConsumer({super.key}); | ||
@override | ||
Widget build(BuildContext context, WidgetHandle use) { | ||
final value = use.data(0); | ||
return TextButton( | ||
onPressed: () => value.value++, | ||
child: ChildConsumer(value.value), | ||
); | ||
} | ||
} | ||
|
||
class ChildConsumer extends RearchConsumer { | ||
const ChildConsumer(this.i, {super.key}); | ||
final int i; | ||
@override | ||
Widget build(BuildContext context, WidgetHandle use) { | ||
return Text('$i'); | ||
} | ||
} |