1
void main() {
 WidgetsFlutterBinding.ensureInitialized();
 SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
 OrientationSingleton.left = true;
 SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft])
 .then((_) {
 runApp(new MyApp());
 });
}
class MyApp extends StatelessWidget {
 // This widget is the root of your application.
 @override
 Widget build(BuildContext context) {
 return MaterialApp(

Here's my app. I've found some tutorials on how to remove it: flutter remove back button on appbar but it's for an AppBar. I tried making my app work on an AppBar but I get

MediaQuery.of() called with a context that does not contain a MediaQuery.

Because I rely on MediaQuery.of() inside my app.

So, how do I remove the Android back, home and square buttons on Flutter for a MaterialApp?

asked Dec 13, 2020 at 22:44

1 Answer 1

1

As stated in the error message, SystemChrome requires context - a place to call it could be the initState() method of the Widget:

class MyApp extends StatefulWidget {
 const MyApp({ Key key }) : super(key: key);
 @override
 _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
 @override
 void initState() {
 super.initState();
 SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
 OrientationSingleton.left = true;
 SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
 }
 @override
 Widget build(BuildContext context) {
 return MaterialApp(); // your MaterialApp class
 }
}

To hide the system bottom bar on Android, one option could be to call the setEnabledSystemUIOverlays() function with an empty list:

SystemChrome.setEnabledSystemUIOverlays([]);

However, this function is not globally supported on all Android devices.

answered Dec 14, 2020 at 0:14
Sign up to request clarification or add additional context in comments.

2 Comments

Doing these things in initState() did not work but doing them all on main() like I did worked. Also super.initState(); wasn't possible.
I've edited the code to support a Stateful widget, which is required to use the initState() function

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.