Abdallah Mahmoud
Abdallah Mahmoud

Reputation: 937

Error: 'ModalBottomSheetRoute' is imported from both

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;

Upvotes: 31

Views: 30439

Answers (11)

Vaibhav Bhus
Vaibhav Bhus

Reputation: 1

if ypu are using country_code_picker package then upgrade it or any package that use modal_bottom_sheet upgrade it if yoou don't want to upgrade simply add below lines in pubspec file

dependency_overrides:
  modal_bottom_sheet: ^3.0.0-pre 

Upvotes: 0

in addition to @Texv said,

if you are using smart_country_code_picker: ^0.0.2 also update to country_code_picker: ^3.0.0

it will solve the problem

Upvotes: 0

Amjad Aldya
Amjad Aldya

Reputation: 281

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

Upvotes: 28

David Dut
David Dut

Reputation: 11

Add modal_bottom_sheet: ^3.0.0-pre under dependecy_overrides: in pubspec.yaml that will solve the problem

Upvotes: 1

Mashood .H
Mashood .H

Reputation: 1782

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' to import 'package:flutter/material.dart' hide ModalBottomSheetRoute; in every file, you are using the bottom sheet plugin.

Like this:

enter image description here

upvote the answer if it's helpful.

Upvotes: 16

Texv
Texv

Reputation: 1894

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.

Upvotes: 10

Abdalmuneim Mahmoud
Abdalmuneim Mahmoud

Reputation: 167

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

  1. \bottom_sheets\material_bottom_sheet.dart
  2. \bottom_sheets\bar_bottom_sheet.dart
  3. \material_with_modal_page_route.dart

Upvotes: 2

jgamesl
jgamesl

Reputation: 296

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

Upvotes: 17

Radika Dilanka
Radika Dilanka

Reputation: 592

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.

  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

Upvotes: 29

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63749

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()

Upvotes: 0

Abdallah Mahmoud
Abdallah Mahmoud

Reputation: 937

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;

Upvotes: 5

Related Questions