I used the bottom sheet and I'm using navigator.pop on the button inside the bottom sheet but want to refresh the first screen when calling popup
CodePudding user response:
You just need to pass class name beside the Navigator.
Like this:-
Navigator.pop(context,classname());
CodePudding user response:
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String homeScreenText = "Bottom Sheet not opened";
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(homeScreenText),
const SizedBox(height: 50),
ElevatedButton(
onPressed: () {
showBS();
},
child: const Text("open bottom sheet"),
),
],
),
),
);
}
showBS() {
showModalBottomSheet(
context: context,
builder: (context) {
return SizedBox(
height: 300,
width: double.infinity,
child: Center(
child: ElevatedButton(
onPressed: () {
// Delete item from the list
// then call these
Navigator.pop(context);
setState(() {});
},
child: const Text("Close")),
),
);
},
);
}
}