testableChildBuilder function

Widget testableChildBuilder (
  1. BuildContext context,
  2. Widget child
)

ChildWidgetBuilder that can be used to wrap child widgets with a Testable widget. This particular builder will only wrap the child if the child has a ValueKey set on it. In that case, the Testable will be given the a new ValueKey with the value from the child's key prefixed with value_key_.

Implementation

Widget testableChildBuilder(BuildContext context, Widget child) {
  String id;

  if (child.key != null && child.key is ValueKey) {
    ValueKey childKey = child.key;

    if (childKey.value is String) {
      id = 'value_key_${childKey.value}';
    }
  }

  return id == null
      ? child
      : Testable(
          id: id,
          child: child,
        );
}