Answers for "how to get display orientation in flutter"

3

flutter set orientation

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  // We need to call it manually,
  // because we going to call setPreferredOrientations()
  // before the runApp() call
  WidgetsFlutterBinding.ensureInitialized();
  
  // Than we setup preferred orientations,
  // and only after it finished we run our app
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((value) => runApp(MyApp()));
}
Posted by: Guest on March-25-2021
1

flutter display widget based on device orientation

build(BuildContext context) {
    final isLandscape = MediaQuery.of(context).orientation ==
        Orientation.landscape; // check if the orientation is landscape
        
        
        // further down your code you can use 'if' or 'ternary' or both
        if (!isLandscape) txListWidget,
            if (isLandscape)
            _ternaryCondition ? _showFirstWidget : _showSecondWidget
            // the above widgets would be in a 'Row' or 'Column'
        }
Posted by: Guest on November-18-2020

Code answers related to "how to get display orientation in flutter"

Browse Popular Code Answers by Language