Skip to content

Commit

Permalink
feat(deriv_web_view): add open in app web view with redirect url hand…
Browse files Browse the repository at this point in the history
…ling helper
  • Loading branch information
sahani-deriv committed Feb 5, 2024
1 parent c4a5321 commit c521a9f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/deriv_web_view/lib/deriv_web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:developer' as dev;

import 'package:deriv_web_view/helper.dart';
import 'package:deriv_web_view/widgets/in_app_browser/chrome_safari_browser.dart';
import 'package:deriv_web_view/widgets/in_app_browser/in_app_browser.dart';
import 'package:deriv_web_view/widgets/web_view_page/web_view_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -56,6 +57,35 @@ Future<void> openInAppTabActivityWebView({
}
}

/// Opens in-app tab activity web view.
/// Uses [AppChromeSafariBrowser] if available, otherwise uses [AppInAppBrowser]
/// which takes [uriHandler] to handle redirect uri.
Future<void> openInAppWebViewWithUriHandler({
required String url,
required String userAgent,
required Function(Uri) uriHandler,
required Function(String) onError,
required VoidCallback onClosed,
}) async {
try {
_openInAppTabView(url, onClosed);
} on PlatformException catch (_) {
final AppInAppBrowser browser = AppInAppBrowser(
onUrlChanged: (Uri uri) => uriHandler(uri),
onError: (String message) => onError(message),
);

await browser.openUrlRequest(
urlRequest: URLRequest(url: WebUri(url)),
settings: InAppBrowserClassSettings(
webViewSettings: InAppWebViewSettings(
userAgent: userAgent,
clearCache: true,
)),
);
}
}

bool get isInAppTabActivityWebViewOpen => appSafariBrowser.isOpened();

Future<void> closeInAppTabActivityWebView() => appSafariBrowser.close();
Expand Down

0 comments on commit c521a9f

Please sign in to comment.