尝试将参数
a=1&b=2
传递到 WebView URI:
Uri uri = Uri.parse('http://localhost:8080');
var body = Uint8List.fromList(utf8.encode('a=1&b=2')));
WebViewController controller = WebViewController()
..loadRequest(uri, body: body);
WebViewWidget(controller: controller);
服务器端参数
a
和 b
为空。
你可以通过
Uri uri = Uri.parse('localhost:8080?a=1&b=2');
如果 a 和 b null 你可以像下面这样传递
Uri uri = Uri.parse('localhost:8080?a=&b=');
高级
import 'dart:convert';
void main() {
var a = '1';
var b = '2';
var encodedA = Uri.encodeQueryComponent(a);
var encodedB = Uri.encodeQueryComponent(b);
var url = 'http://localhost:8080?a=$encodedA&b=$encodedB';
print(url); // This will print the properly encoded URL
}
检查value是否为null;通过“”空白。
但是在Flutter中,你不能这样调用localhost。
https://medium.com/@podcoder/connecting-flutter-application-to-localhost-a1022df63130