Skip to content

Instantly share code, notes, and snippets.

@maks
Created February 18, 2020 00:00
Show Gist options
  • Select an option

  • Save maks/a0c73bbe103434300f93fd57dbdb6dc4 to your computer and use it in GitHub Desktop.

Select an option

Save maks/a0c73bbe103434300f93fd57dbdb6dc4 to your computer and use it in GitHub Desktop.
Flutter widget test "Container by Colour" finder
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
class ContainerByColorFinder extends MatchFinder {
ContainerByColorFinder(this.color, {bool skipOffstage = true})
: super(skipOffstage: skipOffstage);
final Color color;
@override
String get description => 'Container{color: "$color"}';
@override
bool matches(Element candidate) {
if (candidate.widget is Container) {
final Container containerWidget = candidate.widget as Container;
if (containerWidget.decoration is BoxDecoration) {
final BoxDecoration decoration =
containerWidget.decoration as BoxDecoration;
return decoration.color.value == color.value;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment