gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:29:57 25 4
gpt4 key购买 nike

  • 我无法从 web view flutter 中删除标题。有没有办法删除 webview 网站的标题并将应用程序标题应用到 web View ,这样网站标题就会被删除,我们的应用栏作为标题显示在应用程序上。
  • 我想在底部导航栏下的 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 appbar,如下所示:

      @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 中删除 Header 并在底部导航图标中添加下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67998395/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com