how can i controll the default pop property of bottom sheet.Like I want to asign a value to a variable when showModalBottomSheet is popped .I have tried to do with controllers
Asked
Active
Viewed 343 times
-1
-
Can you show some code of yours – Risheek Mittal Dec 21 '22 at 09:51
5 Answers
0
Why don't you just do :
showModalBottomSheet(
context: context,
builder: (context) {
var a = "desired value";
return Widget;

Risheek Mittal
- 1,077
- 2
- 18
0
you can trigger when the bottom sheet is popped/dismissed with an AnimationController
like this:
in your StatefulWidget
's State
:
late AnimationController _controller;
@override
void initState() {
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
);
_controller.addListener(() {
if (_controller.isDismissed) {
print("dismissed");
}
});
super.initState();
}
@override
void dispose() {
_controller.dispose;
super.dispose();
}
in your showModalBottomSheet
:
showModalBottomSheet(
context: context,
builder: (context) => Container(),
transitionAnimationController: _controller, // assign the controller
);

Gwhyyy
- 7,554
- 3
- 8
- 35
0
You can set isDismissible: false,
and than add one button (Close button) on tap of button, you have to do your code and pop the bottomSheet.
showModalBottomSheet(
isScrollControlled: true,
isDismissible: false,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(15),
),
),
context: context,
builder: (context) {
return SizedBox(
height:
MediaQuery.of(context).size.height * (0.6),
child: Padding(
padding: const EdgeInsets.only(top: 15),
child: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
InkWell(
onTap: () {
// Add your code here. which you want to perform before closing bottomSheet
Navigator.pop(context);
},
child: const Icon(Icons.close)),
InkWell(
onTap: () {},
child: const Text(
"Reset",
)),
],
),
const SizedBox(height: 15),
//Other widgets of bottomSheet
Container(
height:
MediaQuery.of(context).size.height * (0.5),
color: Colors.amber,
)
],
),
),
);
});

Khyati Modi
- 630
- 1
- 9
- 19
0
thanks for your help
I solved the problem with WillPopScope
popfunction() {
SelectedValue = tempValue;
Navigator.pop(context, true);
}
onWillPop: () async {
return popfunction() ?? false;
},

sks
- 1
- 1
0
if you want to click on the back button
, showModalBottomSheet
closed ,
I suggest used useRootNavigator: true
in showModalBottomSheet

EbrahimAghdasi
- 61
- 5