Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Child widget of CupertinoPageScaffold is behind CupertinoNavigationBar

Tags:

flutter

I'm trying to put contents below a CupertinoNavigationBar.

But the content Widgets are partially covered by the CupertinoNavigationBar.

I don't understand why the child Column is not vertically offset so that the top isn't covered by the CupertinoNavigationBar.

Below is a screenshot, and my code

iOS simulator screenshot

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class PersonalInfoEditor extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: buildNavigationBar(context),
      child: Column(
        children: <Widget>[
          Text('Personal Info'),
          Text('t1'),
        ],
      ),
    );
  }

  CupertinoNavigationBar buildNavigationBar(BuildContext context) {
    return CupertinoNavigationBar(        
        trailing: CupertinoButton(
          child: Text('Save', style: TextStyle(color: CupertinoColors.activeBlue)),
          onPressed: () => Navigator.pop(context),
        ));
  }
}
like image 479
Frank Harper Avatar asked Sep 24 '18 03:09

Frank Harper


1 Answers

Wrap your child inside SafeArea :

        return CupertinoPageScaffold(
              navigationBar: buildNavigationBar(context),
              child: SafeArea(
                child: Column(
                  children: <Widget>[
                    Text('Personal Info'),
                    Text('t1'),
                  ],
                ),
              ),
            );

And don't forget to use CupertinoApp instead of MaterialApp

More info: https://api.flutter.dev/flutter/cupertino/CupertinoPageScaffold-class.html

like image 120
diegoveloper Avatar answered Oct 21 '22 11:10

diegoveloper