@@ -22,7 +22,7 @@ import 'package:flutter/foundation.dart';
22
22
import 'package:flutter/material.dart' ;
23
23
import 'package:flutter/services.dart' show rootBundle;
24
24
25
- import 'package:flutter_inappwebview/flutter_inappwebview.dart' ;
25
+ // import 'package:flutter_inappwebview/flutter_inappwebview.dart';
26
26
import 'package:url_launcher/url_launcher.dart' show launchUrl, LaunchMode;
27
27
28
28
import './theme.dart' show standardAppBar;
@@ -32,20 +32,20 @@ const String kDocsDir = 'docs';
32
32
const String kLoadingHTMLFilePath = "$kDocsDir /loading.html" ;
33
33
const String kLoadingDarkHTMLFilePath = "$kDocsDir /loading_dark.html" ;
34
34
35
- late InAppWebViewInitialData loadingHTMLData;
36
- late InAppWebViewInitialData loadingDarkHTMLData;
37
-
38
- /// Preloads the "loading" HTML documents to prevent any initial
39
- /// lag when showing loading indicator for documentation pages.
40
- Future <void > preloadHTMLDocuments () async {
41
- dlog ("Preloading HTML loading documents" );
42
- loadingHTMLData =
43
- InAppWebViewInitialData (data: await rootBundle.loadString (kLoadingHTMLFilePath));
44
- loadingHTMLData.baseUrl = Uri .parse ("file:///" );
45
- loadingDarkHTMLData =
46
- InAppWebViewInitialData (data: await rootBundle.loadString (kLoadingDarkHTMLFilePath));
47
- loadingDarkHTMLData.baseUrl = Uri .parse ("file:///" );
48
- }
35
+ // late InAppWebViewInitialData loadingHTMLData;
36
+ // late InAppWebViewInitialData loadingDarkHTMLData;
37
+
38
+ // // / Preloads the "loading" HTML documents to prevent any initial
39
+ // // / lag when showing loading indicator for documentation pages.
40
+ // Future<void> preloadHTMLDocuments() async {
41
+ // dlog("Preloading HTML loading documents");
42
+ // loadingHTMLData =
43
+ // InAppWebViewInitialData(data: await rootBundle.loadString(kLoadingHTMLFilePath));
44
+ // loadingHTMLData.baseUrl = Uri.parse("file:///");
45
+ // loadingDarkHTMLData =
46
+ // InAppWebViewInitialData(data: await rootBundle.loadString(kLoadingDarkHTMLFilePath));
47
+ // loadingDarkHTMLData.baseUrl = Uri.parse("file:///");
48
+ // }
49
49
50
50
/// Standard web view route used for displaying HTML documentation files.
51
51
class WebViewRoute extends StatefulWidget {
@@ -70,86 +70,84 @@ class WebViewRouteState extends State<WebViewRoute> {
70
70
return "$url ?dark=1" ;
71
71
}
72
72
73
- /// Fall back to local HTML document if error comes
74
- /// up when fetching document from remote server.
75
- void errHandler (InAppWebViewController controller, Uri ? url, int errCode, String desc) async {
76
- dlog ("Page load error for $url : $errCode , $desc " );
77
- final String path = _fallbackAssetForURL (url.toString ());
78
- dlog ("Falling back to local asset $path " );
79
- setState (() {
80
- controller.loadFile (assetFilePath: path);
81
- });
82
- }
83
-
84
- /// Handle clicks on links in HTML documentation.
85
- /// These links should be opened in an external browser to
86
- /// avoid screwing with the navigation stack of the app.
87
- Future <NavigationActionPolicy > urlClickHandler (
88
- InAppWebViewController controller, NavigationAction action) async {
89
- final URLRequest req = action.request;
90
- final String urlStr = req.url.toString ();
91
- final String fallbackFilename = _fallbackAssetForURL (urlStr);
92
-
93
- if (urlStr.startsWith (widget.initialURL) == false &&
94
- urlStr.endsWith (fallbackFilename) == false ) {
95
- // It's not a local URL, so open it in an external browser
96
- dlog ("Opening external URL: ${req .url }" );
97
- await launchUrl (req.url! , mode: LaunchMode .externalApplication);
98
- return NavigationActionPolicy .CANCEL ;
99
- }
100
-
101
- return NavigationActionPolicy .ALLOW ;
102
- }
103
-
104
- /// Create web view that initially presents a "loading" document with
105
- /// a progress indicator. Then immediately fetch the actual remote document.
106
- /// Falls back to loading a local bundled HTML document with the same name
107
- /// on network error. This ensures that at least *some* version of the
108
- /// document can be viewed even when the device is offline.
109
- InAppWebView _buildWebView (BuildContext context) {
110
- final darkMode = (MediaQuery .platformBrightnessOf (context) == Brightness .dark);
111
- final loadingURL = darkMode ? kLoadingDarkHTMLFilePath : kLoadingHTMLFilePath;
112
- final finalURL = darkMode ? _darkURLForURL (widget.initialURL) : widget.initialURL;
113
- final initialData = darkMode ? loadingDarkHTMLData : loadingHTMLData;
114
-
115
- final webViewOpts = InAppWebViewGroupOptions (
116
- crossPlatform: InAppWebViewOptions (
117
- clearCache: kDebugMode,
118
- useShouldOverrideUrlLoading: true ,
119
- transparentBackground: true ,
120
- ));
121
-
122
- // Create and configure web view
123
- return InAppWebView (
124
- initialData: initialData,
125
- initialUrlRequest: URLRequest (url: Uri .parse (finalURL)),
126
- initialOptions: webViewOpts,
127
- onLoadStart: (InAppWebViewController controller, Uri ? uri) {
128
- dlog ("Loading URL ${uri .toString ()}" );
129
- },
130
- onLoadStop: (InAppWebViewController controller, Uri ? uri) async {
131
- final String urlStr = uri.toString ();
132
- if (urlStr.endsWith (loadingURL) || urlStr == 'about:blank' || urlStr == 'file:///' ) {
133
- // Loading of initial "loading" document is complete.
134
- // Now load the actual remote document.
135
- setState (() {
136
- controller.loadUrl (urlRequest: URLRequest (url: Uri .parse (finalURL)));
137
- });
138
- }
139
- },
140
- onLoadError: errHandler,
141
- onLoadHttpError: errHandler,
142
- shouldOverrideUrlLoading: urlClickHandler,
143
- onConsoleMessage: (InAppWebViewController controller, ConsoleMessage msg) {
144
- dlog ("Web View Console message: ${msg .message }" );
145
- });
146
- }
73
+ // // / Fall back to local HTML document if error comes
74
+ // // / up when fetching document from remote server.
75
+ // void errHandler(InAppWebViewController controller, Uri? url, int errCode, String desc) async {
76
+ // dlog("Page load error for $url: $errCode, $desc");
77
+ // final String path = _fallbackAssetForURL(url.toString());
78
+ // dlog("Falling back to local asset $path");
79
+ // setState(() {
80
+ // controller.loadFile(assetFilePath: path);
81
+ // });
82
+ // }
83
+
84
+ // // / Handle clicks on links in HTML documentation.
85
+ // // / These links should be opened in an external browser to
86
+ // // / avoid screwing with the navigation stack of the app.
87
+ // Future<NavigationActionPolicy> urlClickHandler(
88
+ // InAppWebViewController controller, NavigationAction action) async {
89
+ // final URLRequest req = action.request;
90
+ // final String urlStr = req.url.toString();
91
+ // final String fallbackFilename = _fallbackAssetForURL(urlStr);
92
+
93
+ // if (urlStr.startsWith(widget.initialURL) == false &&
94
+ // urlStr.endsWith(fallbackFilename) == false) {
95
+ // // It's not a local URL, so open it in an external browser
96
+ // dlog("Opening external URL: ${req.url}");
97
+ // await launchUrl(req.url!, mode: LaunchMode.externalApplication);
98
+ // return NavigationActionPolicy.CANCEL;
99
+ // }
100
+
101
+ // return NavigationActionPolicy.ALLOW;
102
+ // }
103
+
104
+ // // / Create web view that initially presents a "loading" document with
105
+ // // / a progress indicator. Then immediately fetch the actual remote document.
106
+ // // / Falls back to loading a local bundled HTML document with the same name
107
+ // // / on network error. This ensures that at least *some* version of the
108
+ // // / document can be viewed even when the device is offline.
109
+ // InAppWebView _buildWebView(BuildContext context) {
110
+ // final darkMode = (MediaQuery.platformBrightnessOf(context) == Brightness.dark);
111
+ // final loadingURL = darkMode ? kLoadingDarkHTMLFilePath : kLoadingHTMLFilePath;
112
+ // final finalURL = darkMode ? _darkURLForURL(widget.initialURL) : widget.initialURL;
113
+ // final initialData = darkMode ? loadingDarkHTMLData : loadingHTMLData;
114
+
115
+ // final webViewOpts = InAppWebViewGroupOptions(
116
+ // crossPlatform: InAppWebViewOptions(
117
+ // clearCache: kDebugMode,
118
+ // useShouldOverrideUrlLoading: true,
119
+ // transparentBackground: true,
120
+ // ));
121
+
122
+ // // Create and configure web view
123
+ // return InAppWebView(
124
+ // initialData: initialData,
125
+ // initialUrlRequest: URLRequest(url: Uri.parse(finalURL)),
126
+ // initialOptions: webViewOpts,
127
+ // onLoadStart: (InAppWebViewController controller, Uri? uri) {
128
+ // dlog("Loading URL ${uri.toString()}");
129
+ // },
130
+ // onLoadStop: (InAppWebViewController controller, Uri? uri) async {
131
+ // final String urlStr = uri.toString();
132
+ // if (urlStr.endsWith(loadingURL) || urlStr == 'about:blank' || urlStr == 'file:///') {
133
+ // // Loading of initial "loading" document is complete.
134
+ // // Now load the actual remote document.
135
+ // setState(() {
136
+ // controller.loadUrl(urlRequest: URLRequest(url: Uri.parse(finalURL)));
137
+ // });
138
+ // }
139
+ // },
140
+ // onLoadError: errHandler,
141
+ // onLoadHttpError: errHandler,
142
+ // shouldOverrideUrlLoading: urlClickHandler,
143
+ // onConsoleMessage: (InAppWebViewController controller, ConsoleMessage msg) {
144
+ // dlog("Web View Console message: ${msg.message}");
145
+ // });
146
+ // }
147
147
148
148
@override
149
149
Widget build (BuildContext context) {
150
- return Scaffold (
151
- appBar: standardAppBar,
152
- body: _buildWebView (context),
153
- );
150
+ return Scaffold (appBar: standardAppBar, body: standardAppBar //buildWebView(context),
151
+ );
154
152
}
155
153
}
0 commit comments