简体   繁体   English

AppBar 顶部的黑条 Flutter

[英]Black bar on top of AppBar Flutter

I am trying to build a small app in flutter, and I do have a black bar coming on top of my app on a Samsung Galaxy S9+.我正在尝试在 flutter 中构建一个小应用程序,在三星 Galaxy S9+ 上我的应用程序顶部确实有一个黑条。 The bar also appears in when using the emulator.使用模拟器时也会出现该栏。

Could anyone help me find whats causes this?谁能帮我找出是什么原因造成的?

See the picture attached.见附图。

Thanks for the help谢谢您的帮助![主屏幕图像

and here is the main screen code这是主屏幕代码

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

Okay I faced the same issue and after multiple trial and error I fixed it.好吧,我遇到了同样的问题,经过多次试验和错误后,我修复了它。 Just goto your AndroidManifest.xml class (android/app/src/main/AndroidManifest.xml) and under the MainActivity added, change the theme to NoTitleBar只需转到您的 AndroidManifest.xml class (android/app/src/main/AndroidManifest.xml) 并在添加的 MainActivity 下,将主题更改为 NoTitleBar

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

You need to add styles.xml to android/app/src/main/res in values and values-night folders您需要添加styles.xmlAndroid /应用/ src目录/价值观价值观夜文件夹/ RES

/values/styles.xml /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 /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>

This toolbar appears when these files are deleted删除这些文件时会出现此工具栏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM