Created
February 18, 2020 00:00
-
-
Save maks/a0c73bbe103434300f93fd57dbdb6dc4 to your computer and use it in GitHub Desktop.
Flutter widget test "Container by Colour" finder
This file contains hidden or 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
| 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