flutterchina / flutter_in_action_2nd

《Flutter实战 第二版》 书稿
https://book.flutterchina.club/
2.23k stars 348 forks source link

7.2.2 章节代码报错 #180

Closed zhangrunhao closed 1 year ago

zhangrunhao commented 1 year ago

//定义一个便捷方法,方便子树中的widget获取共享数据 static ShareDataWidget of(BuildContext context) { //return context.dependOnInheritedWidgetOfExactType(); return context.getElementForInheritedWidgetOfExactType().widget; }

报错: A value of type 'Widget' can't be returned from the method 'of' because it has a return type of 'SharedDataWidget'

➜ ~ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.7.0, on macOS 13.1 22C65 darwin-x64, locale en-CN) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc4) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.3) [✓] IntelliJ IDEA Ultimate Edition (version 2020.3) [✓] VS Code (version 1.75.0) [✓] Connected device (3 available) [✓] HTTP Host Availability

wendux commented 1 year ago

updated