The problem is that many people suggest wrapping your bottom sheet with a Scaffold widget, but that’s an issue if you have isScrollControlled: true and ListView.builder with shrinkwrap inside the bottom sheet, with this approach your listview will not shrinkwrap
So a solution i came up with:
/// Create your global key for scaffold messanger, it **must not**
/// be used in your MaterialApp widget to prevent building errors
final GlobalKey<ScaffoldMessengerState> snackbarKey =
GlobalKey<ScaffoldMessengerState>();
/// Then create an overlay entry, place it somewhere
/// in you app (Or you can just copy this directly into the stack below)
final OverlayEntry scaffoldOverylayForSnackbar = OverlayEntry(
builder: (_) {
return Positioned(
child: IgnorePointer(
child: ScaffoldMessenger(
key: snackbarKey,
child: const Scaffold(
backgroundColor: Colors.transparent,
primary: false,
resizeToAvoidBottomInset: false,
body: SizedBox.shrink(),
),
),
),
);
},
);
/// Now find your MaterialApp app, add builder inside it and create a
/// stack that display our overlay entry above any screen we currently render
MaterialApp(
builder: (_, child) {
return Stack(
children: <Widget>[
child!,
Overlay(initialEntries: [scaffoldOverylayForSnackbar]),
],
);
},
);
That’s it, now you can call a snackbar above literally any widget in your app without loosing that shrinkwrap feature
snackbarKey.currentState?.showSnackBar(
SnackBar(
behavior: SnackBarBehavior.floating,
content: GestureDetector(
onTap: () {
print('213');
},
child: Container(
color: Colors.red,
width: 200,
height: 100,
),
),
),
);