import 'package:flutter/services.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; // Private host/plugin bridge. These settings never originate from extension JS. class WebViewProfileSettings extends InAppWebViewSettings { WebViewProfileSettings({required this.profileId, required bool debug, super.userAgent}) : super(javaScriptEnabled: true, transparentBackground: true, isInspectable: debug); final String profileId; @override Map toMap() => {...super.toMap(), 'gopeedProfileId': profileId}; } class WebViewProfile { WebViewProfile(this.id); final String id; static const _channel = MethodChannel('com.pichillilorenzo/flutter_inappwebview_cookiemanager'); Future remove() async { await _call('gopeed.removeProfile', {}); } Future prepare(String proxyUrl) async { await _call('gopeed.prepareProfile', {'proxyUrl': proxyUrl}); } Future _call(String method, Map arguments) => _channel.invokeMethod(method, {...arguments, 'gopeedProfileId': id}); Future> getCookies({required WebUri url}) async { final values = await _call('getCookies', {'url': url.toString()}) as List? ?? []; return values.map((value) => Cookie.fromMap(Map.from(value as Map))!).toList(); } Future setCookie({ required WebUri url, required String name, required String value, String? domain, String path = '/', int? expiresDate, bool isSecure = false, bool isHttpOnly = false, }) async { await _call('setCookie', { 'url': url.toString(), 'name': name, 'value': value, 'domain': domain, 'path': path, 'expiresDate': expiresDate?.toString(), 'isSecure': isSecure, 'isHttpOnly': isHttpOnly, }); } Future deleteCookie({required WebUri url, required String name, String? domain, String path = '/'}) async { await _call('deleteCookie', {'url': url.toString(), 'name': name, 'domain': domain, 'path': path}); } Future deleteAllCookies() async { await _call('deleteAllCookies', {}); } }