Reputation: 87
My goal is to achieve the dialog like the below image. I want that when I press the cancel or confirm button in the dialog, the background color of the cancel and confirm buttons should change.
I have designed this dialog the same as but only I am not able to change the cancel or confirm container background color when I click on it. my designed dialog is below here.
Please help me, anyone, how can I achieve this.
class MyHomePage1 extends StatefulWidget {
@override
State createState() {
return MyHomePage1State();
}
}
class MyHomePage1State extends State<MyHomePage1> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: InkWell(
onTap: (){
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)), //this right here
child: Container(
height: 200,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.confirmation,
style: TextStyle(
color: AppColors.orange.withOpacity(.65),
//fontSize: DeviceSize.width(context) / 26,
fontSize: 24,
fontFamily: "Poppins",
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.youAreAboutTO,
style: TextStyle(
color: AppColors.grey30,
//fontSize: DeviceSize.width(context) / 26,
fontSize: 12,
fontFamily: "Gilroy-Bold"),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.add1Stamp,
style: TextStyle(
color: AppColors.grey50,
//fontSize: DeviceSize.width(context) / 26,
fontSize: 12,
fontFamily: "Poppins"),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.redeem1FreeSet,
style: TextStyle(
color: AppColors.grey50,
//fontSize: DeviceSize.width(context) / 26,
fontSize: 12,
fontFamily: "Poppins"),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 25,right: 25,top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap:(){
setState(() {
});
},
child: Container(
alignment: Alignment.center,
//color: AppColors.blueColorNew,
//margin: EdgeInsets.only(bottom: 20),
width: 100,
height: 32,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: AppColors.white,
border: Border.all(color: AppColors.orange)
),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Text(
"Cancel",
style: TextStyle(
fontFamily: "Gilroy-Bold",
color:AppColors.orange),
),
),
),
),
InkWell(
onTap:(){
setState(() {
});
},
child: Container(
alignment: Alignment.center,
//color: AppColors.blueColorNew,
//margin: EdgeInsets.only(bottom: 20),
width: 100,
height: 32,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: AppColors.white,
border: Border.all(color: AppColors.orange,
)
),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Text(
"Confirm",
style: TextStyle(
fontFamily: "Gilroy-Bold",
color:AppColors.orange),
),
),
),
)
],
),
),
],
),
),
),
);
});
},
child: Container(
height: 50,
width: 100,
color: Colors.orange,
child: Center(
child: Text("Click on",
style: TextStyle(
color: Colors.white
),),
),
),
),
)
);
}
}
Upvotes: 0
Views: 709
Reputation: 63779
You need to use StatefulBuilder
to update on dialog.
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
bool isCancelBtnTappeed = false;
bool isConfirmBtnTappeed = false;
return StatefulBuilder(
builder: (context, setStateSB) {
return Dialog(
shape: RoundedRectangleBorder(
/// ........
GestureDetector(
onTap: () {
setStateSB(() {
isCancelBtnTappeed = true;
});
},
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(5),
color: isCancelBtnTappeed
? Colors.red
: Colors.white,
Upvotes: 2