模态底部图纸库导致问题

Mac*_*iek 8 dart flutter

我今天升级了我的 flutter 版本并发现了这个问题:

../../../../../AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/bar_bottom_sheet.dart:102:13: Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.
      .push(ModalBottomSheetRoute<T>(
            ^^^^^^^^^^^^^^^^^^^^^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/bar_bottom_sheet.dart:125:10: Error: A value of type 'Object?' can't be returned from an async function with return type 'Future<T?>'.
 - 'Object' is from 'dart:core'.
 - 'Future' is from 'dart:async'.
  return result;
         ^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/material_bottom_sheet.dart:28:13: Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.
      .push(ModalBottomSheetRoute<T>(
            ^^^^^^^^^^^^^^^^^^^^^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/material_bottom_sheet.dart:50:10: Error: A value of type 'Object?' can't be returned from an async function with return type 'Future<T?>'.
 - 'Object' is from 'dart:core'.
 - 'Future' is from 'dart:async'.
  return result;
         ^
../../../../../AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/material_with_modal_page_route.dart:4:1: Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.
import '../modal_bottom_sheet.dart';
^^^^^^^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script 'C:\FlutterSDK\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1165

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\FlutterSDK\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 20s
Exception: Gradle task assembleDebug failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

它在我尝试调试它后出现,是否有任何解决方案或者我应该删除这个库?

Ash*_*ish 15

所以这个问题是由于 flutter 3.7 和 modal_bottom_sheet:2.1.0 中的名称冲突造成的

自从 flutter 3.7 发布这个编译时问题开始以来,库维护者已经发布了3.0.0-pre版本,他们将任何ModalBottomSheetRoute类引用重命名为ModalSheetRoute. 使用这个版本modal_bottom_sheet: ^3.0.0-pre


小智 7

升级 flutter 后我也遇到了同样的问题。我意识到是flutter开发环境的兼容性问题。解决方案是还更新开发通道:

flutter channel dev
flutter upgrade
Run Code Online (Sandbox Code Playgroud)


小智 7

根据Ashish的说法,对我有用的是,我通过添加以下行,在 pubspec.yaml 文件中使用依赖项覆盖对默认模式底部表进行了覆盖:

dependency_overrides:
  modal_bottom_sheet: ^3.0.0-pre
Run Code Online (Sandbox Code Playgroud)

(添加到 pubspec.yaml 文件时请务必检查缩进)