Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when adding Futures into the widget tree #15203

Open
gorjan-mishevski opened this issue Mar 6, 2018 · 6 comments
Open
Labels
d: api docs Issues with https://api.flutter.dev/ dependency: dart Dart team may need to help us found in release: 3.0 Found to occur in 3.0 found in release: 3.1 Found to occur in 3.1 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@gorjan-mishevski
Copy link

gorjan-mishevski commented Mar 6, 2018

EDIT: It seems I must use setState() for it to work. Not directly returning from the async function. But still I think a better error message is needed.

Steps to Reproduce

import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:convert';

class Report extends StatelessWidget {
  makeRequest() async {
    var _httpClient = new HttpClient();
  
    try {
      return 'OK';
    } catch (exception) {
      return 'OH NO!';
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Text(makeRequest());
  }
}

Logs

Logs
I/flutter ( 4208): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
[   +3 ms] I/flutter ( 4208): The following assertion was thrown building Report(dirty):
[        ] I/flutter ( 4208): type '_Future' is not a subtype of type 'String' of 'data' where
[        ] I/flutter ( 4208):   _Future is from dart:async
[        ] I/flutter ( 4208):   String is from dart:core
[  +32 ms] I/flutter ( 4208): Either the assertion indicates an error in the framework itself, or we should provide substantially
[        ] I/flutter ( 4208): more information in this error message to help you determine and fix the underlying cause.
[        ] I/flutter ( 4208): In either case, please report this assertion by filing a bug on GitHub:
[        ] I/flutter ( 4208):   https://github.com/flutter/flutter/issues/new
[        ] I/flutter ( 4208): When the exception was thrown, this was the stack:
[  +10 ms] I/flutter ( 4208): #0      new Text (package:flutter/src/widgets/text.dart:203)
[        ] I/flutter ( 4208): #1      Report.build (file:///Users/gorjan/Projects/aero/lib/widgets/Report.dart:32)
[        ] I/flutter ( 4208): #2      StatelessElement.build (package:flutter/src/widgets/framework.dart:3678)
[  +10 ms] I/flutter ( 4208): #3      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3625)
[        ] I/flutter ( 4208): #4      Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #5      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #6      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #7      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #8      Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[  +10 ms] I/flutter ( 4208): #10     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #11     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #12     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #13     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #14     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #15     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #16     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #17     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #18     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #19     ParentDataElement.mount (package:flutter/src/widgets/framework.dart:3916)
[        ] I/flutter ( 4208): #20     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #21     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4716)
[        ] I/flutter ( 4208): #22     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #23     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #25     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #26     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #27     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #28     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #29     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #30     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #31     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #32     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #33     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3741)
[        ] I/flutter ( 4208): #34     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #35     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #36     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #37     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #38     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #39     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #40     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #41     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #42     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #43     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #44     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #45     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #46     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #47     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #48     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #49     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #50     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #51     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #52     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3741)
[        ] I/flutter ( 4208): #53     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #54     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #55     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #56     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #57     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #58     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #59     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3741)
[        ] I/flutter ( 4208): #60     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #61     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #62     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #63     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #64     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #65     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #66     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #67     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #68     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #69     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #70     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #71     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #72     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #73     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #74     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #75     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #76     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #77     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #78     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3741)
[        ] I/flutter ( 4208): #79     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #80     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #81     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #82     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #83     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #84     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #85     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3741)
[        ] I/flutter ( 4208): #86     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #87     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #88     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #89     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #90     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #91     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #92     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #93     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #94     Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #95     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #96     Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #97     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #98     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #99     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #100    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #101    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #102    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #103    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #104    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #105    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #106    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #107    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #108    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #109    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #110    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #111    Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #112    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #113    StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3741)
[        ] I/flutter ( 4208): #114    ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #115    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #116    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #117    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #118    Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #119    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #120    ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #121    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #122    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #123    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #124    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #125    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #126    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #127    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #128    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #129    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #130    Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #131    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #132    ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #133    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #134    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #135    SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4611)
[        ] I/flutter ( 4208): #136    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)
[        ] I/flutter ( 4208): #137    Element.updateChild (package:flutter/src/widgets/framework.dart:2693)
[        ] I/flutter ( 4208): #138    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636)
[        ] I/flutter ( 4208): #139    Element.rebuild (package:flutter/src/widgets/framework.dart:3478)
[        ] I/flutter ( 4208): #140    ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605)
[        ] I/flutter ( 4208): #141    StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3741)
[        ] I/flutter ( 4208): #142    ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600)
[        ] I/flutter ( 4208): #143    Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890)

Flutter Doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.1.5, on Mac OS X 10.13.3 17D102, locale en-MK)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
[✓] Android Studio (version 3.0)
[✓] VS Code (version 1.20.1)
[✓] Connected devices (1 available)

• No issues found!
@gorjan-mishevski gorjan-mishevski changed the title Bug Better error message Mar 6, 2018
@xster xster added framework flutter/packages/flutter repository. See also f: labels. d: api docs Issues with https://api.flutter.dev/ labels Mar 6, 2018
@xster xster changed the title Better error message Better error message when adding Futures into the widget tree Mar 6, 2018
@Hixie
Copy link
Contributor

Hixie commented Mar 7, 2018

Did the analyzer not report any issues?

@gorjan-mishevski
Copy link
Author

gorjan-mishevski commented Mar 7, 2018

Unfortunately nothing @Hixie . I am using VS Code with the flutter plugin and then tried with Android Studio. I ran the example just now and opened the Dart Analysis but it reported no problems at all. I hope this helps

@Hixie
Copy link
Contributor

Hixie commented Mar 8, 2018

Oh, I see. It's because you declared makeRequest as returning dynamic (by not specifying a return type).

In the coming months we'll turn on more inference and more strict checking and eventually this will get caught by the analyzer because the inferred return type (Future<String>) will not match the expected type (String).

@goderbauer goderbauer added the dependency: dart Dart team may need to help us label Dec 28, 2018
@goderbauer
Copy link
Member

Properly specifying the return type will trigger an analyzer error:

import 'package:flutter/material.dart';
import 'dart:async';

class Report extends StatelessWidget {
  Future<String> makeRequest() async {
    try {
      return 'OK';
    } catch (exception) {
      return 'OH NO!';
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Text(makeRequest());
  }
}

Not sure what we can do on the Flutter side to make this better?

@pedromassangocode
Copy link

Found in 1.21.0-1.0.pre.

Complete sample code
import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatelessWidget {

  makeRequest() async {
    try {
      return 'OK';
    } catch (exception) {
      return 'OH NO!';
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Text(makeRequest()),
    );
  }
}
Logs
Performing hot restart...
Syncing files to device AOSP on IA Emulator...
Restarted application in 774ms.

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following _TypeError was thrown building MyApp(dirty):
type 'Future<dynamic>' is not a subtype of type 'String'

The relevant error-causing widget was:
  MyApp file:///Users/pedro/dev/projects/hello_flutter/lib/main.dart:3:41

When the exception was thrown, this was the stack:
#0      MyApp.build (package:hello_flutter/main.dart:18:18)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4631:28)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4557:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4273:5)
#4      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4536:5)
#5      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4531:5)
...     Normal element mounting (132 frames)
#137    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3501:14)
#138    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6002:32)
...     Normal element mounting (267 frames)
#405    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3501:14)
#406    Element.updateChild (package:flutter/src/widgets/framework.dart:3260:18)
#407    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1217:16)
#408    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1188:5)
#409    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1130:17)
#410    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2620:19)
#411    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1129:13)
#412    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:941:7)
#413    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:922:7)
(elided 11 frames from class _RawReceivePortImpl, class _Timer, dart:async, and dart:async-patch)

════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following _TypeError was thrown building MyApp(dirty):
type 'Future<dynamic>' is not a subtype of type 'String'

The relevant error-causing widget was: 
  MyApp file:///Users/pedro/dev/projects/hello_flutter/lib/main.dart:3:41
When the exception was thrown, this was the stack: 
#0      MyApp.build (package:hello_flutter/main.dart:18:18)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4631:28)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4557:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4273:5)
#4      ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4536:5)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following _TypeError was thrown building MyApp(dirty):
type 'Future<dynamic>' is not a subtype of type 'String'

The relevant error-causing widget was:
  MyApp file:///Users/pedro/dev/projects/hello_flutter/lib/main.dart:3:41

When the exception was thrown, this was the stack:
#0      MyApp.build (package:hello_flutter/main.dart:18:18)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4631:28)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4557:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4273:5)
#4      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:33)
#5      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:880:20)
#6      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
#7      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
#8      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1056:9)
#9      SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:865:7)
(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)

════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following _TypeError was thrown building MyApp(dirty):
type 'Future<dynamic>' is not a subtype of type 'String'

The relevant error-causing widget was: 
  MyApp file:///Users/pedro/dev/projects/hello_flutter/lib/main.dart:3:41
When the exception was thrown, this was the stack: 
#0      MyApp.build (package:hello_flutter/main.dart:18:18)
#1      StatelessElement.build (package:flutter/src/widgets/framework.dart:4631:28)
#2      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4557:15)
#3      Element.rebuild (package:flutter/src/widgets/framework.dart:4273:5)
#4      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2667:33)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
flutter doctor -v
[✓] Flutter (Channel dev, 1.21.0-1.0.pre, on Mac OS X 10.15.5 19F101, locale
    en-AO)
    • Flutter version 1.21.0-1.0.pre at /Users/pedro/dev/SDKs/flutter_dev
    • Framework revision f25bd9c55c (8 days ago), 2020-07-14 20:26:01 -0400
    • Engine revision 99c2b3a245
    • Dart version 2.9.0 (build 2.9.0-21.0.dev 20bf2fcf56)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/pedro/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Users/pedro/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6514223/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.3

[✗] Chrome - develop for the web (Cannot find Chrome executable at
    /Applications/Google Chrome.app/Contents/MacOS/google-chrome-unsafe)
    ! /Applications/Google Chrome.app/Contents/MacOS/google-chrome-unsafe is not
      executable.

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] Android Studio (version 4.0)
    • Android Studio at /Users/pedro/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6514223/Android
      Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.47.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.12.1

[✓] Connected device (3 available)
    • AOSP on IA Emulator (mobile) • emulator-5554 • android-x86    • Android 9
      (API 28) (emulator)
    • macOS (desktop)              • macos         • darwin-x64     • Mac OS X
      10.15.5 19F101
    • Web Server (web)             • web-server    • web-javascript • Flutter
      Tools

! Doctor found issues in 1 category.

@pedromassangocode pedromassangocode added found in release: 1.21 Found to occur in 1.21 has reproducible steps The issue has been confirmed reproducible and is ready to work on labels Jul 22, 2020
@maheshmnj
Copy link
Member

Reproducible as of stable 3.0.1 and master 3.1.0 if the return type of widget is not specified (It is assumed to be dynamic) a run time error is thrown as intended. And when we specify the return type as Future<String> the analyzer shows the error and the app fails to compile. I believe this issue is more specific to dart rather than flutter.

logs
Restarted application in 299ms.

════════ Exception caught by widgets library ═══════════════════════════════════
The following _TypeError was thrown building Report(dirty):
type 'Future<dynamic>' is not a subtype of type 'String'

The relevant error-causing widget was
Report
When the exception was thrown, this was the stack
#0      Report.build
#1      StatelessElement.build
#2      ComponentElement.performRebuild
#3      Element.rebuild
#4      ComponentElement._firstBuild
#5      ComponentElement.mount
...     Normal element mounting (24 frames)
#29     Element.inflateWidget
#30     MultiChildRenderObjectElement.inflateWidget
#31     MultiChildRenderObjectElement.mount
...     Normal element mounting (175 frames)
#206    Element.inflateWidget
#207    MultiChildRenderObjectElement.inflateWidget
#208    MultiChildRenderObjectElement.mount
...     Normal element mounting (407 frames)
#615    Element.inflateWidget
#616    Element.updateChild
#617    RenderObjectToWidgetElement._rebuild
#618    RenderObjectToWidgetElement.mount
#619    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure>
#620    BuildOwner.buildScope
#621    RenderObjectToWidgetAdapter.attachToRenderTree
#622    WidgetsBinding.attachRootWidget
#623    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure>
(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════

flutter doctor -v (mac)
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.3 21E230 darwin-arm, locale en-IN)
    • Flutter version 3.0.1 at /Users/mahesh/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (3 days ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! CocoaPods 1.10.2 out of date (1.11.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin
        usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.66.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (4 available)
    • Redmi K20 Pro (mobile) • 192.168.1.2:5555                     • android-arm64  • Android 11 (API 30)
    • iPhone 12 Pro (mobile) • 19FD0231-BFF0-441D-B584-AD94C4084525 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 12.3 21E230 darwin-arm
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 101.0.4951.64

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 3.1.0-0.0.pre.1008, on macOS 12.3 21E230 darwin-arm, locale en-IN)
    • Flutter version 3.1.0-0.0.pre.1008 at /Users/mahesh/Documents/flutter_master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c2cc31b198 (26 hours ago), 2022-05-30 05:23:08 -0400
    • Engine revision 05efd25f05
    • Dart version 2.18.0 (build 2.18.0-151.0.dev)
    • DevTools version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
    • Android SDK at /Users/mahesh/Library/Android/sdk
    • Platform android-32, build-tools 33.0.0-rc4
    • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! CocoaPods 1.10.2 out of date (1.11.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin
        usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Community Edition (version 2021.2.1)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 61.2.4
    • Dart plugin version 212.5080.8

[✓] VS Code (version 1.66.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (4 available)
    • sdk gphone arm64 (mobile) • emulator-5554                        • android-arm64  • Android 11 (API 30)
      (emulator)
    • iPhone 12 Pro (mobile)    • 6AE1D692-DB57-4C3E-ADCA-66842182426B • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • macOS (desktop)           • macos                                • darwin-arm64   • macOS 12.3 21E230
      darwin-arm
    • Chrome (web)              • chrome                               • web-javascript • Google Chrome
      102.0.5005.61

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

@maheshmnj maheshmnj added found in release: 3.0 Found to occur in 3.0 found in release: 3.1 Found to occur in 3.1 and removed found in release: 1.21 Found to occur in 1.21 labels Jun 3, 2022
@goderbauer goderbauer added the P3 Issues that are less important to the Flutter project label Feb 21, 2023
@flutter-triage-bot flutter-triage-bot bot added team-framework Owned by Framework team triaged-framework Triaged by Framework team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
d: api docs Issues with https://api.flutter.dev/ dependency: dart Dart team may need to help us found in release: 3.0 Found to occur in 3.0 found in release: 3.1 Found to occur in 3.1 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

6 participants