I have this annoying issue with the Cupertino widgets. When I create a super simple app setup (scaffold, navbar, one text item) the text seems to start far outside of the viewport.
heres the example:
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Me Title'),
),
child: Column(
children: <Widget>[
Text(
"No matter how short or long your journey to your accomplishment is, if you don't begin you can't get there. Beginning is difficult, but unavoidable!",
style: TextStyle(fontSize: 30),
),
],
),
),
);
}
}
which leads to this result.
The "native" Widgets (MaterialApp, Scaffold, AppBar) lead to this and work just fine:
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Me Title'),
),
body: Column(
children: <Widget>[
Text(
"No matter how short or long your journey to your accomplishment is, if you don't begin you can't get there. Beginning is difficult, but unavoidable!",
Can somebody help out here? This is a bit annoying and I imagine this will f*** up every layout I try to build on it.
Thanks in advance!
if you want to make a custom appbar in a different file so that it can be shared you can just make your new app bar extend it and then pass your customization to super(), in your case your KainAppBar will extend the GradientAppBar like below how MyAppBar extends AppBar.
leading. A widget to display before the toolbar's title. Typically the leading widget is an Icon or an IconButton. Becomes the leading component of the NavigationToolbar built by this widget. The leading widget's width and height are constrained to be no bigger than leadingWidth and toolbarHeight respectively.
Steps. Step 1: Open the next/second page. Step 2: Inside the AppBar, add the automaticallyImplyLeading parameter and set it to false . Step 3: Open the previous/first page.
The solution that worked for me is wrapping the central Column
into a SafeArea
widget (screenshot):
return CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Me Title'),
),
// the SafeArea is new!
child: SafeArea(
// that's unchanged.
child: Column(
// ... etc.
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