Repository: flutter
Issue: [flutter_svg] SvgPicture.asset test fails when debugDumpApp is used
Labels: package,p: flutter_svg

_Imported from https://github.com/dnfield/flutter_svg/issues/324_

Original report by @pszklarska on Apr 2, 2020

I'm trying to write tests for the widgets that use SvgPicture. The following test can be run successfully:
```
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('svg picture test', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: SvgPicture.asset(
        'images/icon_percent.svg',
      ),
    ));

    expect(find.byType(SvgPicture), findsOneWidget);
  });
}
```

However, when I add `debugDumpApp` method to print current widgets' tree, test fails:

```
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('svg picture test', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: SvgPicture.asset(
        'images/icon_percent.svg',
      ),
    ));

    debugDumpApp();

    expect(find.byType(SvgPicture), findsOneWidget);
  });
}
```

The exception stack trace is: 

```
AutomatedTestWidgetsFlutterBinding - CHECKED MODE
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following assertion was thrown running a test:
type 'PictureStream' is not a subtype of type 'Diagnosticable'

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

When the exception was thrown, this was the stack:
#0      DiagnosticableMixin.toDiagnosticsNode (package:flutter/src/foundation/diagnostics.dart:3113:14)
#1      DiagnosticableMixin.toString.<anonymous closure> (package:flutter/src/foundation/diagnostics.dart:3095:20)
#2      DiagnosticableMixin.toString (package:flutter/src/foundation/diagnostics.dart:3097:6)
#3      DiagnosticsProperty.valueToString (package:flutter/src/foundation/diagnostics.dart:2698:61)
#4      DiagnosticsProperty.toDescription (package:flutter/src/foundation/diagnostics.dart:2712:21)
#5      TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1170:31)
#6      TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1280:39)
#7      DiagnosticsNode.toStringDeep (package:flutter/src/foundation/diagnostics.dart:1709:7)
#8      DiagnosticsNode.toString (package:flutter/src/foundation/diagnostics.dart:1632:14)
#9      DiagnosticableMixin.toString.<anonymous closure> (package:flutter/src/foundation/diagnostics.dart:3095:78)
#10     DiagnosticableMixin.toString (package:flutter/src/foundation/diagnostics.dart:3097:6)
#11     DiagnosticsProperty.valueToString (package:flutter/src/foundation/diagnostics.dart:2698:61)
#12     DiagnosticsProperty.toDescription (package:flutter/src/foundation/diagnostics.dart:2712:21)
#13     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1170:31)
#14     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1280:39)
#15     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#16     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#17     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#18     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#19     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#20     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#21     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#22     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#23     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#24     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#25     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#26     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#27     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#28     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#29     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#30     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#31     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#32     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#33     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#34     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#35     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#36     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#37     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#38     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#39     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#40     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#41     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#42     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#43     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#44     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#45     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#46     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#47     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#48     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#49     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#50     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#51     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#52     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#53     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#54     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#55     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#56     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#57     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#58     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#59     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#60     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#61     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#62     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#63     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#64     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#65     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#66     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#67     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#68     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#69     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#70     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#71     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#72     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#73     TextTreeRenderer.render (package:flutter/src/foundation/diagnostics.dart:1336:33)
#74     DiagnosticsNode.toStringDeep (package:flutter/src/foundation/diagnostics.dart:1709:7)
#75     DiagnosticableTree.toStringDeep (package:flutter/src/foundation/diagnostics.dart:3406:32)
#76     debugDumpApp (package:flutter/src/widgets/binding.dart:883:58)
#77     main.<anonymous closure> (file:///Users/paulinaszklarska/Projects/cca-mobile-app/test/agreements/agreement_details/example_test.dart:13:5)
<asynchronous suspension>
#78     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:124:25)
#79     TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:696:19)
<asynchronous suspension>
#82     TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:679:14)
#83     AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1050:24)
#89     AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1047:15)
#90     testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:121:22)
#91     Declarer.test.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:171:27)
<asynchronous suspension>
#92     Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:242:15)
#97     Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:239:5)
#98     Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:169:33)
#103    Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:168:13)
#104    Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:392:25)
#118    _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
#119    _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
#120    _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
(elided 28 frames from class _FakeAsync, package dart:async, package dart:async-patch, and package stack_trace)
```

---
Comment by @tigertore on May 7, 2020
I see the same issue when using the flutter inspector. If I click on a widget that contains a SvgPicture it dumps this stack trace and the widget and all its children can't be inspected:
════════ Exception caught by Flutter framework ═════════════════════════════════════════════════════
The following assertion was thrown during a service extension callback for "ext.flutter.inspector.getDetailsSubtree":
type 'PictureStream' is not a subtype of type 'Diagnosticable'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

When the exception was thrown, this was the stack: 
#0      DiagnosticableMixin.toDiagnosticsNode (package:flutter/src/foundation/diagnostics.dart:3113:14)
#1      DiagnosticableMixin.toString.<anonymous closure> (package:flutter/src/foundation/diagnostics.dart:3095:20)
#2      DiagnosticableMixin.toString (package:flutter/src/foundation/diagnostics.dart:3097:6)
#3      DiagnosticsProperty.valueToString (package:flutter/src/foundation/diagnostics.dart:2698:61)
#4      DiagnosticsProperty.toDescription (package:flutter/src/foundation/diagnostics.dart:2712:21)
...
════════════════════════════════════════════════════════════════════════════════════════════════════


---
Comment by @dnfield on May 7, 2020
What version of Flutter are you on?

There were changes to both Flutter svg and Flutter recently that are impacting this.

---
Comment by @tigertore on May 8, 2020
This is on flutter stable channel version 1.12.13+hotfix.9.
flutter_svg: ^0.17.3+1
I will test it again when I have upgraded to flutter 1.17

---
Comment by @tigertore on May 8, 2020
In Flutter 1.17 this error is gone, and it is working as expected.

---
Comment by @shinriyo on Aug 27, 2020
@pszklarska
Hello
You put the code before `expect` line.

```
await tester.pumpAndSettle();
```
It waits drawing.

---
Comment by @erickm32 on Apr 9, 2021
I'm having a similar problem on a integration test. Rendering a tree like so:
```dart
   ...
              Expanded(
                flex: 1,
                child: GestureDetector(
                  onTap: () async => await doSomething(),
                  child: Center(
                    child: SvgPicture.asset(
                      'images/some.svg',
                      key: Key('find_me'),
                    ),
                  ),
                ),
              ),
   ...
```
The widget tester is unable to find a widget to tap with the code:
```dart
        group('', () {
            testWidgets('', (tester) async {
              await tester.pumpWidget(MyWidget());
              await tester.pumpAndSettle();
              
              await tester.tap(find.byKey(Key('find_me')));
              // await tester.tap(find.byType(SvgPicture).last); // this also doesn't work
              await tester.pumpAndSettle();

              // expectations for the onTap...
            }
          );
        });
```
All that I get is an error:
`The following StateError was thrown running a test:`
`Bad state: No element`

If I put an `await Future.delayed(Duration(seconds: 5));` to see the screen, the svg is rendered but, when clicking on it, on the console is printed:
`No widgets found at Offset(171.4, 656.3).`

Any hints on how to find it?