Is it possible to set SafeArea once for every route? For now I have no idea how to do that nor found such question. Do I have to put it every screen view?
You can copy paste run full code below
You can use builder
of MaterialApp
code snippet
MaterialApp(
title: 'Builder Demo',
builder: (BuildContext context, Widget child) {
return SafeArea(
child: child,
);
},
full code
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Builder Demo',
builder: (BuildContext context, Widget child) {
return SafeArea(
child: child,
);
},
initialRoute: '/',
routes: {
'/': (context) => FirstScreen(),
'/second': (context) => SecondScreen(),
},
));
}
class FirstScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('First Screen'),
),
body: Center(
child: RaisedButton(
child: Text('Launch screen'),
onPressed: () {
// Navigate to the second screen using a named route.
Navigator.pushNamed(context, '/second');
},
),
),
);
}
}
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Second Screen"),
),
body: Center(
child: RaisedButton(
onPressed: () {
// Navigate back to the first screen by popping the current route
// off the stack.
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}
I had to add scaffold widget as child of safearea because it complained about widget parameter being nullable...
builder: (context, widget) {
return SafeArea(
child: Scaffold(
body: widget,
),
);
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With