【问题标题】:How to prevent widgets from being shown in notification bar in flutter如何防止小部件在颤动中显示在通知栏中
【发布时间】:2021-10-22 12:50:43
【问题描述】:

我这里有一个简单 webview 的代码。它只是显示一个网页。但是,网页的顶部显示在通知栏下方(与页面顶部的某些按钮一样)。我怎样才能防止这种情况? 我知道我可以隐藏通知栏/图标,但我想在通知栏下方显示 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,
    );
  }
}

【问题讨论】:

    标签: flutter webview flutter-layout android-widget notification-bar


    【解决方案1】:

    只需使用 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,
        );
      }
    }
    

    输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 2022-08-02
      • 2019-10-18
      • 2019-06-16
      • 2020-11-19
      • 2019-10-27
      • 2019-03-19
      相关资源
      最近更新 更多