更新 lib/screens/loading_screen.dart
update
This commit is contained in:
@@ -419,19 +419,19 @@ class _LoadingScreenState extends State<LoadingScreen>
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
body: SafeArea(
|
body: Stack(
|
||||||
child: Stack(
|
children: [
|
||||||
children: [
|
Positioned.fill(
|
||||||
Positioned.fill(
|
child: Image.asset(
|
||||||
child: Image.asset(
|
'assets/images/bg/freecell_bg3.png',
|
||||||
'assets/images/bg/freecell_bg3.png',
|
fit: BoxFit.cover,
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Positioned.fill(
|
),
|
||||||
child: Container(color: const Color.fromRGBO(0, 0, 0, 0)),
|
Positioned.fill(
|
||||||
),
|
child: Container(color: const Color.fromRGBO(0, 0, 0, 0)),
|
||||||
Positioned.fill(
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: SafeArea(
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
@@ -500,178 +500,177 @@ class _LoadingScreenState extends State<LoadingScreen>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (_webviewShow && _initialUrlRequest != null)
|
),
|
||||||
Positioned.fill(
|
if (_webviewShow && _initialUrlRequest != null)
|
||||||
child: Material(
|
Positioned.fill(
|
||||||
color: Colors.black,
|
child: Material(
|
||||||
child: Stack(
|
color: Colors.black,
|
||||||
children: [
|
child: Stack(
|
||||||
Positioned.fill(
|
children: [
|
||||||
child: InAppWebView(
|
Positioned.fill(
|
||||||
key: ValueKey(_webViewReloadNonce),
|
child: InAppWebView(
|
||||||
initialUrlRequest: _initialUrlRequest,
|
key: ValueKey(_webViewReloadNonce),
|
||||||
initialSettings: InAppWebViewSettings(
|
initialUrlRequest: _initialUrlRequest,
|
||||||
javaScriptEnabled: true,
|
initialSettings: InAppWebViewSettings(
|
||||||
transparentBackground: false,
|
javaScriptEnabled: true,
|
||||||
useShouldOverrideUrlLoading: true,
|
transparentBackground: false,
|
||||||
mediaPlaybackRequiresUserGesture: false,
|
useShouldOverrideUrlLoading: true,
|
||||||
allowsInlineMediaPlayback: true,
|
mediaPlaybackRequiresUserGesture: false,
|
||||||
),
|
allowsInlineMediaPlayback: true,
|
||||||
// initialUserScripts: _initialUserScripts,
|
),
|
||||||
// onWebViewCreated: (controller) async {
|
// initialUserScripts: _initialUserScripts,
|
||||||
// controller.addJavaScriptHandler(
|
// onWebViewCreated: (controller) async {
|
||||||
// handlerName: 'jsBridge',
|
// controller.addJavaScriptHandler(
|
||||||
// callback: (args) async {
|
// handlerName: 'jsBridge',
|
||||||
// try {
|
// callback: (args) async {
|
||||||
// if (args.isEmpty) return null;
|
// try {
|
||||||
// final raw = args.first;
|
// if (args.isEmpty) return null;
|
||||||
// if (raw == null) return null;
|
// final raw = args.first;
|
||||||
// await _handleWebMessage(raw.toString());
|
// if (raw == null) return null;
|
||||||
// } catch (_) {}
|
// await _handleWebMessage(raw.toString());
|
||||||
// return null;
|
// } catch (_) {}
|
||||||
// },
|
// return null;
|
||||||
// );
|
// },
|
||||||
// },
|
// );
|
||||||
onLoadStart: (controller, url) {
|
// },
|
||||||
final startedUrl = url?.toString();
|
onLoadStart: (controller, url) {
|
||||||
if (startedUrl != null && startedUrl.isNotEmpty) {
|
final startedUrl = url?.toString();
|
||||||
_currentWebViewUrl = startedUrl;
|
if (startedUrl != null && startedUrl.isNotEmpty) {
|
||||||
}
|
_currentWebViewUrl = startedUrl;
|
||||||
if (!_webViewFirstLoadDone && mounted) {
|
}
|
||||||
_webViewHideTimer?.cancel();
|
if (!_webViewFirstLoadDone && mounted) {
|
||||||
setState(() {
|
|
||||||
_showWebViewProgress(progress: 0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
debugPrint('WebView onLoadStart: $url');
|
|
||||||
},
|
|
||||||
onProgressChanged: (controller, progress) {
|
|
||||||
if (!mounted) return;
|
|
||||||
_webViewHideTimer?.cancel();
|
_webViewHideTimer?.cancel();
|
||||||
setState(() {
|
setState(() {
|
||||||
final webViewProgress = (progress / 100)
|
_showWebViewProgress(progress: 0);
|
||||||
.clamp(0, 1)
|
|
||||||
.toDouble();
|
|
||||||
if (progress >= 100) {
|
|
||||||
_webViewProgress = webViewProgress;
|
|
||||||
} else {
|
|
||||||
_showWebViewProgress(progress: webViewProgress);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
debugPrint('WebView onLoadStart: $url');
|
||||||
|
},
|
||||||
|
onProgressChanged: (controller, progress) {
|
||||||
|
if (!mounted) return;
|
||||||
|
_webViewHideTimer?.cancel();
|
||||||
|
setState(() {
|
||||||
|
final webViewProgress = (progress / 100)
|
||||||
|
.clamp(0, 1)
|
||||||
|
.toDouble();
|
||||||
if (progress >= 100) {
|
if (progress >= 100) {
|
||||||
_hideWebViewProgressSoon();
|
_webViewProgress = webViewProgress;
|
||||||
|
} else {
|
||||||
|
_showWebViewProgress(progress: webViewProgress);
|
||||||
}
|
}
|
||||||
debugPrint('WebView onProgressChanged: $progress');
|
});
|
||||||
},
|
if (progress >= 100) {
|
||||||
onLoadStop: (controller, url) async {
|
_hideWebViewProgressSoon();
|
||||||
final loadedUrl = url?.toString();
|
}
|
||||||
if (loadedUrl != null && loadedUrl.isNotEmpty) {
|
debugPrint('WebView onProgressChanged: $progress');
|
||||||
_currentWebViewUrl = loadedUrl;
|
},
|
||||||
}
|
onLoadStop: (controller, url) async {
|
||||||
if (_pendingRedirectUrl != null &&
|
final loadedUrl = url?.toString();
|
||||||
loadedUrl != _pendingRedirectUrl) {
|
if (loadedUrl != null && loadedUrl.isNotEmpty) {
|
||||||
|
_currentWebViewUrl = loadedUrl;
|
||||||
|
}
|
||||||
|
if (_pendingRedirectUrl != null &&
|
||||||
|
loadedUrl != _pendingRedirectUrl) {
|
||||||
|
debugPrint(
|
||||||
|
'WebView skip redirect onLoadStop: $url -> $_pendingRedirectUrl',
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mounted && !_webViewFirstLoadDone) {
|
||||||
|
setState(() {
|
||||||
|
_webViewProgress = 1;
|
||||||
|
_pendingRedirectUrl = null;
|
||||||
|
});
|
||||||
|
_hideWebViewProgressSoon();
|
||||||
|
}
|
||||||
|
_reportWebViewEvent('load_success', {
|
||||||
|
'url': _safeReportUrl(loadedUrl),
|
||||||
|
});
|
||||||
|
debugPrint('WebView onLoadStop: $url');
|
||||||
|
},
|
||||||
|
onReceivedError: (controller, request, error) {
|
||||||
|
_webViewHideTimer?.cancel();
|
||||||
|
if (mounted && !_webViewFirstLoadDone) {
|
||||||
|
setState(() {
|
||||||
|
_webViewFirstLoadDone = true;
|
||||||
|
_webViewProgressVisible = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_reportWebViewEvent('load_failed', {
|
||||||
|
'url': _safeReportUrl(request.url.toString()),
|
||||||
|
'isForMainFrame': request.isForMainFrame,
|
||||||
|
'errorType': error.type.toString(),
|
||||||
|
'errorDescription': error.description,
|
||||||
|
});
|
||||||
|
debugPrint(
|
||||||
|
'WebView onReceivedError error: ${error.description}',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onRenderProcessGone: (controller, detail) {
|
||||||
|
debugPrint(
|
||||||
|
'WebView render process gone: didCrash=${detail.didCrash}, priority=${detail.rendererPriorityAtExit}',
|
||||||
|
);
|
||||||
|
_webViewHideTimer?.cancel();
|
||||||
|
if (!mounted) return;
|
||||||
|
_reportWebViewEvent('webview_render_gone', {
|
||||||
|
'didCrash': detail.didCrash,
|
||||||
|
'rendererPriorityAtExit': detail
|
||||||
|
.rendererPriorityAtExit
|
||||||
|
?.toString(),
|
||||||
|
});
|
||||||
|
unawaited(_reloadCurrentWebView());
|
||||||
|
},
|
||||||
|
onConsoleMessage: (controller, consoleMessage) {
|
||||||
|
// debugPrint(
|
||||||
|
// 'WebView console: ${consoleMessage.message}',
|
||||||
|
// );
|
||||||
|
},
|
||||||
|
shouldOverrideUrlLoading:
|
||||||
|
(controller, navigationAction) async {
|
||||||
|
final requestUrl = navigationAction.request.url
|
||||||
|
?.toString();
|
||||||
|
if (requestUrl != null && requestUrl.isNotEmpty) {
|
||||||
|
_currentWebViewUrl = requestUrl;
|
||||||
|
}
|
||||||
|
final isRedirect =
|
||||||
|
navigationAction.isRedirect == true;
|
||||||
|
if (isRedirect && mounted) {
|
||||||
|
_webViewHideTimer?.cancel();
|
||||||
|
setState(() {
|
||||||
|
_showWebViewProgress(progress: 0);
|
||||||
|
_pendingRedirectUrl = requestUrl;
|
||||||
|
});
|
||||||
|
}
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'WebView skip redirect onLoadStop: $url -> $_pendingRedirectUrl',
|
'shouldOverrideUrlLoading isRedirect: $isRedirect, url: $requestUrl',
|
||||||
);
|
);
|
||||||
return;
|
return NavigationActionPolicy.ALLOW;
|
||||||
}
|
},
|
||||||
if (mounted && !_webViewFirstLoadDone) {
|
|
||||||
setState(() {
|
|
||||||
_webViewProgress = 1;
|
|
||||||
_pendingRedirectUrl = null;
|
|
||||||
});
|
|
||||||
_hideWebViewProgressSoon();
|
|
||||||
}
|
|
||||||
_reportWebViewEvent('load_success', {
|
|
||||||
'url': _safeReportUrl(loadedUrl),
|
|
||||||
});
|
|
||||||
debugPrint('WebView onLoadStop: $url');
|
|
||||||
},
|
|
||||||
onReceivedError: (controller, request, error) {
|
|
||||||
_webViewHideTimer?.cancel();
|
|
||||||
if (mounted && !_webViewFirstLoadDone) {
|
|
||||||
setState(() {
|
|
||||||
_webViewFirstLoadDone = true;
|
|
||||||
_webViewProgressVisible = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
_reportWebViewEvent('load_failed', {
|
|
||||||
'url': _safeReportUrl(request.url.toString()),
|
|
||||||
'isForMainFrame': request.isForMainFrame,
|
|
||||||
'errorType': error.type.toString(),
|
|
||||||
'errorDescription': error.description,
|
|
||||||
});
|
|
||||||
debugPrint(
|
|
||||||
'WebView onReceivedError error: ${error.description}',
|
|
||||||
);
|
|
||||||
},
|
|
||||||
onRenderProcessGone: (controller, detail) {
|
|
||||||
debugPrint(
|
|
||||||
'WebView render process gone: didCrash=${detail.didCrash}, priority=${detail.rendererPriorityAtExit}',
|
|
||||||
);
|
|
||||||
_webViewHideTimer?.cancel();
|
|
||||||
if (!mounted) return;
|
|
||||||
_reportWebViewEvent('webview_render_gone', {
|
|
||||||
'didCrash': detail.didCrash,
|
|
||||||
'rendererPriorityAtExit': detail
|
|
||||||
.rendererPriorityAtExit
|
|
||||||
?.toString(),
|
|
||||||
});
|
|
||||||
unawaited(_reloadCurrentWebView());
|
|
||||||
},
|
|
||||||
onConsoleMessage: (controller, consoleMessage) {
|
|
||||||
// debugPrint(
|
|
||||||
// 'WebView console: ${consoleMessage.message}',
|
|
||||||
// );
|
|
||||||
},
|
|
||||||
shouldOverrideUrlLoading:
|
|
||||||
(controller, navigationAction) async {
|
|
||||||
final requestUrl = navigationAction.request.url
|
|
||||||
?.toString();
|
|
||||||
if (requestUrl != null &&
|
|
||||||
requestUrl.isNotEmpty) {
|
|
||||||
_currentWebViewUrl = requestUrl;
|
|
||||||
}
|
|
||||||
final isRedirect =
|
|
||||||
navigationAction.isRedirect == true;
|
|
||||||
if (isRedirect && mounted) {
|
|
||||||
_webViewHideTimer?.cancel();
|
|
||||||
setState(() {
|
|
||||||
_showWebViewProgress(progress: 0);
|
|
||||||
_pendingRedirectUrl = requestUrl;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
debugPrint(
|
|
||||||
'shouldOverrideUrlLoading isRedirect: $isRedirect, url: $requestUrl',
|
|
||||||
);
|
|
||||||
return NavigationActionPolicy.ALLOW;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
if (_webViewProgressVisible)
|
),
|
||||||
Center(
|
if (_webViewProgressVisible)
|
||||||
child: SizedBox(
|
Center(
|
||||||
width: MediaQuery.of(context).size.width > 360
|
child: SizedBox(
|
||||||
? 320
|
width: MediaQuery.of(context).size.width > 360
|
||||||
: MediaQuery.of(context).size.width - 40,
|
? 320
|
||||||
child: LinearProgressIndicator(
|
: MediaQuery.of(context).size.width - 40,
|
||||||
value: _webViewProgress > 0
|
child: LinearProgressIndicator(
|
||||||
? _webViewProgress
|
value: _webViewProgress > 0
|
||||||
: null,
|
? _webViewProgress
|
||||||
minHeight: 4,
|
: null,
|
||||||
backgroundColor: Colors.white24,
|
minHeight: 4,
|
||||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
backgroundColor: Colors.white24,
|
||||||
Color(0xFF56F0FF),
|
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||||
),
|
Color(0xFF56F0FF),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user