I want to center a Text Widget vertically inside a container with a fixed height. But, I want to keep the width of the container dynamic which will change according to the length of the Text. I tried using the Center and Align over the Text widget and the parent container widget, but it expanded along the whole width. Point to be noted Container is residing inside another Column.
import 'package:flutter/material.dart';
class CustomIconButton extends StatelessWidget {
final String name;
final Function()? onTap;
final TextStyle? textStyle;
final BorderRadius? borderRadius;
const CustomIconButton({
Key? key,
required this.name,
this.onTap,
this.textStyle,
this.borderRadius,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * 0.2,
decoration: BoxDecoration(
color: Color(0xFFE2D9FB),
borderRadius:
borderRadius ?? const BorderRadius.all(Radius.circular(15)),
),
child: Text(
name,
style: textStyle,
),
);
}
}
I don't want to use vertical padding to center the Text