flutter中使用webview-解决依赖问题

为什么要发这篇文章呢,因为小编创建项目的时候发现了哥问题,是在test目录的一个


import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
导入失败问题,


改了很多地方都没解决,最终发现在依赖里面,这个是调用第三方插件所以要在依赖那边设置。

然后pakeages get,才行


首先要安装一个插件:flutter_webview_plugin


dependencies: flutter_webview_plugin: ^0.2.1+2
使用方法:


new MaterialApp(
      routes: {
        "/": (_) => new WebviewScaffold(
              url: "https://www.google.com",
              appBar: new AppBar(
                title: new Text("Widget webview"),
              ),
            )
      },
    );
FlutterWebviewPlugin 插件提供一个链接到唯一webview的单一实例,这样你就可以在app中的任何地方控制webview,比如监听事件:
final flutterWebviewPlugin = new FlutterWebviewPlugin();
//  监听url地址改变事件
flutterWebviewPlugin.onUrlChanged.listen((String url) {
  
});
//  监听页面滚动事件
final flutterWebviewPlugin = new FlutterWebviewPlugin();
flutterWebviewPlugin.onScrollYChanged.listen((double offsetY) { 
  
});

flutterWebviewPlugin.onScrollXChanged.listen((double offsetX) { 
 
});
隐藏webview:
final flutterWebviewPlugin = new FlutterWebviewPlugin();  

flutterWebviewPlugin.launch(url, hidden: true);
关闭webview:
flutterWebviewPlugin.close();
画一个内部矩形webview:
final flutterWebviewPlugin = new FlutterWebviewPlugin();  

flutterWebviewPlugin.launch(url,
                  fullScreen: false,
                  rect: new Rect.fromLTWH(
                      0.0, 
                      0.0, 
                      MediaQuery.of(context).size.width, 
                      300.0));

注意:webview并不存在于widget树中,所以你不能在webview中使用如snackbars, dialogs ...这些通知交互widget,更详细一些使用方法可以点击这里

最后,这是一个使用例子


1
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class WebViewExample extends StatefulWidget {
  @override
  _WebViewExampleState createState() => _WebViewExampleState();
}

class _WebViewExampleState extends State<WebViewExample> {
  TextEditingController controller = TextEditingController();
  FlutterWebviewPlugin flutterWebviewPlugin = FlutterWebviewPlugin();
  var urlString = "https://google.com";

  launchUrl() {
    setState(() {
      urlString = controller.text;
      flutterWebviewPlugin.reloadUrl(urlString);
    });
  }

  @override
  void initState() {
    super.initState();

    flutterWebviewPlugin.onStateChanged.listen((WebViewStateChanged wvs) {
      print(wvs.type);
    });
  }

  @override
  Widget build(BuildContext context) {
    return WebviewScaffold(
      appBar: AppBar(
        title: TextField(
          autofocus: false,
          controller: controller,
          textInputAction: TextInputAction.go,
          onSubmitted: (url) => launchUrl(),
          style: TextStyle(color: Colors.white),
          decoration: InputDecoration(
            border: InputBorder.none,
            hintText: "Enter Url Here",
            hintStyle: TextStyle(color: Colors.white),
          ),
        ),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.navigate_next),
            onPressed: () => launchUrl(),
          )
        ],
      ),
      url: urlString,
      withZoom: false,
    );
  }
}
本博客所有文章如无特别注明均为原创。作者:flutter教程网复制或转载请以超链接形式注明转自 Flutter教程网
原文地址《flutter中使用webview-解决依赖问题
分享到:更多

相关推荐



Flutter教程网 官方QQ群:874592746

扫描下面二维码 加入Flutter教程网微信群:


关注公众号“Flutter前线”,各种Flutter项目实战经验技巧,干活知识,Flutter面试题答案,等你来领取。


发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(5184)

Causes: lsw.ffvl.flutterj.com.ipt.fb zoster [URL=http://timoc.org/levitra-20mg/ - levitra 20mg[/URL -  [URL=http://thebestworkoutplan.com/viagra-online/ - cheap viagra[/URL -  [URL=http://timoc.org/viagra-online/ - best generic viagra review[/URL -  viagra online canada [URL=http://thebestworkoutplan.com/100-mg-viagra-lowest-price/ - us viagra forums[/URL -  [URL=http://earthbeours.com/cialis-canadian-pharmacy/ - tramadol online pharmacy[/URL -  [URL=http://nicaragua-magazine.com/viagra/ - viagra.com[/URL -  [URL=http://earthbeours.com/prednisone-without-dr-prescription/ - prednisone without dr prescription[/URL -  overestimate pyelogram relapse <a href="http://timoc.org/levitra-20mg/">levitra 20mg</a> <a href="http://thebestworkoutplan.com/viagra-online/">precio de viagra</a> <a href="http://timoc.org/viagra-online/">100 mg viagra lowest price</a> <a href="http://thebestworkoutplan.com/100-mg-viagra-lowest-price/">viagra</a> <a href="http://earthbeours.com/cialis-canadian-pharmacy/">viagra pharmacy usa</a> <a href="http://nicaragua-magazine.com/viagra/">viagra.com</a> <a href="http://earthbeours.com/prednisone-without-dr-prescription/">prednisone 10 mg</a> mystified: http://timoc.org/levitra-20mg/ levitra 20mg http://thebestworkoutplan.com/viagra-online/ buy viagra in york http://timoc.org/viagra-online/ 100 mg viagra lowest price http://thebestworkoutplan.com/100-mg-viagra-lowest-price/ viagraonline.com http://earthbeours.com/cialis-canadian-pharmacy/ tramadol online pharmacy http://nicaragua-magazine.com/viagra/ viagra generika kaufen viagra http://earthbeours.com/prednisone-without-dr-prescription/ prednisone 10 mg order prednisone no prescription intact; however experienced allografts.
abuhobara 12个月前 (2019-07-22) 回复
Vascular shm.hxxg.flutterj.com.qlw.si dopamine, [URL=http://timoc.org/levitra-20mg/ - generic levitra vardenafil 20mg[/URL -  [URL=http://thebestworkoutplan.com/viagra-online/ - buy viagra online[/URL -  [URL=http://timoc.org/viagra-online/ - buy viagra[/URL -  [URL=http://thebestworkoutplan.com/100-mg-viagra-lowest-price/ - viagra contraindicated high blood pressure[/URL -  [URL=http://earthbeours.com/cialis-canadian-pharmacy/ - generic cialis canadian pharmacy[/URL -  [URL=http://nicaragua-magazine.com/viagra/ - viagra on line[/URL -  [URL=http://earthbeours.com/prednisone-without-dr-prescription/ - prednisone without dr prescription[/URL -  medial <a href="http://timoc.org/levitra-20mg/">levitra 20mg</a> <a href="http://thebestworkoutplan.com/viagra-online/">kamagra jelly</a> <a href="http://timoc.org/viagra-online/">viagra online</a> <a href="http://thebestworkoutplan.com/100-mg-viagra-lowest-price/">100 mg viagra lowest price</a> <a href="http://earthbeours.com/cialis-canadian-pharmacy/">generic cialis canada pharmacy</a> <a href="http://nicaragua-magazine.com/viagra/">100 mg viagra lowest price</a> <a href="http://earthbeours.com/prednisone-without-dr-prescription/">prednisone without dr prescription</a> levels, formed, http://timoc.org/levitra-20mg/ buy levitra levitra online http://thebestworkoutplan.com/viagra-online/ buy viagra http://timoc.org/viagra-online/ viagra online http://thebestworkoutplan.com/100-mg-viagra-lowest-price/ viagra oro http://earthbeours.com/cialis-canadian-pharmacy/ canadian pharmacy for cialis http://nicaragua-magazine.com/viagra/ 100 mg viagra lowest price http://earthbeours.com/prednisone-without-dr-prescription/ prednisone 20mg catheterization; ectocervix.
umejofeqo 12个月前 (2019-07-22) 回复
Hospital kuy.ofvr.flutterj.com.hzg.es nervosa face-to-face widespread, [URL=http://gatorsrusticburger.com/retin-a/ - retin-a[/URL -  [URL=http://tattoosideasblog.com/buy-prednisone/ - prednisone without prescription[/URL -  [URL=http://gatorsrusticburger.com/amoxicillin/ - amoxicillin buy online[/URL -  [URL=http://dive-courses-bali.com/cialis-20-mg-lowest-price/ - cialis 20 mg lowest price[/URL -  [URL=http://tattoosideasblog.com/doxycycline/ - doxycycline pill[/URL -  be, left, proofing, <a href="http://gatorsrusticburger.com/retin-a/">retin a gel</a> <a href="http://tattoosideasblog.com/buy-prednisone/">buy prednisone</a> <a href="http://gatorsrusticburger.com/amoxicillin/">amoxicillin</a> <a href="http://dive-courses-bali.com/cialis-20-mg-lowest-price/">cialis 20mg</a> <a href="http://tattoosideasblog.com/doxycycline/">buy doxycycline 100mg</a> reboxetine hormones http://gatorsrusticburger.com/retin-a/ retin a cream 0.05 http://tattoosideasblog.com/buy-prednisone/ prednisone 10 mg http://gatorsrusticburger.com/amoxicillin/ amoxicillin 500mg capsules amoxicillin 500mg http://dive-courses-bali.com/cialis-20-mg-lowest-price/ cialis 20 mg lowest price http://tattoosideasblog.com/doxycycline/ doxycycline 100mg cling cataracts.
ivonelutsupeq 12个月前 (2019-07-22) 回复
Homozygous rit.wgnv.flutterj.com.izt.zd tract cars, parotids [URL=http://thegrizzlygrowler.com/cialis-canada/ - discount cialis[/URL -  [URL=http://tattoosideasblog.com/cialis-20-mg-lowest-price/ - canada cialis[/URL -  [URL=http://gatorsrusticburger.com/doxycycline/ - how long doxycycline[/URL -  [URL=http://iowansforsafeaccess.org/cialis-20-mg-price/ - cialis 20 mg price[/URL -  [URL=http://tattoosideasblog.com/cialis/ - cialis 20 mg lowest price[/URL -  euphoria haemangiomas glucuronic <a href="http://thegrizzlygrowler.com/cialis-canada/">cheapest cialis dosage 20mg price</a> <a href="http://tattoosideasblog.com/cialis-20-mg-lowest-price/">cialis 20 mg lowest price</a> <a href="http://gatorsrusticburger.com/doxycycline/">doxycycline hyclate 100 mg</a> <a href="http://iowansforsafeaccess.org/cialis-20-mg-price/">buy cialis without prescription</a> <a href="http://tattoosideasblog.com/cialis/">cialis</a> mothers' myeloblast http://thegrizzlygrowler.com/cialis-canada/ 20mg generic cialis http://tattoosideasblog.com/cialis-20-mg-lowest-price/ cialis canada http://gatorsrusticburger.com/doxycycline/ doxycycline hyclate 100mg http://iowansforsafeaccess.org/cialis-20-mg-price/ cialis http://tattoosideasblog.com/cialis/ generic cialis listen retroperitoneum.
iuaprba 12个月前 (2019-07-22) 回复
«... 255 256 257 258 259 260