Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring app from background, results in webview_flutter showing a black screen. #148128

Closed
ElixirMike opened this issue May 10, 2024 · 4 comments
Labels
r: solved Issue is closed as solved

Comments

@ElixirMike
Copy link

Steps to reproduce

Here is my current flutter versions

Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f468f33 (10 months ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1

I am using webview_flutter version 4.5.0.

On my flutter app, when I'm viewing content on android device, using the webview_controller. If there is a link, I use a URL launcher package to launch external browser. Then, when I navigate to bring my app up from background, it shows black screen where HTML content should be.

I have not tested on IOS device.

Expected results

Expected that when I bring up app from background, it will show app with html content.

Actual results

When I bring app from background, it's showing black screen.

FYI, I can't reproduce this in my emulator...only happens on physical Pixel device.

Code sample

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

class MyWebView extends StatefulWidget {
final String htmlContent;

MyWebView({required this.htmlContent});

@OverRide
_MyWebViewState createState() => _MyWebViewState();
}

class _MyWebViewState extends State {
late final WebViewController _webViewController;
bool _isLoading = true;

Future _launchInBrowser(String url) async {
Uri uri = Uri.parse(url);

if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
  throw Exception('Could not launch $url');
}

}

@OverRide
void initState() {
super.initState();
_webViewController = WebViewController();
_webViewController.setNavigationDelegate(NavigationDelegate(
onNavigationRequest: (NavigationRequest request) {
// Check if the URL is an external link and not the initial content load
if (request.url != 'about:blank' &&
Uri.tryParse(request.url)?.hasAbsolutePath == true) {
_launchInBrowser(request.url);
return NavigationDecision
.prevent; // Prevent further navigation in WebView
}
return NavigationDecision.navigate; // Allow navigation within WebView
// _launchInBrowser(request.url);
// return NavigationDecision.prevent;
},
onUrlChange: (UrlChange change) {
debugPrint('url change to ${change.url}');
},
));
loadHtml();
}

Future loadHtml() async {
//
//<style>html,body{font-size: 30px;}</style>
String htmlString =
'${widget.htmlContent}';
await _webViewController.loadHtmlString(htmlString);

setState(() {
  _isLoading = false;
});

}

@OverRide
Widget build(BuildContext context) {
return _isLoading
? Center(
child: CircularProgressIndicator(),
)
: Container(
height: 1600, child: WebViewWidget(controller: _webViewController));
}
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

[√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [Version 10.0.19045.4291], locale en-US)
• Flutter version 3.10.6 on channel stable at C:\development\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f468f33 (10 months ago), 2023-07-12 15:19:05 -0700
• Engine revision cdbeda788a
• Dart version 3.0.6
• DevTools version 2.23.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\Mike\AppData\Local\Android\Sdk
• Platform android-33, build-tools 30.0.3
• ANDROID_HOME = C:\Users\Mike\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[!] Visual Studio - develop for Windows (Visual Studio Build Tools 2017 15.9.16)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
• Visual Studio Build Tools 2017 version 15.9.28307.858
• Windows 10 SDK version 10.0.17763.0
X Visual Studio 2019 or later is required.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 4.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.89.0)
• VS Code at C:\Users\Mike\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.88.0

[√] Connected device (1 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.4291]

[√] Network resources
• All expected network resources are available.

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 10, 2024
@darshankawar
Copy link
Member

only happens on physical Pixel device.

What OS version is on this device @ElixirMike ? If 14 or 15, most probably you are hitting #146499 that has been recently fixed. So you will need to switch to latest master or beta and re-run your scenario to check and confirm.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 10, 2024
@ElixirMike
Copy link
Author

I am on version14 on my phone. So you are saying I need to be on latest version of Flutter and version 4.7.0 of webview_flutter?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 10, 2024
@Pholluxion
Copy link

same issue in Android 11 and version 4.7.0 of webview_flutter.

@ElixirMike
Copy link
Author

Upgrading to the latest flutter and version .4.7.;0 of webview_flutter seems have solved the issue for me.

@darshankawar darshankawar added r: solved Issue is closed as solved and removed in triage Presently being triaged by the triage team labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r: solved Issue is closed as solved
Projects
None yet
Development

No branches or pull requests

3 participants