The dialog widget is stateless widget, so I Thought I could make the Dialog to Stateful widget by using statefulbuilder. So I made the code like this
import 'package:flutter/material.dart';
class TestDialog extends StatefulWidget {
const TestDialog({Key? key}) : super(key: key);
@override
State<TestDialog> createState() => _TestDialogState();
}
class _TestDialogState extends State<TestDialog> {
int i=0;
Future<void> showpopup (context) async {
showDialog(
context: context,
builder: (context){
return Dialog(
child: StatefulBuilder(builder: (BuildContext context, StateSetter setstate){
return Column(
children: [
Row(
children: [
GestureDetector(
child: Container(
child : Text(i.toString())
),
onTap: (){
setState(() {
i++;
});
},
)
],
)
],
);
}),
);
}
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('stateful dialog'),
),
body: Column(
children: [
GestureDetector(
child: Text('yeah'),
onTap: (){
showpopup(context);
},
)
],
),
);
}
}
but in the dialog, the number doesn't change. After I close the dialog and open again, now it shows the change. How can I use statefulbuilder properly? Or is statefulbuilder not valid on this code?
I tried the Future<void> to void but it is as same as first.