简体   繁体   English

flutter中如何防止小部件显示在通知栏中

[英]How to prevent widgets from being shown in notification bar in flutter

I have a code here for a simple webview. It simply displays a webpage.我这里有一个简单的代码 webview。它只显示一个网页。 However, the top part of the webpage is shown stacked below the notification bar(As in some of the buttons on the top part of the page).但是,网页的顶部显示为堆叠在通知栏下方(如页面顶部的某些按钮)。 How can I prevent this?我怎样才能防止这种情况发生? I know I can hide the notification bar/icons, but I want to show the contents of the webview widgets below the notification bar without hiding it.我知道我可以隐藏通知栏/图标,但我想在通知栏下方显示 webview 小部件的内容而不隐藏它。 I also don't want to use an app bar.我也不想使用应用程序栏。 Kindly help me out请帮帮我

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

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

class MyApp extends StatefulWidget {
  @override
  MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  late WebViewController controller;
  @override
  void initState() {
    super.initState();
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          body: WebView(
        initialUrl: 'https://flutter.dev',
        javascriptMode: JavascriptMode.unrestricted,
      )),
      debugShowCheckedModeBanner: false,
    );
  }
}

Just wrap your webviw with SafeArea用 SafeArea 包裹你的SafeArea

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

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

class MyApp extends StatefulWidget {
  @override
  MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  WebViewController controller;
  @override
  void initState() {
    super.initState();
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          body: SafeArea(
            child: WebView(
              initialUrl: 'https://flutter.dev',
              javascriptMode: JavascriptMode.unrestricted,
            ),
          )),
      debugShowCheckedModeBanner: false,
    );
  }
}

output: output:

在此处输入图像描述

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

相关问题 如何防止小部件将自己置于通知栏/摄像头下? - How to prevent widgets from placing themselves under notifications bar / camera? Flutter Randomizing - 如何防止显示显示的上一个元素 - Flutter Randomizing - How to prevent from displaying the previous element shown 如何控制 FLutter 包 audio_service 中通知栏中显示的内容 - How can I control what is shown in the notification bar in the package audio_service for FLutter 在 flutter 如何清除栏中的通知? - In flutter how to clear notification in bar? 如何将图片中显示的卡片等小部件放在应用栏顶部? - how to put widgets like cards that shown in the picture on top of an app bar? 我来自 API 的内容未在 Flutter 中显示 - My Content from API is not being shown in Flutter 如何从 Flutter 的通知栏中删除所有通知? - How to remove all notifications from notification bar in Flutter? Flutter - 如何防止变量在状态更改时重新初始化? - Flutter - How to prevent variables from being reinitialized when the state changes? 如何防止在父小部件 GestureDetector 上触发 onTapDown? - How do I prevent onTapDown from being triggered on a parent widgets GestureDetector? Flutter:如何防止屏幕滚动并适合屏幕内的所有小部件 - Flutter: How to prevent screen from scrolling and fit all widgets inside the screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM