为什么 Scaffold 在 Android 中没有填充屏幕底部?

发布于 2025-01-10 16:22:47 字数 721 浏览 4 评论 0原文

我是颤振新手。我的屏幕没有其他任何东西——只有一个脚手架。不知道为什么,它没有填满整个屏幕。

输入图片此处描述

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: MyHomePage(),
    ),
  );
}

class MyHomePage extends StatefulWidget {

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _incrementCounter() {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    
    return Scaffold(
          backgroundColor: Colors.green,

          
    );
  }
}

I am new to Flutter. My screen don't have anything else - only a scaffold. I don't know why, it is not filling the entire screen.

enter image description here

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      home: MyHomePage(),
    ),
  );
}

class MyHomePage extends StatefulWidget {

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _incrementCounter() {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    
    return Scaffold(
          backgroundColor: Colors.green,

          
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盛夏尉蓝 2025-01-17 16:22:47

我认为这是因为底部区域是 Android 导航栏的一部分,因此您需要显式更改其背景:

void main() {
  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(systemNavigationBarColor: Colors.green),
  );

  runApp(
    MaterialApp(
      home: MyHomePage(),
    ),
  );
}

有关更多信息,请检查 文档

I think this is because the bottom area is a part of the Android navigation bar, hence you need to change the background of it explicitly:

void main() {
  SystemChrome.setSystemUIOverlayStyle(
    const SystemUiOverlayStyle(systemNavigationBarColor: Colors.green),
  );

  runApp(
    MaterialApp(
      home: MyHomePage(),
    ),
  );
}

For more information, check the documentation.

浅沫记忆 2025-01-17 16:22:47

您应该考虑使用 SafeArea Widget,它用于覆盖或不覆盖屏幕的顶部和底部:
https://api.flutter.dev/flutter/widgets/SafeArea-class。 html

底部是你关心的:

SafeArea(
  child: Scaffold(),
  bottom: false/true,
)

它知道当前上下文 MediaQuery 和 View Padding

You should consider using the SafeArea Widget, it's used to cover the top and bottom of the screen or not :
https://api.flutter.dev/flutter/widgets/SafeArea-class.html

The bottom is what you care :

SafeArea(
  child: Scaffold(),
  bottom: false/true,
)

It's aware of the current context MediaQuery and the View Padding

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文