The data coming from the view model is supposed to be listened in the view, and the setState make it rebuild.
The refresh is correct with the modal widget (secondChildWidget) but it’s not updating with the one inside the onTap closure (firstChildWidget).
How to make it update ?
Both are stateless.
This is my code:
class MyView extends StatefulWidget {
const MyView({super.key});
@override
State<MyView> createState() => _MyViewState();
}
class _MyViewState extends State<MyView> {
final ViewModel viewModel = ViewModel();
String item = "";
@override
void initState() {
super.initState();
viewModel.item.listen((value) {
setState(() {
item = value;
});
});
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return firstChildWidget(item);
});
},
child: secondChildWidget(item),
);
}
}