From 6b4bb1fec45bcd01a33506f15fca08e27f8bab35 Mon Sep 17 00:00:00 2001 From: Foldblade Date: Sun, 13 Mar 2022 20:20:29 +0800 Subject: [PATCH] Fix #10 , update model_viewer_plus_mobile.dart _proxy null check and setState() for it --- lib/src/model_viewer_plus_mobile.dart | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/src/model_viewer_plus_mobile.dart b/lib/src/model_viewer_plus_mobile.dart index 2657787..9b55511 100644 --- a/lib/src/model_viewer_plus_mobile.dart +++ b/lib/src/model_viewer_plus_mobile.dart @@ -46,7 +46,14 @@ class ModelViewerState extends State { @override Widget build(final BuildContext context) { if (_proxy == null) { + return Center( + child: CircularProgressIndicator( + semanticsLabel: 'Loading Model Viewer...', + ), + ); + } else { return WebView( + backgroundColor: Colors.transparent, initialUrl: null, javascriptMode: JavascriptMode.unrestricted, initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow, @@ -97,11 +104,6 @@ class ModelViewerState extends State { '>>>> ModelViewer failed to load: ${error.description} (${error.errorType} ${error.errorCode})'); // DEBUG }, ); - } else { - return Center( - child: CircularProgressIndicator( - semanticsLabel: 'Loading Model Viewer...', - )); } } @@ -125,6 +127,11 @@ class ModelViewerState extends State { Future _initProxy() async { final url = Uri.parse(widget.src); _proxy = await HttpServer.bind(InternetAddress.loopbackIPv4, 0); + + setState(() { + _proxy; + }); + _proxy!.listen((final HttpRequest request) async { //print("${request.method} ${request.uri}"); // DEBUG //print(request.headers); // DEBUG