问题
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