How to get screen orientation in flutter?

This Article is posted by seven.srikanth at 11/14/2022 4:38:41 PM




You can get the size of the screen in flutter using MediaQuery as below.
  var screenOrientation = MediaQuery.of(context).orientation;
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 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: [
              const SizedBox(
                height: 20,
              ),
              Text(
                'Screen Orientation - $screenOrientation',
                style: const TextStyle(fontSize: 18.0),
              ),
            ],
          ),
        ),
      ),
    );
  }
}



Tags: screen orientation in flutter








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com