Reputation:
I created a custom dialogBox but when I add 2 buttons at the bottom I still have a padding, how can I remove it?
This is my code
contentBox(context) {
return ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.all(20),
child: Column(
children: [
Text(
widget.title,
style: TextStyle(fontSize: 23, fontWeight: FontWeight.w600),
textAlign: TextAlign.center,
),
SizedBox(height: 15),
Text(
widget.descriptions,
style: TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
],
),
),
Row(
children: <Widget>[
Expanded(
child: RaisedButton(
child: Text('Reject'),
onPressed: () => null,
),
),
Expanded(
child: RaisedButton(
color: Colors.amber,
child: Text('Approve'),
onPressed: () => null,
),
),
],
),
],
),
),
);
}
Result :
PS: if there are optimizations, please tell me as I'm beginning in flutter
Upvotes: 1
Views: 2330
Reputation: 891
This is because RaisedButton
have a fixed height. Wrap the RaisedButton
inside a Container
widget and give it a height value. Like this and it should be fine
Expanded(
child: Container(
height: 48,
child: RaisedButton(
child: Text('Reject'),
onPressed: () => null,
),
),
),
Do this for both of your buttons This is the output:
Also if you want to create an alert box it is better to use flutter build in widgets like AlertDialog
if you want iOS styled alert box then you can use CupertinoAlertDialog
AlertDialog
's are very well explained in this video
Upvotes: 1
Reputation: 7973
RaisedButton have some default padding, so you need to create a custom button like this :
class CustomButton extends StatelessWidget {
const CustomButton({
Key key,
this.backgroundColor,
this.child,
}) : super(key: key);
final child;
final Color backgroundColor;
@override
Widget build(BuildContext context) {
return Container(
height: 40,
child: Material(
color: backgroundColor,
child: InkWell(
onTap: () {},
child: Container(
alignment: Alignment.center,
child: child,
),
),
),
);
}
}
Now use it in your code, replace your row with this
Row(
children: <Widget>[
Expanded(
child: CustomButton(
backgroundColor: Colors.grey[100],
child: Text('Reject'),
),
),
Expanded(
child: CustomButton(
backgroundColor: Colors.amber,
child: Text('Approve'),
),
),
],
),
Upvotes: 1