Skip to content

Commit

Permalink
Handle system back button in web view (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo authored Feb 6, 2024
1 parent bdfd11d commit 4e6060d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/shared/webview.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:async';

import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down Expand Up @@ -50,6 +53,23 @@ class _WebViewState extends State<WebView> {
(controller.platform as AndroidWebViewController).setMediaPlaybackRequiresUserGesture(false);
}
_controller = controller;

BackButtonInterceptor.add(_handleBack);
}

@override
void dispose() {
BackButtonInterceptor.remove(_handleBack);
super.dispose();
}

FutureOr<bool> _handleBack(bool stopDefaultButtonEvent, RouteInfo info) async {
if (await _controller.canGoBack()) {
_controller.goBack();
return true;
}

return false;
}

@override
Expand Down

0 comments on commit 4e6060d

Please sign in to comment.