← Technology Archive

Historical archive

Useful Flutter App Configuration: Orientation and Debug Banner

Two small Flutter configuration examples for locking device orientation and hiding the debug banner.

Lock the app to portrait or landscape

Call SystemChrome.setPreferredOrientations() before runApp():

void main() async {
  await SystemChrome.setPreferredOrientations([
    // Keep the app in portrait mode.
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,

    // Or keep the app in landscape mode.
    // DeviceOrientation.landscapeLeft,
    // DeviceOrientation.landscapeRight,
  ]);

  runApp(new MyApp());
}

Choose either the portrait values or the landscape values rather than enabling both groups.

Hide the debug banner

Set debugShowCheckedModeBanner to false on MaterialApp:

void main() {
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyApp(),
    ),
  );
}