skip to Main Content

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


  1. Chosen as BEST ANSWER

    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;
    
    

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

    Login or Signup to reply.
  3. 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
    Login or Signup to reply.
  4. 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

    Login or Signup to reply.
  5. 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>AppDataLocalPubCachehostedpub.devmodal_bottom_sheet-2.1.2libsrc

    1. bottom_sheetsmaterial_bottom_sheet.dart
    2. bottom_sheetsbar_bottom_sheet.dart
    3. material_with_modal_page_route.dart
    Login or Signup to reply.
  6. 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.

    Login or Signup to reply.
  7. 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.

    Login or Signup to reply.
  8. use
    modal_bottom_sheet: 3.0.0-pre

    Login or Signup to reply.
  9. Add "modal_bottom_sheet: ^3.0.0-pre" under dependecy_overrides: in pubspec.yaml
    that should solve the problem

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search