Shashi Kiran
Shashi Kiran

Reputation: 1079

Android's webview.postUrl in Flutter

Is there a webview plugin that allows to post params to a webpage, equivalent to Android's webview.postUrl ?

I want to post parameters in a request body in flutter and that redirects to another webpage which I need to display. I am not able to find any current webview plugin that can do this. Is there a workaround for this?

Upvotes: 1

Views: 3557

Answers (1)

Lorenzo Pichilli
Lorenzo Pichilli

Reputation: 3429

You can use flutter_inappwebview plugin. It has the postUrl method:

inAppWebViewController.postUrl(String url, Uint8List postData);

Here is an example:

You could import the dart:convert library and encode your POST body string into a Uint8List data. To do that you can use, for example, the utf8.encode() method:

import 'dart:convert';

...

onWebViewCreated: (InAppWebViewController controller) {
  var data = "firstname=Foo&lastname=Bar";

  controller.postUrl(
    url: "http://192.168.1.123:8082/test-ajax-post",
    postData: utf8.encode(data));
},

Upvotes: 1

Related Questions