How do I run Flutter widget tests with shadows enabled?


I’d like to render some of my Flutter golden files with shadows. How can I accomplish that?

Shadows are disabled by default:


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.

Answered By – Iiro Krankka

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *