【发布时间】:2021-11-24 14:59:32
【问题描述】:
我正在开发一个应用程序,我需要在其中使用安全区域以避免不必要的滑动。虽然我已经在自定义容器中实现了安全区域来呈现屏幕,但它在顶部留下了白边。
当我将这些参数添加到SafeArea() 小部件时,
top: false,
maintainBottomViewPadding: true,
空白消失。但是,应用栏的大小太大。这是最少的代码
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
class DashboardActivity extends StatefulWidget {
@override
_DashboardActivityState createState() => _DashboardActivityState();
}
class _DashboardActivityState extends State<DashboardActivity> {
@override
Widget build(BuildContext context) {
return SafeArea(
//top: false,
//maintainBottomViewPadding: true,
child: Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomInset: true,
appBar: CupertinoNavigationBar(
backgroundColor: Colors.grey,
leading: InkWell(
child: Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
onTap: () => Navigator.pop(context),
),
middle: Text(
"Dashboard",
),
),
body: Text(
'This is an example use of SafeArea',
),
),
);
}
}
这只发生在高显示器上,即纵横比超过 18:9 的显示器上。
谁能告诉我出了什么问题,我该如何解决?
【问题讨论】:
-
用安全区域而不是脚手架包裹身体。
-
SafeArea 的目的是防止操作系统入侵,而不是防止刷卡 - 我认为您在这里混淆了不同的概念。