Flutter构建Web应用程序 - “无法编译应用程序”

5

我已经为我的项目启用了Web支持,在运行 flutter run -d chrome 后,我收到以下错误:

Launching lib/main.dart on Chrome in debug mode...
Syncing files to device Chrome...                                                                                                                                                                    
Compiler message:                                  
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:26:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  GoogleAuth.fakeConstructor$();                                                                                   
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:216:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  SigninOptionsBuilder.fakeConstructor$();                                                                         
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:351:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequestPromise.fakeConstructor$();                                                                           
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:378:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequest.fakeConstructor$() : super.fakeConstructor$();                                                       
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:402:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpBatch.fakeConstructor$();                                                                                    
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:440:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  RpcRequest.fakeConstructor$();                                                                                   
  ^                                                                                                                
Syncing files to device Chrome...                               19,442ms (!)                                       
Failed to compile application.
Tals-Macbook:matkonit talbarda$ flutter run -d chrome
Launching lib/main.dart on Chrome in debug mode...
Syncing files to device Chrome...                                                                                                                                                                    
Compiler message:                                  
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:26:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  GoogleAuth.fakeConstructor$();                                                                                   
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapiauth2.dart:216:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  SigninOptionsBuilder.fakeConstructor$();                                                                         
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:351:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequestPromise.fakeConstructor$();                                                                           
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:378:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpRequest.fakeConstructor$() : super.fakeConstructor$();                                                       
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:402:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  HttpBatch.fakeConstructor$();                                                                                    
  ^                                                                                                                
../../flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in_web-0.8.3+1/lib/src/generated/gapi.dart:440:3: Error: JS interop classes do not support non-external constructors.
Try annotating with `external`.                                                                                    
  RpcRequest.fakeConstructor$();                                                                                   
  ^                                                                                                                
Syncing files to device Chrome...                               17,899ms (!)                                       
Failed to compile application.

我该如何修复这个问题?

4个回答

3

我注意到这个问题已经在 google_sign_in_web 0.9.0 中得到解决。因此,请在您的 pubspec.yaml 文件中更改版本。

google_sign_in_web: ^0.9.1

更新于2020年4月20日:如果您在依赖于google_sign_in方面遇到问题,那么请在pubspec.yaml文件中更改该版本。

google_sign_in: 4.4.3

之前: 然而,当像我一样,你对 google_sign_in 有依赖关系时,就需要更改一些东西...... 如果将 google_sign_in_web 更改为0.9.0,并将 google_sign_in 版本更改为4.4.1,则获取软件包将失败:

Because ${your_project_name} depends on google_sign_in 4.4.1 which depends on google_sign_in_web ^0.8.2, google_sign_in_web ^0.8.2 is required.
So, because ${your_project_name} depends on google_sign_in_web ^0.9.0, version solving failed.
pub get failed (1; So, because  ${your_project_name} depends on google_sign_in_web ^0.9.0, version solving failed.)

在这种情况下,您需要等待google_sign_in进行升级(我创建了https://github.com/flutter/plugins/pull/2647拉取请求),或者像我一样暂时执行以下操作:
1)从https://github.com/flutter/plugins克隆flutter插件。
mkdir /src
cd /src
git clone https://github.com/flutter/plugins.git

2) 修改 /src/plugins/plugins/packages/google_sign_in/google_sign_in/pubspec.yaml 文件。

  google_sign_in_web: ^0.9.0

3)将您项目中的依赖项更改为指向已更改版本的google_sign_in,即:

google_sign_in:
  path: ../../flutter/plugins/packages/google_sign_in/google_sign_in
google_sign_in_web: ^0.9.0

2

建议转移到beta频道。

flutter channel beta

1
使用Dart pub outdated来识别过时的软件包依赖项,并获得有关如何更新它们的建议。依赖管理的最佳实践包括使用最新的稳定软件包版本,以便您可以获得最新的错误修复和改进。
打开终端并进入您的应用程序文件夹,然后运行flutter pub outdated以列出所有过时的软件包。 listing all outdated packages and

cmd:flutter pub outdated

升级所有过时的软件包到最新或可解决的版本。从终端运行flutter pub upgrade以将过时的软件包更新为最新版本,然后运行您的应用程序。 更多信息:https://dart.dev/tools/pub/cmd/pub-outdated

1

由于某些原因,较新版本的Flutter停止支持以下格式的依赖关系: folding_cell: "^0.1.2" 相反,请检查您的pubspec.yaml文件并将任何使用该格式的依赖项更改为以下内容: folding_cell: ^1.0.0 我以folding_cell为例。 这对我解决了问题,希望能帮助到其他人。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接