You can get the size of the screen in flutter using MediaQuery as below.
var screenSize = MediaQuery.of(context).size;
Here is an example of how to use that in your program.
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: MyContainer(),
),
);
}
}
class MyContainer extends StatelessWidget {
const MyContainer({
super.key,
});
@
override
Widget build(BuildContext context) {
var screenSize = MediaQuery.of(context).size;
var screenOrientation = MediaQuery.of(context).orientation;
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 100),
child: Padding(
padding: const EdgeInsets.all(28.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'ScreenSize - $screenSize
',
style: const TextStyle(fontSize: 18.0),
),
const SizedBox(
height: 20,
),
Text(
'Screen Width - ${screenSize.width}',
style: const TextStyle(fontSize: 18.0),
),
const SizedBox(
height: 20,
),
Text(
'Screen height - ${screenSize.height}',
style: const TextStyle(fontSize: 18.0),
),
const SizedBox(
height: 20,
),
Text(
'Screen Orientation - $screenOrientation
',
style: const TextStyle(fontSize: 18.0),
),
],
),
),
),
);
}
}
Thanks,Srikanth