sweep down to refresh WebView app in flutter

让人想犯罪 __ 提交于 2020-01-24 01:15:09

问题


I have created a flutter app with WebView

Is there any way to sweep down to refresh the webpage

I am using "webview_flutter_plugin" plugin

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: Stack(
        children: <Widget>[
          Container(
            child: Center(
              child: Text(_title),
            ),
          ),
        ],
      )),
      body: SafeArea(
          child: WebView(
              key: _key,
              javascriptMode: JavascriptMode.unrestricted,
              initialUrl: _url)),
    );
  }
}

回答1:


SwipeDetectore did it.

in pubspec.yaml :

dependencies:
  flutter:
    sdk: flutter
  flutter_webview_plugin: ^0.3.0+2
  swipedetector: ^1.2.0

imports :

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

in the State Class :

final flutterWebviewPlugin = new FlutterWebviewPlugin();
@override
  Widget build(BuildContext context) {
    return SwipeDetector(
      child: WebviewScaffold(
        url: _url,
        withJavascript: true,
        withZoom: false,
        appBar: AppBar(
          title: Stack(
            children: <Widget>[
              Container(child: Center(child: Text(_title))),
            ],
          ),
          elevation: 1,
        ),
      ),
      onSwipeDown: () {
        flutterWebviewPlugin.reload();
      },

      swipeConfiguration: SwipeConfiguration(       
          verticalSwipeMinVelocity: 100.0,
          verticalSwipeMinDisplacement: 50.0,
          verticalSwipeMaxWidthThreshold: 100.0,
          horizontalSwipeMaxHeightThreshold: 50.0,
          horizontalSwipeMinDisplacement: 50.0,
          horizontalSwipeMinVelocity: 200.0),
    );


来源:https://stackoverflow.com/questions/57656045/sweep-down-to-refresh-webview-app-in-flutter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!