Skip to content

Commit

Permalink
added key to widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoumanDev committed Feb 25, 2025
1 parent 8bcb7dc commit 908e15d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/ensemble/lib/framework/ensemble_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ abstract class EnsembleWidgetState<W extends EnsembleWidget> extends State<W> {

Widget rtn = buildWidget(context);

// Add KeyedSubtree with ValueKey based on testId to make widget findable in tests using find.byKey()
if (widgetController.testId != null &&
widgetController.testId!.isNotEmpty) {
rtn = KeyedSubtree(
key: ValueKey(widgetController.testId!),
child: rtn,
);
}

if (widgetController.textDirection != null) {
rtn = Directionality(
textDirection: widgetController.textDirection!, child: rtn);
Expand Down
9 changes: 9 additions & 0 deletions modules/ensemble/lib/framework/widget/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ abstract class EWidgetState<W extends HasController>
if (widget.controller is WidgetController) {
WidgetController widgetController = widget.controller as WidgetController;

// Add KeyedSubtree with ValueKey based on testId to make widget findable in tests using find.byKey()
if (widgetController.testId != null &&
widgetController.testId!.isNotEmpty) {
rtn = KeyedSubtree(
key: ValueKey(widgetController.testId!),
child: rtn,
);
}

if (widgetController.textDirection != null) {
rtn = Directionality(
textDirection: widgetController.textDirection!, child: rtn);
Expand Down

0 comments on commit 908e15d

Please sign in to comment.