I'm very new to Flutter so please bear with me. I wonder whether I can retrieve and use the width of a widget inside the build
method. The RoundButton widget below illustrates two cases where having the width could be useful:
- to display the width as text
- to create a circular Container, I could use
radius=width/2
(Note: I know this can be done usingshape: BoxShape.circle
so it's just an example where having the width could be useful)
So I have two questions:
- is it possible to get the width of the widget
- if so, can you outline how this can be done?
class RoundButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: Colors.white),
child: Container (
decoration: BoxDecoration(
border: Border.all(width: 6, color: Colors.green),
borderRadius: const BorderRadius.all(const Radius.circular(**width**/2)),
//shape: BoxShape.circle,
),
child: Center (
child: Text(
"w="+**width**.toString(),
),
)
));
}
}