openInNewTab static method
Static method to open a URL in a new browser tab Can be called from custom buttons stacked over the widget Web platform only - no-op on native platforms
Parameters:
url: The URL to open in a new tabaddToProxyCacheForNextTime: If true, the URL will be marked as requiring a proxy for future loads. Default is true (maintains existing behavior).
Example usage:
Stack(children: [
SWebView(url: 'https://example.com'),
Positioned(
top: 10,
right: 10,
child: PointerInterceptor(
child: ElevatedButton(
// With proxy cache update (default)
onPressed: () => SWebView.openInNewTab('https://example.com'),
child: Text('Open in New Tab'),
),
),
),
])
Example without proxy caching:
ElevatedButton(
onPressed: () => SWebView.openInNewTab(
'https://example.com',
addToProxyCacheForNextTime: false,
),
child: Text('Open'),
)
Implementation
static Future<void> openInNewTab(
String url, {
bool addToProxyCacheForNextTime = true,
}) async {
if (kDebugMode) {
debugPrint('SWebView: Opening in new tab: $url');
if (addToProxyCacheForNextTime) {
debugPrint('SWebView: URL marked to use proxy for next load: $url');
} else {
debugPrint(
'SWebView: ⚠️ SUGGESTION: Add "${Uri.parse(url).host}" to restrictedDomains list');
}
}
// Mark URL as needing proxy for future loads (default behavior)
if (addToProxyCacheForNextTime) {
_SWebViewState._restrictionCache[url] = true;
}
await _SWebViewState._saveCache();
// Open in new tab (web platform)
if (kIsWeb) {
web_utils.openInNewTab(url);
}
}