提问人:Phuris SOMKAEW 提问时间:10/31/2023 最后编辑:Brian Tompsett - 汤莱恩Phuris SOMKAEW 更新时间:10/31/2023 访问量:25
我怎样才能在列表“EngName”(Flutter)中仅获得子列表值“Bangkok”(类型:list<dynamic>)
How can I get sublist value only "Bangkok" in list "EngName" (Flutter) (type: list<dynamic>)
问:
我想在“EngName”列表中获得“Bangkok”的值
--->这是我的json数据
这就是我的飞镖代码:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_report/RainfallThai.dart';
import 'package:http/http.dart' as http;
import 'package:syncfusion_flutter_charts/charts.dart';
class LineCharts extends StatefulWidget {
const LineCharts({super.key});
@override
State<LineCharts> createState() => _DashBoardDBState();
}
class _DashBoardDBState extends State<LineCharts> {
List<RainfallThai> usersA = [];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Line Charts"),
backgroundColor: Colors.pink[300],
),
body: Container(
child: SfCartesianChart(
primaryXAxis: CategoryAxis(),
title: ChartTitle(text: 'ปริมาณน้ำฝน'),
legend: Legend(
isVisible: true,
),
tooltipBehavior: TooltipBehavior(enable: true),
series: <ChartSeries<RainfallThai, String>>[
LineSeries<RainfallThai, String>(
dataSource: usersA,
xValueMapper: (RainfallThai monthai, _) => monthai.MonThai,
yValueMapper: (RainfallThai avgrain, _) =>
num.tryParse(avgrain.AvgRain),
dataLabelSettings: DataLabelSettings(isVisible: true),
),
]),
),
floatingActionButton: FloatingActionButton(
onPressed: fetchUsersA,
backgroundColor: Colors.amber,
child: Icon(Icons.auto_graph_rounded),
),
);
}
@override
void initState() {
super.initState();
fetchUsersA();
}
void fetchUsersA() async {
print('LINE CHART called');
const urlA = "https://v1.nocodeapi.com/synatic/csv2json/pOWwVHFulerJvWnC";
final uriA = Uri.parse(urlA);
final responseA = await http.get(uriA);
final bodyA = responseA.body;
final jsonsA = jsonDecode(bodyA);
final jsonA = jsonsA['json'] as List<dynamic>;
final transformedA = jsonA.map((obj) {
print(obj['EngName']);
return RainfallThai(
ProvinceName: '',
EngName: obj['EngName'],
toID: '',
MonThai: obj['MonThai'],
MinRain: '',
MaxRain: '',
AvgRain: obj['AvgRain'],
region: '',
Year: obj['Year'],
Month: '',
Date: '');
}).toList();
setState(() {
usersA = transformedA;
});
print('LINE CHART completed');
}
}
这就是---->的输出
print(obj['EngName']);
输出
打印输出的--->图像
总之,我想知道仅在子列表中显示值的输出如何
颤动:曼谷
并非子列表中的每个数据
答:
0赞
Ivo
10/31/2023
#1
更改此行
final jsonA = jsonsA['json'] as List<dynamic>;
自
final jsonA = (jsonsA['json'] as List<dynamic>).sublist(0,1);
评论