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

How to prevent widgets from being shown in notification bar in flutter

我这里有一个简单网络视图的代码。它只是显示一个网页。但是,网页的顶部显示为堆叠在通知栏下方(如页面顶部的某些按钮)。我怎样才能防止这种情况发生? 我知道我可以隐藏通知bar/icons,但我想在通知栏下方显示 webview 小部件的内容而不隐藏它。我也不想使用应用程序栏。请帮帮我

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,
    );
  }
}

只需用 SafeArea

包装您的 webviw
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,
    );
  }
}

输出: