You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Web应用启动失败:依赖版本兼容问题求助

解决Flutter Web应用依赖错误问题

环境信息

Flutter 3.7.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b06b8b2710 (1 year, 5 months ago) • 2023-01-23 16:55:55 -0800
Engine • revision b24591ed32
Tools • Dart 2.19.0 • DevTools 2.20.1

pubspec.yml配置

name: myApp
description: My Project

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.19.0 <3.0.0"
        dependencies:
      abg_utils: 8.0.8
      html_editor_enhanced: 2.5.1
      timeago: ^3.1.0
      maps_toolkit: ^2.0.0
      google_maps_flutter_web: 0.3.2+1
      google_maps_flutter: 2.1.1
      universal_html: 2.0.8
      soundpool: 2.2.0
      provider: 6.0.2
      image_picker: 0.8.4+7
      syncfusion_flutter_charts: 19.2.62


      flutter:
        sdk: flutter

      flutter_lints: ^1.0.4

      # The following adds the Cupertino Icons font to your application.
      # Use with the CupertinoIcons class for iOS style icons.
      cupertino_icons: ^1.0.2

    dependency_overrides:
      platform: ^3.1.4
      win32: ^2.0.0
      device_info_plus: ^3.2.1
      device_info_plus_windows: ^2.1.1
      ffi: ^1.0.0
      firebase_core: ^2.5.0
      firebase_core_web: ^2.1.1
      firebase_messaging_web: ^3.2.12
      firebase_messaging_platform_interface: ^4.2.11
      firebase_messaging: ^14.2.2
      firebase_storage: ^11.0.11
      firebase_core_platform_interface: ^4.2.1
      #cloud_functions_web: ^4.7.0
      #cloud_functions: ^5.0.0


    dev_dependencies:
      flutter_test:
        sdk: flutter

    # For information on the generic Dart part of this file, see the
    # following page: https://dart.dev/tools/pub/pubspec

    # The following section is specific to Flutter.
    flutter:

      # The following line ensures that the Material Icons font is
      # included with your application, so that you can use the icons in
      # the material Icons class.
      uses-material-design: true

执行flutter run -d chrome后出现的错误

Launching lib/main.dart on Chrome in debug mode...

../../../.pub-cache/hosted/pub.dev/platform-3.1.4/lib/platform.dart:1:1: Error: The specified language version is too high. The highest supported language version is 2.19.
// Copyright 2013 The Flutter Authors. All rights reserved.
^
../../../.pub-cache/hosted/pub.dev/platform-3.1.4/lib/src/interface/local_platform.dart:1:1: Error: The specified language version is too high. The highest supported language version is 2.19.
// Copyright 2013 The Flutter Authors. All rights reserved.
^
../../../.pub-cache/hosted/pub.dev/platform-3.1.4/lib/src/interface/platform.dart:1:1: Error: The specified language version is too high. The highest supported language version is 2.19.
// Copyright 2013 The Flutter Authors. All rights reserved.
^
../../../.pub-cache/hosted/pub.dev/platform-3.1.4/lib/src/testing/fake_platform.dart:1:1: Error: The specified language version is too high. The highest supported language version is 2.19.
// Copyright 2013 The Flutter Authors. All rights reserved.
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/cloud_firestore_web.dart:53:29: Error: The method 'FirebaseFirestoreWeb.delegateFor' has fewer named arguments than those of overridden method
'FirebaseFirestorePlatform.delegateFor'.
FirebaseFirestorePlatform delegateFor(
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_firestore.dart:68:29: Context: This is the overridden method ('delegateFor').
FirebaseFirestorePlatform delegateFor(
^
../../../.pub-cache/hosted/pub.dev/firebase_auth_web-4.6.1/lib/firebase_auth_web.dart:123:27: Error: The parameter 'currentUser' of the method 'FirebaseAuthWeb.setInitialValues' has type 'Map<String, dynamic>?',
which does not match the corresponding type, 'PigeonUserDetails?', in the overridden method, 'FirebaseAuthPlatform.setInitialValues'.
- 'Map' is from 'dart:core'.
- 'PigeonUserDetails' is from 'package:firebase_auth_platform_interface/src/pigeon/messages.pigeon.dart'
('../../../.pub-cache/hosted/pub.dev/firebase_auth_platform_interface-6.19.1/lib/src/pigeon/messages.pigeon.dart').
Change to a supertype of 'PigeonUserDetails?', or, for a covariant parameter, a subtype.
Map<String, dynamic>? currentUser,
^
../../../.pub-cache/hosted/pub.dev/firebase_auth_platform_interface-6.19.1/lib/src/platform_interface/platform_interface_firebase_auth.dart:99:24: Context: This is the overridden method ('setInitialValues').
FirebaseAuthPlatform setInitialValues({
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:122:37: Error: The parameter 'fields' of the method 'QueryWeb.endAt' has type 'List', which does not match the
corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.endAt'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform endAt(List fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:80:17: Context: This is the overridden method ('endAt').
QueryPlatform endAt(Iterable fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:130:49: Error: The parameter 'orders' of the method 'QueryWeb.endBeforeDocument' has type 'List', which does not match
the corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.endBeforeDocument'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform endBeforeDocument(List orders, List values) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:98:17: Context: This is the overridden method ('endBeforeDocument').
QueryPlatform endBeforeDocument(
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:130:71: Error: The parameter 'values' of the method 'QueryWeb.endBeforeDocument' has type 'List', which does not match
the corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.endBeforeDocument'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform endBeforeDocument(List orders, List values) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:98:17: Context: This is the overridden method ('endBeforeDocument').
QueryPlatform endBeforeDocument(
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:139:41: Error: The parameter 'fields' of the method 'QueryWeb.endBefore' has type 'List', which does not match the
corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.endBefore'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform endBefore(List fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:111:17: Context: This is the overridden method ('endBefore').
QueryPlatform endBefore(Iterable fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:191:45: Error: The parameter 'orders' of the method 'QueryWeb.orderBy' has type 'List<List>', which does not match the
corresponding type, 'Iterable<List>', in the overridden method, 'QueryPlatform.orderBy'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable<List>', or, for a covariant parameter, a subtype.
QueryPlatform orderBy(List<List> orders) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:152:17: Context: This is the overridden method ('orderBy').
QueryPlatform orderBy(Iterable<List> orders) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:205:42: Error: The parameter 'fields' of the method 'QueryWeb.startAfter' has type 'List', which does not match the
corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.startAfter'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform startAfter(List fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:182:17: Context: This is the overridden method ('startAfter').
QueryPlatform startAfter(Iterable fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:213:47: Error: The parameter 'orders' of the method 'QueryWeb.startAtDocument' has type 'List', which does not match
the corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.startAtDocument'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform startAtDocument(List orders, List values) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:200:17: Context: This is the overridden method ('startAtDocument').
QueryPlatform startAtDocument(
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:213:69: Error: The parameter 'values' of the method 'QueryWeb.startAtDocument' has type 'List', which does not match
the corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.startAtDocument'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform startAtDocument(List orders, List values) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:200:17: Context: This is the overridden method ('startAtDocument').
QueryPlatform startAtDocument(
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:222:39: Error: The parameter 'fields' of the method 'QueryWeb.startAt' has type 'List', which does not match the
corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.startAt'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype.
QueryPlatform startAt(List fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_platform_interface-5.16.2/lib/src/platform_interface/platform_interface_query.dart:213:17: Context: This is the overridden method ('startAt').
QueryPlatform startAt(Iterable fields) {
^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/collection_reference_web.dart:13:7: Error: The implementation of 'endAt' in the non-abstract class 'CollectionReferenceWeb' does not conform to
its interface.
class CollectionReferenceWeb extends QueryWeb
^^^^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.dev/cloud_firestore_web-2.8.10/lib/src/query_web.dart:122:37: Context: The parameter 'fields' of the method 'QueryWeb.endAt' has type 'List', which does not match the
corresponding type, 'Iterable', in the overridden method, 'QueryPlatform.endAt'.
- 'List' is from 'dart:core'.
- 'Iterable' is from 'dart:core'.
Change to a supertype of 'Iterable', or, for a covariant parameter, a subtype...

解决方法

  • 调整platform包版本:platform 3.1.4要求的Dart版本高于当前的2.19,在dependency_overrides中将platform版本改为兼容Dart 2.19的3.0.0:
    dependency_overrides:
      platform: 3.0.0
    
  • 统一Firebase包版本:当前Firebase各包版本存在接口不匹配,需确保所有Firebase相关包版本兼容Flutter 3.7.0和Dart 2.19,推荐使用以下版本组合(替换原有的Firebase相关override):
    dependency_overrides:
      firebase_core: ^2.4.0
      firebase_core_web: ^2.0.1
      firebase_messaging: ^14.1.0
      firebase_messaging_web: ^3.1.10
      firebase_storage: ^11.0.9
      firebase_core_platform_interface: ^4.1.0
      firebase_messaging_platform_interface: ^4.1.6
    
    若不需要强制覆盖,可直接移除Firebase相关的dependency_overrides,让pub自动解析兼容版本。
  • 清理缓存并重新拉取依赖:执行以下命令清除旧缓存并获取匹配的依赖:
    flutter clean
    flutter pub get
    
  • 检查其他依赖兼容性:确认abg_utils、html_editor_enhanced等第三方包是否支持Flutter 3.7.0和Dart 2.19,若存在不兼容,降级到对应版本。

内容的提问来源于stack exchange,提问作者leonidas79

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 17:27:33