Home > database >  Modal Bottom sheet route issue in flutter 3.7.0
Modal Bottom sheet route issue in flutter 3.7.0

Time:01-26

I have upgraded my flutter version from 3.3.10 to 3.7.0 and now getting the following error.

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

I tried to follow this Error: 'ModalBottomSheetRoute' is imported from both but solutions didn't work for me.

CodePudding user response:

This error occurs because you have two different versions of the ModalBottomSheetRoute class being imported into your project, one from the Flutter Material package and the other from the modal_bottom_sheet package.

Try this soltution

import 'package:modal_bottom_sheet/src/bottom_sheet_route.dart' as customBottomSheet;

use customBottomSheet wherever you need.

CodePudding user response:

   import 'package:modal_bottom_sheet/src/bottom_sheet_route.dart' as mymodal;
 

mymodal.showModalBottomSheet(
                context: context,
                // color is applied to main screen when modal bottom screen is displayed
                barrierColor: Colors.greenAccent,
                //background color for modal bottom screen
                backgroundColor: Colors.yellow,
                //elevates modal bottom screen
                elevation: 10,
                // gives rounded corner to modal bottom screen
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10.0),
                ),
                builder: (BuildContext context) {
                  // UDE : SizedBox instead of Container for whitespaces
                  return SizedBox(
                    height: 200,
                    child: Center(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: const <Widget>[
                          Text('GeeksforGeeks'),
                        ],
                      ),
                    ),
                  );
                },
              );
  • Related