class NewStatisticModel { final List lists; NewStatisticModel({required this.lists}); factory NewStatisticModel.fromJson(Map json) { return NewStatisticModel( lists: List.from( json['lists'].map((x) => CategoryList.fromJson(x))), ); } Map toJson() { return { 'lists': List.from(lists.map((x) => x.toJson())), }; } } class CategoryList { final int category; final String header; final List contents; CategoryList( {required this.category, required this.header, required this.contents}); factory CategoryList.fromJson(Map json) { return CategoryList( category: json['category'], header: json['header'], contents: List.from(json['contents'].map((x) => Content.fromJson(x))), ); } Map toJson() { return { 'category': category, 'header': header, 'contents': List.from(contents.map((x) => x.toJson())), }; } } class Content { final int id; final String label; final String title; final bool marked; final Data data; final String? subtitle; final String? imageUrl; Content( {required this.id, required this.label, required this.title, required this.marked, required this.data, this.subtitle, this.imageUrl}); factory Content.fromJson(Map json) { return Content( id: json['id'], label: json['label'], title: json['title'], marked: json['marked'], data: Data.fromJson(json['data']), subtitle: json['subtitle'], imageUrl: json['image_url'], ); } Map toJson() { return { 'id': id, 'label': label, 'title': title, 'marked': marked, 'data': data.toJson(), 'subtitle': subtitle, 'image_url': imageUrl, }; } } class Data { final String p; final num dp; final String dt; /// سری قیمت (close) برای رسم نمودار کوچک. در داده‌ی قدیمی خالی است، /// در market-service جدید از آرایه‌ی close پر می‌شود. final List prices; Data({ required this.p, required this.dp, required this.dt, this.prices = const [], }); /// درصد تغییر برای نمایش، با حداکثر چهار رقم اعشار و بدون صفرهای زائد. String get formattedDp { return _formatPercent(dp.toDouble()); } String get formattedAbsDp => _formatPercent(dp.abs().toDouble()); static String _formatPercent(double value) { if (value.abs() < 0.00005) return '0'; return value.toStringAsFixed(4).replaceFirst(RegExp(r'\.?0+$'), ''); } factory Data.fromJson(Map json) { return Data( p: json['p'], dp: json['dp'], dt: json['dt'], prices: const [], ); } Map toJson() { return { 'p': p, 'dp': dp, 'dt': dt, }; } }