I’m using showModalBottomSheet
with DraggableScrollableSheet
, I need to listen to scrolling of the bottom sheet (when scrolling to close the bottom sheet), it’s working fine when the scroll is from the body (DraggableScrollableSheet
/ SingleChildScrollView
widget) but when the scroll is from the background (BackdropFilter
widget) it doesn’t work, here’s an example of the problem:
import 'dart:ui';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
final DraggableScrollableController draggableScrollableController = DraggableScrollableController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(),
floatingActionButton: FloatingActionButton(
onPressed: () => _showBs(context),
tooltip: 'Show bs',
child: const Icon(Icons.play_arrow),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
Widget backgroundWidget() {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
height: double.maxFinite,
width: double.maxFinite,
color: Colors.blue.withOpacity(0.2),
),
);
}
void _showBs(BuildContext context) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
clipBehavior: Clip.none,
backgroundColor: Colors.transparent,
builder: (context) {
return NotificationListener(
onNotification: (notification) {
print('Working only when scroll from body');
return true;
},
child: Stack(
alignment: Alignment.bottomCenter,
clipBehavior: Clip.none,
children: [
backgroundWidget(),
draggableWidget(),
],
),
);
},
);
}
Widget draggableWidget() {
return DraggableScrollableSheet(
expand: false,
maxChildSize: 0.5,
minChildSize: 0.0,
initialChildSize: 0.5,
controller: draggableScrollableController,
builder: (BuildContext context, ScrollController scrollController) {
return SingleChildScrollView(
controller: scrollController,
child: Container(
color: Colors.red,
width: double.maxFinite,
height: 500,
),
);
},
);
}
}
I tried a lot of different ways to find a solution but nothing