flutter - 如何从 webview flutter 中删除标题并在底部导航图标中添加下划线

标签 flutter flutterwebviewplugin flutter-bottomnavigation

  1. 我无法从 Web View 抖动中删除标题。有没有办法删除 Web View 网站的标题并将应用程序标题应用于 Web View ,以便删除网站标题并在应用程序栏上显示标题应用程序。

  2. 我想在底部导航栏下的 svg 图标上添加黄色下划线,但我无法添加,请帮助我。 Home page of my app

import 'dart:async';
import 'package:url_launcher/url_launcher.dart';
import 'dart:io';
/* import 'package:titled_navigation_bar/titled_navigation_bar.dart' ;*/
import 'package:flutter_svg/flutter_svg.dart';

/* import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; */
import 'package:webview_flutter/webview_flutter.dart';

/* import 'package:md2_tab_indicator/md2_tab_indicator.dart'; */

/*import 'package:flutter_inappwebview/flutter_inappwebview.dart'; */
main() {
  runApp(MyApp());
}

// ignore: use_key_in_widget_constructors
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: SplashScreen()); // define it once at root level.
  }
}

// ignore: use_key_in_widget_constructors
class SplashScreen extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return SplashScreenState();
  }
}

class SplashScreenState extends State<SplashScreen> {
  @override
  void initState() {
    super.initState();

    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();

    Timer(
        // ignore: prefer_const_constructors
        Duration(seconds: 1),
        () => Navigator.pushReplacement(
            context, MaterialPageRoute(builder: (context) => HomeScreen())));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Center(child: Image.asset('assets/splash.jpeg')),
    );
  }
}

// ignore: use_key_in_widget_constructors
class HomeScreen extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<HomeScreen> {
  final Completer<WebViewController> _controller =
      Completer<WebViewController>();

  num _stackToView = 1;
  int _selectedTabIndex = 0;
  // ignore: prefer_final_fields
  List _pages = [
    // ignore: prefer_const_constructors
    Text("Home"),
    // ignore: prefer_const_constructors
    Text("Wishlist"),
    // ignore: prefer_const_constructors
    Text("Search"),
    // ignore: prefer_const_constructors
    Text("Bookings"),
    // ignore: prefer_const_constructors
    Text("Menu"),

    Text("call"),
  ];

  _changeIndex(int index) {
    setState(() {
      _selectedTabIndex = index;
    });
  }

  void _handleLoad(String value) {
    setState(() {
      _stackToView = 0;
    });
  }

  @override
  Widget build(BuildContext context) {
    final textTheme = Theme.of(context).textTheme;
    final colorScheme = Theme.of(context).colorScheme;
    return Scaffold(
      appBar: AppBar(
          /*  automaticallyImplyLeading: false, */
          leading: Padding(
            padding: EdgeInsets.all(10.0),
            child: SvgPicture.asset("assets/svg/VW-logo.svg"),

            /* leadingWidth: 35, */
          ),
          actions: [
            IconButton(
              icon: SvgPicture.asset("assets/svg/new.svg", color: Colors.black),
              onPressed: () {},
            ),
            IconButton(
              icon: SvgPicture.asset("assets/svg/Page-1.svg"),
              onPressed: () {
                _launchURL();
              },
            ),
          ],
          backgroundColor: Colors.white),
      body:
          /* const WebView(
        initialUrl: 'https://www.google.com/',
        javascriptMode: JavascriptMode.unrestricted,
      ), */

          /* Center(child: _pages[_selectedTabIndex]), */
          IndexedStack(
        index: _selectedTabIndex,
        children: [
          Column(
            children: <Widget>[
              Expanded(
                  child: WebView(
                initialUrl: "https://www.veenaworld.com/",
                javascriptMode: JavascriptMode.unrestricted,
                onPageFinished: _handleLoad,
                onWebViewCreated: (WebViewController webViewController) {
                  _controller.complete(webViewController);
                },
              )),
            ],
          ),
          Container(
            child: Center(child: _pages[_selectedTabIndex]),
          ),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _selectedTabIndex,
        onTap: _changeIndex,
        type: BottomNavigationBarType.fixed,
        /*    backgroundColor: Colors.blue.shade900, */
        selectedLabelStyle: textTheme.caption,
        unselectedLabelStyle: textTheme.caption,
        /*  Container(   
       decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(width: 1.0, color: Colors.black),
          ),
        ), 
        ), */
        selectedItemColor: Colors.black,
        unselectedItemColor: Colors.black.withOpacity(.60),
        items: [
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/svg/home-alt2.svg",
                  color: Colors.black),
              title: Text("Home")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/svg/favourite.svg",
                  color: Colors.black),
              title: Text("Wishlist")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/svg/search.svg",
                  color: Colors.black),
              title: Text("Search")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/svg/bag.svg", color: Colors.black),
              title: Text("Bookings")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/svg/hamburger.svg",
                  color: Colors.black),
              title: Text("Menu"))
        ],
      ),
    );
  }
}

_launchURL() async {
  const url = 'https://www.google.com/';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}


最佳答案

对于操作 WebView,我认为没有办法做到这一点,也许您可​​以使用像堆栈这样的技巧来隐藏 WebView 应用栏,如下所示:

  @override
  Widget build(BuildContext context) {
    final textTheme = Theme.of(context).textTheme;
    final colorScheme = Theme.of(context).colorScheme;
    return Scaffold(
      // appBar: AppBar(
      //     /*  automaticallyImplyLeading: false, */
      //     leading: Padding(
      //       padding: EdgeInsets.all(10.0),
      //       child: SvgPicture.asset("assets/images/Helmet.svg"),
      //
      //       /* leadingWidth: 35, */
      //     ),
      //     actions: [
      //       IconButton(
      //         icon: SvgPicture.asset("assets/images/Helmet.svg",
      //             color: Colors.black),
      //         onPressed: () {},
      //       ),
      //     ],
      //     backgroundColor: Colors.white),
      body: Stack(
        children: [
          IndexedStack(
            index: _selectedTabIndex,
            children: [
              Column(
                children: <Widget>[
                  Expanded(
                      child: WebView(
                    initialUrl: "https://www.veenaworld.com/",
                    javascriptMode: JavascriptMode.unrestricted,
                    onPageFinished: _handleLoad,
                    onWebViewCreated: (WebViewController webViewController) {
                      _controller.complete(webViewController);
                    },
                  )),
                ],
              ),
              Container(
                child: Center(child: _pages[_selectedTabIndex]),
              ),
            ],
          ),
          AppBar(
            /*  automaticallyImplyLeading: false, */
            leading: Padding(
              padding: EdgeInsets.all(10.0),
              child: SvgPicture.asset("assets/images/Helmet.svg"),

              /* leadingWidth: 35, */
            ),
            actions: [
              IconButton(
                icon: SvgPicture.asset("assets/images/Helmet.svg",
                    color: Colors.black),
                onPressed: () {},
              ),
            ],
            backgroundColor: Colors.white,
          ),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _selectedTabIndex,
        onTap: _changeIndex,
        type: BottomNavigationBarType.fixed,
        /*    backgroundColor: Colors.blue.shade900, */
        selectedLabelStyle: textTheme.caption,
        unselectedLabelStyle: textTheme.caption,
        /*  Container(
       decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(width: 1.0, color: Colors.black),
          ),
        ),
        ), */
        selectedItemColor: Colors.black,
        unselectedItemColor: Colors.black.withOpacity(.60),
        items: [
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/images/Helmet.svg",
                  color: Colors.black),
              title: Text("Home")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/images/Helmet.svg",
                  color: Colors.black),
              title: Text("Wishlist")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/images/Helmet.svg",
                  color: Colors.black),
              title: Text("Search")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/images/Helmet.svg",
                  color: Colors.black),
              title: Text("Bookings")),
          BottomNavigationBarItem(
              icon: SvgPicture.asset("assets/images/Helmet.svg",
                  color: Colors.black),
              title: Text("Menu"))
        ],
      ),
    );
  }

关于flutter - 如何从 webview flutter 中删除标题并在底部导航图标中添加下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67998395/

相关文章:

Flutter WEB 下载选项

html - 如何将外部CSS应用到flutter webview中的html渲染

flutter - 如何在 flutter webview 中打开 localhost

flutter - "' !_needsLayout ': is not true"在使用 BottomNavigationBar 切换屏幕时 Flutter 出错

Flutter - 滑动时隐藏 FAB 按钮

flutter - 无法将 ListView 设置为 LayoutBuilder Widget (Flutter)

flutter:如何向底部导航栏项目添加填充,使项目彼此保持更远的距离

flutter - BottomNavigationBar无法应用背景图像-Flutter

dart - Flutter:如何一次又一次停止不必要地渲染 "Widget build()"?

android - 使用 flutter 应用更改设备亮度