pull_to_refresh_web_view 0.2.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 66

pull_to_refresh_web_view #

A plugin that can embedded (web view) with flutter widgets. #

The web view on iOS support by wkwebview #

The web view on Android support by WebView #

📣 important note

  • Android keyboard cannot be appear according to this flutter issue 19718
  • Not support scrollview

support

  • Can embedded in widget tree ✅
  • Pull to refresh (true / false) ✅
  • Add header ✅
  • Add userAgent ✅
  • Can handl all webview callback method ✅
  • Can call evaluateJavascript ✅
  • Can load HTML ✅

Demo #

alt-text-1

NOTE: For iOS you need to put the key => io.flutter.embedded_views_preview and the value YES in Info.plist

To use this plugin: #

    dependencies:
       flutter:
        sdk: flutter
       pull_to_refresh_web_view:

How it works #

See Full example in example

Basic

    new WebVuw(
        initialUrl: 'www.url.com',
        enableJavascript: true,
        pullToRefresh: true,
        header: {
            .....
        }
        userAgent: 'userAgent',
        // to load html string
        // html: '<body><h1>this is web vuw</h1></body>',
        gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>[
            Factory<OneSequenceGestureRecognizer>(
                () => EagerGestureRecognizer(),
            ),
        ].toSet(),
        javaScriptMode: JavaScriptMode.unrestricted,
        onWebViewCreated: (WebVuwController webViewController) {
            _controller.complete(webViewController);
        }
    )

Listen to webview events #

First 1️⃣ 👇🏻 #


//    ...
    StreamSubscription _ssWebVuwEvents;

    @override
    Widget build(BuildContext context) {
        return FutureBuilder<WebVuwController>(
        future: _controller.future,
        builder:
            (BuildContext context, AsyncSnapshot<WebVuwController> snapshot) {
            final webViewReady = 
                snapshot.connectionState == ConnectionState.done;
            final controller = snapshot.data;

            if (webViewReady) {
                // You can now call the functions
                // controller.stopLoading();
                _ssWebVuwEvents = controller.onEvents().listen((events) {
                    print('Events 😎=> $events');
                });
            }
    ...

Second 2️⃣ 👇🏻 #

    @override
    void dispose() {
        if (_ssWebVuwEvents != null) _ssWebVuwEvents.cancel();
        super.dispose();
    }
    ..

Functions 👨🏻‍💻 #

Future<void> loadUrl(String url);
Future<bool> canGoBack();
Future<bool> canGoForward();
Future<void> goBack();
Future<void> goForward();
Future<void> stopLoading();
Future<void> reload();
Future<void> forward();
Future<dynamic> evaluateJavascript(String javascriptString);
 Future<void> loadHtml(String html);
Stream onEvents;

0.0.1 Release #

  • First release for lib

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:pull_to_refresh_web_view/pull_to_refresh_web_view.dart';
import 'popup_screen.dart';

void main() => runApp(MaterialApp(home: Example()));

class Example extends StatefulWidget {
  @override
  createState() => _ExampleState();
}

class _ExampleState extends State<Example> {
  final Completer<WebVuwController> _controller = Completer<WebVuwController>();
  StreamSubscription _ssWebVuwEvents;
  String _loadUrl = 'https:/flutter.io';
  final _scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<WebVuwController>(
      future: _controller.future,
      builder:
          (BuildContext context, AsyncSnapshot<WebVuwController> snapshot) {
        final webViewReady = snapshot.connectionState == ConnectionState.done;
        final controller = snapshot.data;

        if (webViewReady) {
          _ssWebVuwEvents = controller.onEvents().listen((events) {
            print('Events 😎=> $events');
          });
        }

        return Scaffold(
          key: _scaffoldKey,
          appBar: AppBar(
              centerTitle: true,
              backgroundColor: Colors.red,
              title: Text('Web Vuw'),
              actions: <Widget>[
                IconButton(
                  icon: Icon(Icons.favorite),
                  onPressed: () {
                    showSnackBar("Can Show Snak Bar 😎");
                  },
                ),
                IconButton(
                  icon: Icon(Icons.palette),
                  onPressed: () async {
                    final controller = await _controller.future;
                    final result = await controller.evaluateJavascript(
                        'document.body.style.backgroundColor = \'cyan\'');
                    print('result -> $result');
                  },
                ),
                IconButton(
                    icon: Icon(Icons.thumb_up),
                    onPressed: () {
                      popupScreen(PopupScreen(), context);
                    }),
                IconButton(
                    icon: Icon(Icons.code),
                    onPressed: () async {
                      final controller = await _controller.future;
                      await controller
                          .loadHtml('<body><h1>this is web vuw</h1></body>');
                    })
              ]),
          body: WebVuw(
//             to load web page url
            initialUrl: _loadUrl,
            // to load html string
//            html: '<body><h1>this is web vuw</h1></body>',
            enableJavascript: true,
            pullToRefresh: false,
            userAgent: 'userAgent',
            gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>[
              Factory<OneSequenceGestureRecognizer>(
                () => EagerGestureRecognizer(),
              ),
            ].toSet(),
            javaScriptMode: JavaScriptMode.unrestricted,
            onWebViewCreated: (WebVuwController webViewController) {
              _controller.complete(webViewController);
            },
          ),
        );
      },
    );
  }

  showSnackBar(String message) =>
      _scaffoldKey.currentState.showSnackBar(SnackBar(
        content: Text(
          message,
          textAlign: TextAlign.center,
        ),
        backgroundColor: Colors.green,
      ));

  @override
  void dispose() {
    if (_ssWebVuwEvents != null) _ssWebVuwEvents.cancel();
    super.dispose();
  }
}

popupScreen(Widget screen, BuildContext context) => Navigator.push(
    context,
    PageRouteBuilder(
        opaque: false,
        pageBuilder: (BuildContext context, _, __) => screen,
        transitionsBuilder: (
          BuildContext context,
          Animation<double> animation,
          Animation<double> secondaryAnimation,
          Widget child,
        ) =>
            SlideTransition(
              position: Tween<Offset>(
                begin: Offset(0.0, 1.0),
                end: Offset.zero,
              ).animate(animation),
              child: child, // child is the value returned by pageBuilder
            )));

Use this package as a library

1. Depend on it

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


dependencies:
  pull_to_refresh_web_view: ^0.2.5

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:pull_to_refresh_web_view/pull_to_refresh_web_view.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]
100
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:pull_to_refresh_web_view/pull_to_refresh_web_view.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:pull_to_refresh_web_view/pull_to_refresh_web_view.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:pull_to_refresh_web_view/pull_to_refresh_web_view.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:pull_to_refresh_web_view/pull_to_refresh_web_view.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • pull_to_refresh_web_view that is a package requiring null.

Health suggestions

Format lib/pull_to_refresh_web_view.dart.

Run flutter format to format lib/pull_to_refresh_web_view.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
flutter_test 0.0.0
Transitive dependencies
archive 2.0.13
args 1.6.0
async 2.4.1 2.4.2
boolean_selector 2.0.0
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
crypto 2.1.4 2.1.5
image 2.1.12 2.1.14
matcher 0.12.6 0.12.8
meta 1.1.8 1.2.2
path 1.6.4 1.7.0
petitparser 2.4.0 3.0.4
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3 1.9.5
stream_channel 2.0.0
string_scanner 1.0.5
term_glyph 1.1.0
test_api 0.2.15 0.2.17
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
xml 3.6.1 4.2.0