import 'package:scence_map/controllers/controller.dart'; class TaskItem { int id; int utc; String name; int workTotal; List list; String originLabel; CenterPileInfo centerPileInfo; //桩点生成中心设置 TaskItem({ required this.id, required this.utc, //创建时间 required this.name, //任务名称 required this.workTotal, required this.list, required this.originLabel, //任务来源标签(本地 平台) required this.centerPileInfo, }); factory TaskItem.fromJson(Map data) { return TaskItem( id: data['id'], utc: data['utc'], name: data['name'], workTotal: data['workTotal'], originLabel: data['originLabel'], centerPileInfo: CenterPileInfo.fromJson(data['centerPileInfo']), list: (data['list'] as List) .map((item) => PilePoint.fromJson(item)) .toList(), ); } Map toJson() { return { 'id': id, 'name': name, 'list': list.map((item) => item.toJson()).toList(), 'utc': utc, 'originLabel': originLabel, 'workTotal': workTotal, 'centerPileInfo': centerPileInfo.toJson(), }; } } class CenterPileInfo { double x; double y; // double direction; double space; double pileWidth; double angle; List distances; //桩点距离列表 CenterPileInfo({ required this.x, required this.y, // required this.direction, this.angle = 0, this.space = 5, this.pileWidth = 400, this.distances = const [5, 5, 5, 5], //上右下左(tips:和中心点的距离, 单位:米) }); factory CenterPileInfo.fromJson(Map data) { return CenterPileInfo( x: data['x'], y: data['y'], // direction: data['direction'], space: data['space'], pileWidth: data['pileWidth'], angle: data['angle'], distances: List.from( data['distances'].map((item) => (item ?? 10).toDouble())), ); } Map toJson() { return { 'x': x, 'y': y, // 'direction': direction, 'space': space, 'pileWidth': pileWidth, 'angle': angle, 'distances': distances, }; } }