You can get the heigh or width of a widget in flutter by using layout builder.
Below is the output of a quick example of how you can get those values using layout builder.
![](../../../Uploads/a886a44e-416f-4e7c-888a-733b95b4748e.jpg)
Here is the complete code from main.dart file.
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@
override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(
body: MyLayoutWidget(),
),
);
}
}
class MyLayoutWidget extends StatelessWidget {
const MyLayoutWidget({
super.key,
});
@
override
Widget build(BuildContext context) {
return Center(
child: Container(
color: Colors.grey,
height: 300,
width: 300,
child: LayoutBuilder(
builder: (p0, p1) {
return Center(
child:
Text("height = ${p1.maxHeight}, width = ${p1.maxWidth}"));
},
),
),
);
}
}
Thanks,Srikanth