我正在使用 InAppWebView 插件中的 InAppBrowser 类在我的颤振应用程序中打开浏览器。
案例:我正在检查流中的网络,所以如果没有连接来隐藏浏览器,如果有继续浏览
问题:显示浏览器后,当我想隐藏它时不起作用
主要代码
StreamBuilder(
stream: networkStatusStream(),
builder: (BuildContext context, snapshot) {
if ( snapshot.hasData) {
checkNetworkStatus(snapshot.data);
}
if(netState){
browser.openUrl(url: url);
return Container(color: clrGrey,);
}
else {
browser.hide();
return OfflineScreen();
}},)
InAppBrowser 类
class MyInAppBrowser extends InAppBrowser {
@override
Future onBrowserCreated() async {
print("\n\nBrowser Created!\n\n");
}
@override
Future onLoadStart(url) async {
print("\n\nStarted $url\n\n");
}
@override
Future onLoadStop(url) async {
print("\n\nStopped $url\n\n");
}
@override
void onLoadError(url, code, message) {
print("Can't load $url.. Error: $message");
}
@override
void onProgressChanged(progress) {
print("Progress: $progress");
}
@override
void onExit() {
print("\n\nBrowser closed!\n\n");
}
@override
void onLoadResource(LoadedResource response) {
print("Started at: " +
response.startTime.toString() +
"ms ---> duration: " +
response.duration.toString() +
"ms " +
(response.url?.toString() ?? ''));
}
@override
void onConsoleMessage(ConsoleMessage consoleMessage) {
print("""
console output:
message: ${consoleMessage.message}
messageLevel: ${consoleMessage.messageLevel.toValue()}
""");
}
} ```