Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'. ../…/src/material_with_modal_page_route.dart:4 import '../modal_bottom_sheet.dart'; ^^^^^^^^^^^^^^^^^^^^^
: Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'. ../…/bottom_sheets/material_bottom_sheet.dart:28 .push(ModalBottomSheetRoute( ^^^^^^^^^^^^^^^^^^^^^ : Error: A value of type 'Object?' can't be returned from an async function with return type 'Future<T?>'. ../…/bottom_sheets/material_bottom_sheet.dart:50
'Object' is from 'dart:core'.
'Future' is from 'dart:async'. return result;
^
: Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'. ../…/bottom_sheets/bar_bottom_sheet.dart:102 .push(ModalBottomSheetRoute( ^^^^^^^^^^^^^^^^^^^^^ : Error: A value of type 'Object?' can't be returned from an async function with return type 'Future<T?>'. ../…/bottom_sheets/bar_bottom_sheet.dart:125
- 'Object' is from 'dart:core'.
- 'Future' is from 'dart:async'. return result; ^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
Where: Script '/Users/vannak/Documents/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1151
What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command '/Users/vannak/Documents/flutter/bin/flutter'' finished with non-zero exit value 1
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
- Get more help at https://help.gradle.org
BUILD FAILED in 12m 31s Exception: Gradle task assembleDebug failed with exit code 1
CodePudding user response:
I had a same issue after upgrading flutter new version 3.7.0 yesterday. It is caused by using ModalBottomSheet package from pub.dev.
You have to add below to your pubspec.yaml file.
dependency_overrides:
modal_bottom_sheet:
git:
url: https://github.com/danReynolds/modal_bottom_sheet.git
path: modal_bottom_sheet
DO NOT DELETE your modal_bottom_sheet and just COPY and PASTE below your dependencies.
CodePudding user response:
Firstly, let's understand this type of issue. If you notice the error
ModalBottomSheetRoute
is imported from bothpackage:flutter/src/material/bottom_sheet.dart
andpackage:modal_bottom_sheet/src/bottom_sheet_route.dart
.
So it is telling you are getting ModalBottomSheetRoute
from two different packages.
Now if you like to use material bottomSheet, you can remove this import
package:modal_bottom_sheet/modal_bottom_sheet.dart
.
but If you like to use this package class. You can do
- using
as
prefix
import 'package:flutter/material.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart' as modalSheet;
.....
modalSheet.ModalBottomSheetRoute(
builder: (context) =>
- or you can hide
ModalBottomSheetRoute
of material
import 'package:flutter/material.dart' hide ModalBottomSheetRoute;
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';