Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.
import 'material.dart' hide ModalBottomSheetRoute;

- 5,179
- 10
- 35
- 56

- 491
- 1
- 5
- 8
9 Answers
The reason behind the error is says both material/bottom_sheet.dart
and bottom_sheet_route
exports the ModalBottomSheetRoute
.
'ModalBottomSheetRoute' is imported from both
'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.
In order to fix this issue we have to hide one of the ModalBottomSheetRoute
. since we need this to be imported from bottom_sheet_route
we need to hide it from material
This is the way that we can fix,
Relace
import 'package:flutter/material.dart'
with
import 'package:flutter/material.dart' hide ModalBottomSheetRoute;
in the following files.
/Users/<usename>/.pub-cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/material_with_modal_page_route.dart
/Users/<usename>/.pub-cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/bar_bottom_sheet.dart
/Users/<usename>/.pub-cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/material_bottom_sheet.dart

- 474
- 4
- 13
-
This doesn't work for me. – Peter Jan 20 '23 at 15:33
-
1THIS NOT WORKS. – HappyCoding Jan 26 '23 at 01:06
-
Check your project dependency and remove the modal_bottom_sheet plugin which used it. It solved my issue. – abdul rehman Jan 27 '23 at 06:05
-
2this solution works. hopefully it will be temporary... – ykonda Feb 16 '23 at 18:10
-
1Still WORKING... Thanks for Sharing... :) – Muhammad Hassan Jul 11 '23 at 15:20
There's already a hot fix on the package
add this in the pubspec.yaml
modal_bottom_sheet:
git:
url: https://github.com/followthemoney1/modal_bottom_sheet.git
ref: main
path: modal_bottom_sheet
It has already been pull requested but it has not been merged yet

- 666
- 6
- 20

- 246
- 1
- 6
-
link to MR: https://github.com/jamesblasco/modal_bottom_sheet/issues/311 – Cyber Jan 26 '23 at 12:48
use
modal_bottom_sheet: 3.0.0-pre
This goes under your dependency_overrides:
in the pubspec.yaml
file such as:
dependency_overrides:
modal_bottom_sheet: ^3.0.0-pre

- 2,405
- 1
- 25
- 40

- 161
- 1
- 3
this error occur due to new flutter SDK update
Here is a Migration Guide for flutter 3.7 or later
modal_bottom_sheet:
Update to modal_bottom_sheet: ^3.0.0-pre
change
import 'packa ge:flutter/material.dart'
toimport 'package:flutter/material.dart' hide ModalBottomSheetRoute;
in every file, you are using the bottom sheet plugin.
Like this:
upvote the answer if it's helpful.

- 926
- 6
- 16
-
2but I am not using modal_bottom_sheet in my project and i still have this issue – Duck Dodgers May 08 '23 at 23:48
-
maybe some of your package are using modal_bottom_sheet as dependency – Mashood .H May 09 '23 at 14:14
If you're using the library package country_code_picker
in your project change it with country_picker
. The package uses an old version of modal_bottom_sheet and is conflicting.

- 1,225
- 10
- 14
The problem there is both class named "ModalBottomSheetRoute" found in flutter material and plugin "modal_bottom_sheet"
this happened with me when try to use flutter v3.7.0 beta sdk
#Fix this issue
Search for any file import"material.dart" at plugin "modal_bottom_sheet"
import 'material.dart';
Replace by:
import 'material.dart' hide ModalBottomSheetRoute;

- 491
- 1
- 5
- 8
-
1Abdullah Mahmoud i tried this solution but its not working for me. The problem is still there. – Ijlal Hussain Dec 28 '22 at 11:07
-
In order to fix this issue we have to hide one of the ModalBottomSheetRoute
. since we need this to be imported from bottom_sheet_route
we need to hide it from material
This is the way that we can fix,
Relace
import 'package:flutter/material.dart'
with
import 'package:flutter/material.dart' hide ModalBottomSheetRoute;
in the following files.
Basic Path: \Users\<username>\AppData\Local\Pub\Cache\hosted\pub.dev\modal_bottom_sheet-2.1.2\lib\src
\bottom_sheets\material_bottom_sheet.dart
\bottom_sheets\bar_bottom_sheet.dart
\material_with_modal_page_route.dart

- 117
- 1
- 3
You can use as prefix to import.
import 'package:modal_bottom_sheet/src/bottom_sheet_route.dart' as mbs;
then use the package like mbs.YourClass()

- 54,221
- 7
- 29
- 56
-
I recommend using suggested fix in the official merge request instead of changing your code with a soon obsolete solution. – Cyber Jan 26 '23 at 12:54
-
-
Why would i change all the code with a prefix which would require refactor after the fix has been implemented. – Cyber Jan 28 '23 at 12:37