yin_webview 0.0.11

yin_webview #

为满足自己操作cookie需求

Getting Started #

库引用

dependencies:
    yin_webview: ^0.0.5

包引用

import 'package:yin_webview/YinWebViewPlugin.dart';

实现原理

这个是一个调用原生webview实现的工具
通过MethodChannel 实现 flutter与原生通信

使用方式

List<Map<String, String>> cookies = new List();
cookies.add({"k": "hkroles_develop", "v": "buyer%2Cseller%2Ccardseller"});
cookies.add({"k": "hkuid_develop", "v": "1010004"});
    
Navigator.push(
            context,
            new MaterialPageRoute(
              builder: (context) => new YinWebViewPlugin(
                    url: url,
                    actions: <Widget>[
                      IconButton(
                        icon: Icon(Icons.alarm),
                        tooltip: "Alarm",
                        onPressed: () {
                          print("Alarm");
                        },
                      ),
                      PopupMenuButton(
                        itemBuilder: (BuildContext context) =>
                        <PopupMenuItem<String>>[
                          PopupMenuItem<String>(child: Text("热度"), value: "hot",),
                          PopupMenuItem<String>(child: Text("最新"), value: "new",),
                        ],
                        onSelected: (String action) {
                          switch (action) {
                            case "hot":
                              print("hot");
                              break;
                            case "new":
                              print("new");
                              break;
                          }
                        },
                        onCanceled: () {
                          print("onCanceled");
                        },
                      )
                    ],
                    scrollBar: false,
                    cookieList: cookies,
                    loadUrl: (value) {
                      print('test url=$value');
                    },
                    plugin: (YinWebview bean) {
                      if (bean != null) {
                        bean.getCookies(url, (value) {
                          print('test cookies=$value');
                        });
                      }
                    },
                  ),
            ),
          );

0.0.4 #

  • 调整说明文件

example/README.md

yin_webview_example #

import 'package:flutter/material.dart';
import 'package:yin_webview/YinWebViewPlugin.dart';

import 'package:yin_webview/yin_webview.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Webview',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String url = "https://www.baidu.com";

  ///内容视图
  Widget contentView() {
    List<Map<String, String>> cookies = new List();
    cookies.add({"k": "hkroles_develop", "v": "buyer%2Cseller%2Ccardseller"});
    cookies.add({"k": "hkuid_develop", "v": "1010004"});

    return new Center(
      child: new RaisedButton(
        child: new Text('打开'),
        onPressed: () {
          Navigator.push(
            context,
            new MaterialPageRoute(
              builder: (context) => new YinWebViewPlugin(
                    url: url,
                    actions: <Widget>[
                      IconButton(
                        icon: Icon(Icons.alarm),
                        tooltip: "Alarm",
                        onPressed: () {
                          print("Alarm");
                        },
                      ),
                      PopupMenuButton(
                        itemBuilder: (BuildContext context) =>
                        <PopupMenuItem<String>>[
                          PopupMenuItem<String>(child: Text("热度"), value: "hot",),
                          PopupMenuItem<String>(child: Text("最新"), value: "new",),
                        ],
                        onSelected: (String action) {
                          switch (action) {
                            case "hot":
                              print("hot");
                              break;
                            case "new":
                              print("new");
                              break;
                          }
                        },
                        onCanceled: () {
                          print("onCanceled");
                        },
                      )
                    ],
                    scrollBar: false,
                    cookieList: cookies,
                    loadUrl: (value) {
                      print('test url=$value');
                    },
                    plugin: (YinWebview bean) {
                      if (bean != null) {
                        bean.getCookies(url, (value) {
                          print('test cookies=$value');
                        });
                      }
                    },
                  ),
            ),
          );
        },
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: contentView(),
    );
  }

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  yin_webview: ^0.0.11

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:yin_webview/yin_webview.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Sep 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/yin_webview.dart. (-0.50 points)

Analysis of lib/yin_webview.dart reported 1 hint:

line 56 col 35: This function has a return type of 'Future', but doesn't end with a return statement.

Format lib/YinWebViewPlugin.dart.

Run flutter format to format lib/YinWebViewPlugin.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test