Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Cupertino appbar hides screen space

Tags:

ios

flutter

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!

like image 907
flypenguin Avatar asked Jan 05 '20 19:01

flypenguin


People also ask

How can I have my AppBar in a separate file in flutter?

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.

What is leading in AppBar flutter?

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.

How do I remove leading from AppBar flutter?

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.


1 Answers

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.
like image 150
flypenguin Avatar answered Oct 12 '22 00:10

flypenguin