I'd like to render some of my Flutter golden files with shadows. How can I accomplish that?
Shadows are disabled by default: https://github.com/flutter/flutter/blob/master/packages/flutter_test/lib/src/binding.dart#L942
I'd like to render some of my Flutter golden files with shadows. How can I accomplish that?
Shadows are disabled by default: https://github.com/flutter/flutter/blob/master/packages/flutter_test/lib/src/binding.dart#L942
With the debugDisableShadows flag.
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('my golden test with shadows enabled', (tester) async {
// Enable shadows
debugDisableShadows = false;
await tester.pumpWidget(MyWidget());
await expectLater(find.byType(MyWidget), matchesGoldenFile('..'));
// Set the flag back to normal
debugDisableShadows = true;
});
}
Note that you have to toggle the flag back to normal inside the test case (and not setUp
/ tearDown
) - otherwise, it will fail.
This happens because this check is performed immediately after the body of testWidgets()
completes, but before the test case is considered finished. Which is also before tearDown()
is executed.