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;
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;
9
Answers
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"
Replace by:
You can use as prefix to import.
then use the package like
mbs.YourClass()
The reason behind the error is says both
material/bottom_sheet.dart
andbottom_sheet_route
exports theModalBottomSheetRoute
.In order to fix this issue we have to hide one of the
ModalBottomSheetRoute
. since we need this to be imported frombottom_sheet_route
we need to hide it frommaterial
This is the way that we can fix,
Relace
import 'package:flutter/material.dart'
withimport '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
There’s already a hot fix on the package
add this in the pubspec.yaml
It has already been pull requested but it has not been merged yet
In order to fix this issue we have to hide one of the
ModalBottomSheetRoute
. since we need this to be imported frombottom_sheet_route
we need to hide it frommaterial
This is the way that we can fix,
Relace
with
in the following files.
Basic Path:
Users<username>AppDataLocalPubCachehostedpub.devmodal_bottom_sheet-2.1.2libsrc
bottom_sheetsmaterial_bottom_sheet.dart
bottom_sheetsbar_bottom_sheet.dart
material_with_modal_page_route.dart
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.
If you’re using the library package
country_code_picker
in your project change it withcountry_picker
. The package uses an old version of modal_bottom_sheet and is conflicting.use
modal_bottom_sheet: 3.0.0-pre
Add "modal_bottom_sheet: ^3.0.0-pre" under dependecy_overrides: in pubspec.yaml
that should solve the problem