gpt4 book ai didi

dart - 如何将photo_reference值存储为字符串?

转载 作者:行者123 更新时间:2023-12-03 04:04:40 24 4
gpt4 key购买 nike

我正在尝试使用dart构建我的第一个Android应用程序。该应用程序理想情况下可以提取附近的结果,但我无法随照片一起获取照片。如何在“照片”数组中引用照片引用? Dart非常令人困惑。

import 'package:meta/meta.dart';

class Casino{
Casino({
@required this.name,
@required this.id,
@required this.photos,
@required this.overview,
this.favored,
});

String name,id,overview,photos;
bool favored;

Casino.fromJson(Map json)
: name = json["name"],
photos = json["photos"].getString("photo_reference"),
id = json["place_id"].toString(),
overview = json["overview"],
favored = false;

}

引用位置:
Widget build(BuildContext context){
return Card(
child: Container(
height:200.0,
padding: EdgeInsets.all(10.0),
child: Row(
children: <Widget>[
casinoState.photos != null
? Hero(
child: Image.network(
"https://maps.googleapis.com/maps/api/place/photo?photoreference=${casinoState.photos}&sensor=false&maxheight=200&maxwidth=150&key=$key"),
tag:casinoState.id,
)
:Container(),

JSON格式:
{
"html_attributions": [],
"results": [
{
"geometry": {
"location": {
"lat": 40.1186169,
"lng": -74.9532456
},
"viewport": {
"northeast": {
"lat": 40.1199658802915,
"lng": -74.95189661970849
},
"southwest": {
"lat": 40.1172679197085,
"lng": -74.95459458029151
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id": "080658566051e777f8c81b9a80db271629fd76a3",
"name": "Parx Casino",
"opening_hours": {
"open_now": true,
"weekday_text": []
},
"photos": [
{
"height": 1152,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/117948925865341354264/photos\">Parx Casino</a>"
],
"photo_reference": "CmRaAAAABWy8pB7dKcz-M7iOpSdHMB1xmrN_EmFtxOh02aVemQsLdx4CqCsIOMIGKf6sHiEH2ukIJRNtF4b_NQ4SoXe-c65JxVnqo798RCyIjut9cq5pcquMx4-_D1TDPFjcLFEpEhDtNZHxFvLAeo6UESFM5vGMGhTuy6b3LoyD_KhCXudBmBHWaYlVmA",
"width": 2048
}
],

最佳答案

photos包含一个数组。要获取第一个元素,请使用[0]

photos = json["photos"][0]["photo_reference"],

关于dart - 如何将photo_reference值存储为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50257590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com