Line data Source code
1 : import 'package:url_launcher/url_launcher.dart'; 2 : 3 : import '../../src/main.dart'; 4 : 5 : /// List of static methods to interact with the browser 6 : /// Only one is implemented for mobile: pushExternal 7 : 8 : class BrowserHelpers { 9 0 : static void replaceHistoryState(String state) => 10 0 : throw (Exception('replaceHistoryState should only be used on the web')); 11 : 12 0 : static String? getHistoryState() => 13 0 : throw (Exception('getHistoryState should only be used on the web')); 14 : 15 0 : static int? getHistorySerialCount() => 16 0 : throw (Exception('getHistorySerialCount should only be used on the web')); 17 : 18 0 : static String getPathAndQuery({required VRouterModes routerMode}) => 19 0 : throw (Exception('getHistorySerialCount should only be used on the web')); 20 : 21 0 : static void browserGo(int delta) => 22 0 : throw (Exception('browserGo should only be used on the web')); 23 : 24 0 : static Stream get onBrowserPopState => 25 0 : throw (Exception('onBrowserPopState should only be used on the web')); 26 : 27 0 : static Stream get onBrowserBeforeUnload => 28 0 : throw (Exception('onBrowserBeforeUnload should only be used on the web')); 29 : 30 : /// This uses the launch method from the [url_launcher] package to open a given link 31 : /// [openNewTab] does nothing here since we open a window anyway 32 0 : static Future<void> pushExternal(String url, 33 : {required bool openNewTab}) async { 34 0 : if (await canLaunch(url)) { 35 0 : await launch(url); 36 : } else { 37 0 : throw Exception('Could not launch $url'); 38 : } 39 : } 40 : 41 0 : static void pushReplacement(String url, {required VRouterModes routerMode}) => 42 0 : throw (Exception('pushReplacement should only be used on the web')); 43 : }