boy*_*eak 1 flutter webview-flutter
body: const Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: WebView(
initialUrl: "https://xxxx",
navigationDelegate: (navigation) {
return NavigationDecision.navigate;
},
),
),
Run Code Online (Sandbox Code Playgroud)
编译的时候,发生了错误。
lib/main.dart:84:31: Error: Not a constant expression.
navigationDelegate: (navigation) {
^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
当我使用flutter-2.2.0and时webview_flutter-2.0.13,上面的代码工作正常。但是当我将 flutter 升级到 2.5.2 并将 webview_flutter 升级到 2.0.13 后,发生了错误。环境(颤振2.5.2):
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
webview_flutter: 2.1.1
Run Code Online (Sandbox Code Playgroud)
您正在尝试使用带有非常量参数的小部件const的构造函数。Center
通过使用 const 构造函数创建小部件,您可以指定其所有字段都将在编译时定义。
因此,在您的情况下,您需要在小部件const之前删除Center,因为这不是恒定的:
navigationDelegate: (navigation) {
return NavigationDecision.navigate;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3617 次 |
| 最近记录: |