如何在Flutter Dio软件包中添加地图

发布于 2025-02-12 17:57:23 字数 608 浏览 0 评论 0原文

我想使用DIO软件包将表单数据发送到后端,其中一个字段接受地图而不是字符串。

formData.fields.add(MapEntry('category', _category));
    formData.fields.add(MapEntry('license_number', _licenseNumber.text));
    formData.fields.add(MapEntry('license_issued_on', _licenseIssueDateString));
//The line below is the one causing the error. The argument type 'Map<String, Object>' can't be assigned to the parameter type 'String'.
   formData.fields.add(MapEntry('address', {'address': _address.text, 'lattitude': _addressLat, 'longitude': _addressLng}));

FormData接口提供了一种方法,可以轻松构造一组键/值对,代表表单字段及其值 我该如何解决这个问题?

I want to send a form data to the backend using the Dio package one of the fields accepts a map instead of a String.

formData.fields.add(MapEntry('category', _category));
    formData.fields.add(MapEntry('license_number', _licenseNumber.text));
    formData.fields.add(MapEntry('license_issued_on', _licenseIssueDateString));
//The line below is the one causing the error. The argument type 'Map<String, Object>' can't be assigned to the parameter type 'String'.
   formData.fields.add(MapEntry('address', {'address': _address.text, 'lattitude': _addressLat, 'longitude': _addressLng}));

The FormData interface provides a way to easily construct a set of key/value pairs representing form fields and their values
How can I go around this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终止放荡 2025-02-19 17:57:23

将地图转换为JSON字符串。自然的后端必须解码一个字符串。

字段→列表&lt; mapentry&lt; string,string&gt;&gt;
发送此请求的表单字段。

import 'dart:convert';

formData.fields.add(MapEntry('address', jsonEncode({'address': _address.text, 'lattitude': _addressLat, 'longitude': _addressLng})));

Convert a map to a JSON string. Naturally backend has to decode a string.

fields → List<MapEntry<String, String>>
The form fields to send for this request.

import 'dart:convert';

formData.fields.add(MapEntry('address', jsonEncode({'address': _address.text, 'lattitude': _addressLat, 'longitude': _addressLng})));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文