【问题标题】:Android Emulator dont respect AppBar shadowColor since Flutter version 2.8.0自 Flutter 2.8.0 版以来,Android 模拟器不尊重 AppBar shadowColor
【发布时间】:2022-01-16 18:38:06
【问题描述】:

从 Flutter 2.8.0 版开始,我在 Android 模拟器上得到了奇怪的 UI 表示(在 Android API 28 和 30 上测试)。模拟器在定义为透明的标题下方绘制阴影。

我们使用 AppBar 的 shadowColor 字段将其设置为 Colors.Transparent。在所有硬件设备(Android/iOS 和 iOS 模拟器)上,这会导致应用栏隐藏阴影。

任何人都可以确认此行为并知道我可以在哪里报告此问题或我可以做些什么来确保这实际上只是一个模拟器问题。到目前为止,我还没有找到显示这种阴影的硬件设备。

示例代码:

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(  
      home: Scaffold(
         appBar: AppBar(
      shadowColor: Colors.transparent,
    ),
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

【问题讨论】:

标签: android flutter dart user-interface emulation


【解决方案1】:

在不同的版本或设备中可能有默认设置,您需要手动设置。

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.transparent, // Colors.red and ...
    statusBarIconBrightness: Brightness.light,
  ));
  runApp(MyApp());
}

【讨论】:

  • 不,那行不通。默认值为阴影/黑色,没关系。但是我们在几个页面上覆盖它。所以我希望在大多数页面上都有阴影,但是在带有搜索栏的页面上,我们将 shadowColor 覆盖为透明,因此我们得到了我们想要的设计,就像在屏幕截图 2 中一样。它一直在工作,直到今天它才停止在模拟器上工作我今天早上将 Flutter 更新到 2.8.0 版本的同时。
猜你喜欢
  • 2022-10-09
  • 1970-01-01
  • 2019-06-23
  • 2012-09-12
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 2019-05-08
  • 2021-02-23
相关资源
最近更新 更多