如何在不拖尾的情况下显示 Flutter AppBar space
How to show Flutter AppBar without trailing space
当我将 AppBar 添加到我的程序时,它在 AppBar 下显示一个空白 space,这实际上是一个空白行。当我删除 AppBar 时,space 行不存在。 space 行非常引人注目,破坏了应用程序的外观。有没有一种方法可以让我在没有 space 并且不使用我自己的小部件来实现它的情况下拥有 AppBar?
代码:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Calculator',
home: Scaffold(
appBar: AppBar(title: Text("Flutter Calculator")),
body: (HomeScreen())));
}
}
问题似乎是由添加安全区域而没有 "top:" 设置为 false 引起的。希望这是解决方案。不确定为什么 SafeArea 默认显示为添加填充。我本来认为添加一个填充更好 属性,但我知道什么,我只是在学习 Flutter?
相关代码如下,现在看来问题已经解决了。我之前展示了一个最小的 AppBar 来减少代码量来说明问题。现在显示完整的 AppBar。似乎只是设置 AppBar 高度的复杂方法,但我知道什么?然而,作为 Flutter 初学者,我花了几个小时才找到我希望的解决方案。然而,要点在上面的第 1 段中。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(35.0),
child: AppBar(
automaticallyImplyLeading: false, // hides leading widget
centerTitle: true,
title: Text("Flutter Calculator by Brian"))),
body: (HomeScreen())));
}
}
class HomeScreen extends StatefulWidget {
@override
HomeScreenState createState() => new HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {`
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
top: false,
bottom: false,
child: Material(
当我将 AppBar 添加到我的程序时,它在 AppBar 下显示一个空白 space,这实际上是一个空白行。当我删除 AppBar 时,space 行不存在。 space 行非常引人注目,破坏了应用程序的外观。有没有一种方法可以让我在没有 space 并且不使用我自己的小部件来实现它的情况下拥有 AppBar?
代码:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Calculator',
home: Scaffold(
appBar: AppBar(title: Text("Flutter Calculator")),
body: (HomeScreen())));
}
}
问题似乎是由添加安全区域而没有 "top:" 设置为 false 引起的。希望这是解决方案。不确定为什么 SafeArea 默认显示为添加填充。我本来认为添加一个填充更好 属性,但我知道什么,我只是在学习 Flutter?
相关代码如下,现在看来问题已经解决了。我之前展示了一个最小的 AppBar 来减少代码量来说明问题。现在显示完整的 AppBar。似乎只是设置 AppBar 高度的复杂方法,但我知道什么?然而,作为 Flutter 初学者,我花了几个小时才找到我希望的解决方案。然而,要点在上面的第 1 段中。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(35.0),
child: AppBar(
automaticallyImplyLeading: false, // hides leading widget
centerTitle: true,
title: Text("Flutter Calculator by Brian"))),
body: (HomeScreen())));
}
}
class HomeScreen extends StatefulWidget {
@override
HomeScreenState createState() => new HomeScreenState();
}
class HomeScreenState extends State<HomeScreen> {`
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
top: false,
bottom: false,
child: Material(