Ios 为什么要颤振';s CupertinoNavigationBar与CUPERTINOPAGE脚手架中的儿童重叠?

Ios 为什么要颤振';s CupertinoNavigationBar与CUPERTINOPAGE脚手架中的儿童重叠?,ios,flutter,flutter-cupertino,Ios,Flutter,Flutter Cupertino,我有以下小部件树: @override Widget build(BuildContext context) { final double topMargin = Platform.isAndroid ? 0 : 105; // TODO: (why margin on iOS?) final double interMargin = Platform.isAndroid ? 0 : 10; final body = Column(children: <Widg

我有以下小部件树:

@override
  Widget build(BuildContext context) {
    final double topMargin = Platform.isAndroid ? 0 : 105; // TODO: (why margin on iOS?)
    final double interMargin = Platform.isAndroid ? 0 : 10;
    final body = Column(children: <Widget> [
      Padding(
        padding: EdgeInsets.only(left: 10, right: 10, top: topMargin),
        child: Platform.isAndroid // url
        ? TextField(
            decoration: new InputDecoration(hintText: 'Host'),
            maxLines: 1,
            autofocus: true,
            textInputAction: TextInputAction.next,
            controller: _hostController)
        : CupertinoTextField(
            maxLines: 1,
            autofocus: true,
            textInputAction: TextInputAction.next,
            controller: _hostController)),
      Padding(
        padding: EdgeInsets.only(left: 10, top: interMargin, right: 10),
        child: Platform.isAndroid // port
          ? TextField(
              decoration: new InputDecoration(hintText: 'Port'),
              keyboardType: TextInputType.number,
              maxLines: 1,
              controller: _portController)
          : CupertinoTextField(
              keyboardType: TextInputType.number,
              maxLines: 1,
              controller: _portController)),
      Platform.isAndroid
        ? RaisedButton(child: Text('OK'), onPressed: () => _onInputFinished())
        : CupertinoButton(child: Text('OK'), onPressed: () => _onInputFinished())
    ]);
    return Platform.isAndroid
      ? Scaffold(
          appBar: AppBar(title: Text('Server connection')),
          body: body)
      : CupertinoPageScaffold(
          navigationBar: CupertinoNavigationBar(middle: Text('Server connection')),
          child: body);
  }

如果我不添加它,则“CupertinaVigationBar”将重叠子项:

我错过了什么


以下是整个项目。

您只需要在您孩子的小部件上实现“安全区域”小部件(而不是上边距),以避免被Cupertino导航栏重叠

CupertinoPageScaffold(
   navigationBar: CupertinoNavigationBar(),
   child: SafeArea(
            child: [Your widgets] // your children widgets 
        ),
)

您必须为
CupertinoApp
设置
barBackgroundColor
。或者为
cupertinaviationbar
设置
backgroundColor
,也可以解决此问题

类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回CupertinoApp(
标题:“颤振应用程序”,
主题:CupertinoThemeData(
barBackgroundColor:CupertinoColors.white,
),
主页:我的主页(标题:“颤振应用程序”),
);
}
}

CupertinoPageScaffold(
导航栏:CupertinoNavigationBar(
中间:文本('MyStackPageState'),
背景颜色:CupertinoColors.white,
),
子级:容器(),
}
根据“一个小部件,通过足够的填充插入其子部件以避免操作系统的入侵”。在我的例子中,预期该区域被另一个小部件占用(
CuperinoNavigationBar
,这是故意的).所以使用
SafeArea
看起来像是一个解决办法。对此有何想法?在本用例的官方文档/来源中有没有使用
SafeArea
CupertinoPageScaffold(
   navigationBar: CupertinoNavigationBar(),
   child: SafeArea(
            child: [Your widgets] // your children widgets 
        ),
)