错误:“ModalBottomSheetRoute”是从两者导入的

Abd*_*oud 29 dart flutter flutter-dependencies

错误:“ModalBottomSheetRoute”是从“package:flutter/src/material/bottom_sheet.dart”和“package:modal_bottom_sheet/src/bottom_sheet_route.dart”导入的。

导入'material.dart'隐藏ModalBottomSheetRoute;

Rad*_*nka 29

错误背后的原因是同时表示material/bottom_sheet.dartbottom_sheet_route导出ModalBottomSheetRoute.

'ModalBottomSheetRoute' is imported from both
'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,我们必须隐藏其中一个ModalBottomSheetRoute. 因为我们需要将其导入,所以bottom_sheet_route我们需要隐藏它material

这就是我们可以解决的方法

雷莱斯

import 'package:flutter/material.dart'

import 'package:flutter/material.dart' hide ModalBottomSheetRoute;

在以下文件中。

  1. /Users/<usename>/.pub-cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/material_with_modal_page_route.dart
  2. /Users/<usename>/.pub-cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/bar_bottom_sheet.dart
  3. /Users/<usename>/.pub-cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/material_bottom_sheet.dart

  • 这个解决方案有效。希望这只是暂时的... (3认同)

小智 26

使用 modal_bottom_sheet: 3.0.0-pre

这位于您的dependency_overrides:文件中pubspec.yaml,例如:

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


小智 17

软件包中已经有一个热修复程序

将其添加到 pubspec.yaml 中

 modal_bottom_sheet:
     git:
       url: https://github.com/followthemoney1/modal_bottom_sheet.git
       ref: main
       path: modal_bottom_sheet
Run Code Online (Sandbox Code Playgroud)

已经被拉取请求但尚未合并


Mas*_* .H 16

此错误是由于新的 flutter SDK 更新而发生的

这是 flutter 3.7 或更高版本的迁移指南

模态底部表:

  • 更新到 modal_bottom_sheet:^3.0.0-pre

  • 在每个文件中更改import 'packa ge:flutter/material.dart'import 'package:flutter/material.dart' hide ModalBottomSheetRoute;,您正在使用底部工作表插件。

像这样:

在此输入图像描述

如果答案有帮助,请投票。

  • 但我没有在我的项目中使用 modal_bottom_sheet 并且仍然有这个问题 (2认同)

Tex*_*exv 10

country_code_picker如果您在项目中使用库包,请将其更改为country_picker. 该包使用旧版本的 modal_bottom_sheet 并且存在冲突。


Abd*_*oud 5

问题是在flutter材质和插件“modal_bottom_sheet”中发现了名为“ModalBottomSheetRoute”的类

当我尝试使用 flutter v3.7.0 beta sdk 时发生了这种情况

#修复这个问题

在插件“modal_bottom_sheet”中搜索任何导入“material.dart”的文件

import 'material.dart';

Run Code Online (Sandbox Code Playgroud)

替换为:

import 'material.dart' hide ModalBottomSheetRoute;

Run Code Online (Sandbox Code Playgroud)