本文介绍了下拉以刷新WebView页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用WebView创建了一个Flutter应用程序
I have created a flutter app with WebView
有什么方法可以刷新页面
Is there any way to sweep down to refresh the webpage
我正在使用"webview_flutter_plugin"插件
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)),
);
}
}
推荐答案
SwipeDetectore做到了.
SwipeDetectore did it.
在pubspec.yaml中:
in pubspec.yaml :
dependencies:
flutter:
sdk: flutter
flutter_webview_plugin: ^0.3.0+2
swipedetector: ^1.2.0
进口:
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
import 'package:swipedetector/swipedetector.dart';
在国家舱:
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),
);
这篇关于下拉以刷新WebView页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!