I have a modal bottom sheet on my page, whit 2 radio buttons. Radio button class is inside the same page. Modal bottom sheet cannot reach selected value from radio button class.
In this case, anything will happens when i click the ElevatedButton
.
If i delete if (value ==2)
, the function will execute only the divide operation.
How can i reach the selected value
?
This is the modal button to execute once radio button is selected:
ElevatedButton(onPressed: (){
if (value == 1){
multiply();
Navigator.of(context).pop();
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => result()));
}else if (value ==2){
divide();
Navigator.of(context).pop();
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => result()));
};
This is the radio button class:
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int value = 0;
Widget CustomRadioButton(String text, int index) {
return OutlinedButton(
onPressed: () {
setState(() {
value = index;
});
},
child: Text(
text,
style: TextStyle(
color: (value == index) ? Colors.white : Colors.black,
),
),
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
primary: Colors.white,
backgroundColor: (value == index)?Colors.deepOrange: Colors.white,
),
);
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
CustomRadioButton("Multiply", 1),
CustomRadioButton("Divide", 2),
],
);
}