I'm using a webview to display Wordpress login page in my flutter app but when ever a user press back button, they always have to login back to their accounts so I'm just wondering how can I save their user login information in the cookie so that they don't have to login again after they use webview?
I'm using webview_flutter: ^2.0.4.
MyWebView Screen.
Expanded(
child: Center(
child: WebView(
initialUrl: "https://chinblog.com/wp-login.php",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
}),
))
It is a duplicate of 59733001. You can check the link and use webview cookie manager or you can get cookie from javascript channel in webview.
Related
I'm using a webview in Flutter and struggling to view the headers of a url request. Looking at the webview_flutter documentation the headers appear to be available via the WebViewRequest class but i'm not seeing that come through any delegate methods. Based upon the request URL i'd like to look at the headers and based on the URL and header combination perform specific actions within my app.
I've implemented the webview controller and am not seeing the WebViewRequest as a property that is available in any of the delegate methods.
My webview implementation for reference:
child: WebView(
initialUrl: null,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController w) {
_webViewController = w;
_webViewController.loadUrl(loginRequestUrl);
},
navigationDelegate: this._interceptNavigation,
onPageStarted: (url) {
// If URL is <login redirect URL> Check headers for success callback
// If we have success, call mobile API with token and close webview
print('Started Loading URL:');
print(url);
},
onPageFinished: (finish) {
// Reading response on finish
// If URL is <authenticated in app url> we've missed the success callback and webview is loading web-facing product
print('Finished Loading URL:');
print(finish);
},
),
You can use InAppWebView instead like this:
InAppWebView(
initialUrlRequest:
URLRequest(url: Uri.parse("https://stackoverflow.com")),
initialOptions: InAppWebViewGroupOptions(
crossPlatform:
InAppWebViewOptions(useShouldOverrideUrlLoading: true),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
),
),
shouldOverrideUrlLoading: (controller, navigationAction) async {
var request = navigationAction.request;
var url = request.url;
if (request.headers != null) {
print('see header');
return NavigationActionPolicy.ALLOW;
}
return NavigationActionPolicy.ALLOW;
},
)
I am working on app where I need to show certificate in pdf format inside WebView from specific URL. I am using webview_flutter plugin for webview.
Please consider the below mentioned code:
WebView(
debuggingEnabled: true,
initialUrl: Uri.encodeFull('https://docs.google.com/gview?embedded=true&url=${strUrl}'),
javascriptMode: JavascriptMode.unrestricted,
onProgress: (int progress) {
print('WebView is loading (progress : $progress%)');
},
onWebViewCreated: (webViewController) {
_controller.complete(webViewController);
webViewController.clearCache();
final cookieManager = CookieManager();
cookieManager.clearCookies();
},
),
Now on the progress log if the webview loads certificate properly then the progress shows like 10, 15, 30, 50, 80, 100. But in the case of white screen on no data loading progress went like 10, to directly 100. Logs are not working properly.
I couldn't use other libs or plugin, Is there any solution for same?
Progress in HTTP isn't an absolute so you cannot always expect a "smooth" progress. Sometimes data chunks will be received in buffers that are outside your control so this behavior isn't surprising.
I'm looking for a way to get the actual Flutter Webview User Agent before loading an url.
It seems not be possible...
WebView(
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController controller) {
controller
.runJavascriptReturningResult('navigator.userAgent')
.then((String currentUserAgent) {
controller.loadUrl('https://stackoverflow.com/q/70882313/17473716');
}
}
)
I am not an expert of Flutter.
I am creating a WebView of this website
https://nearxt.com/
which asks for location when opened but when i use this link to create a webview in flutter
then it can not take location
i have also defined location in the application but webview cant recieve location
SafeArea(
child: WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: flutterUrl,
onWebViewCreated: (WebViewController webViewController) {
_controller = webViewController;
},
),
),
This is unsupported in flutter. Even if you try to ask for location access using permission handler the app will deny it and still if you manually give the location permission to the app from your phone it still won't catch the real time location. Suggestion is to use plain old java for it you can find a lot of help around the internet about webview in java with location access it works perfect.
Use flutter_inappwebview to get users location
InAppWebView(
initialUrlRequest:
URLRequest(url: Uri.parse('your link here')),
androidOnGeolocationPermissionsShowPrompt:
(InAppWebViewController controller, String origin) async {
return GeolocationPermissionShowPromptResponse(
origin: origin,
allow: true,
retain: true
);
},
)
I wanna load HTML string through plugin webview_flutter, I try it like those:
But I couldn't load an image in my HTML string, meanwhile, I made WebView as a child for SizedBox, its height and width were adapted to device screen. Even though, it still exceeded device's width. I check the official demo, but it was futile
return WebView(
initialUrl: '',
onWebViewCreated: (controller) async {
String content = base64Encode(Utf8Encoder().convert(html));
controller.loadUrl('data:text/html;base64,$content');
},
);