【问题标题】:Black bar on top of AppBar FlutterAppBar Flutter 顶部的黑条
【发布时间】:2019-07-02 11:53:18
【问题描述】:

我正在尝试在 Flutter 中构建一个小应用程序,并且在三星 Galaxy S9+ 上我的应用程序顶部确实出现了一个黑条。 使用模拟器时也会出现该栏。

谁能帮我找出这是什么原因?

见附图。

感谢的帮助

这是主屏幕代码

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'register_house.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'findMe',
      home: MapSample(),
    );
  }
}

class MapSample extends StatefulWidget {
  @override
  State<MapSample> createState() => MapSampleState();
}

class MapSampleState extends State<MapSample> {
  Completer<GoogleMapController> _controller = Completer();

  static final CameraPosition _homePageLocation = CameraPosition(
    target: LatLng(3.8189673, 11.5010141),
    zoom: 14.4746,
  );

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('findMe'),
      ),
      body: GoogleMap(
        mapType: MapType.hybrid,
        initialCameraPosition: _homePageLocation,
        onMapCreated: (GoogleMapController controller) {
          _controller.complete(controller);
        },
      ),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: goToRegisterPage,
        label: Text('Add my House'),
        icon: Icon(Icons.home),
      ),
    );
  }

  void _pushPage(BuildContext context, Widget page) {
    Navigator.of(context).push(
      MaterialPageRoute<void>(builder: (_) => page),
    );
  }

  void goToRegisterPage() {
    _pushPage(context, RegisterPage());
  }
} //delimits class

【问题讨论】:

  • 请添加您的代码,以便我们更好地帮助您
  • 你必须指定一些代码
  • 请分享您的屏幕代码
  • 我编辑了问题并附上了一些代码

标签: android mobile flutter


【解决方案1】:

你需要在valuesvalues-night中添加styles.xmlandroid/app/src/main/res 文件夹

/values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
    <!-- Show a splash screen on the activity. Automatically removed when
         Flutter draws its first frame -->
    <item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
     This theme determines the color of the Android Window while your
     Flutter UI initializes, as well as behind your Flutter UI while its
     running.
     
     This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
    <item name="android:windowBackground">?android:colorBackground</item>
</style>

/values-night/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
    <!-- Show a splash screen on the activity. Automatically removed when
         Flutter draws its first frame -->
    <item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
     This theme determines the color of the Android Window while your
     Flutter UI initializes, as well as behind your Flutter UI while its
     running.
     
     This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
    <item name="android:windowBackground">?android:colorBackground</item>
</style>

删除这些文件时会出现此工具栏

【讨论】:

  • 嗨。这并没有为我解决问题。它对你有用吗??
【解决方案2】:

好的,我遇到了同样的问题,经过多次反复试验,我修复了它。只需转到您的 AndroidManifest.xml 类 (android/app/src/main/AndroidManifest.xml) 并在添加的 MainActivity 下,将主题更改为 NoTitleBar

            android:theme="@android:style/Theme.NoTitleBar"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多