Skip to content

Instantly share code, notes, and snippets.

@preetjdp
Created May 22, 2021 12:44
Show Gist options
  • Save preetjdp/f37033a3eda0491dbf02465b63344fab to your computer and use it in GitHub Desktop.
Save preetjdp/f37033a3eda0491dbf02465b63344fab to your computer and use it in GitHub Desktop.
import 'dart:convert';
import 'package:flutter/foundation.dart';
void main() {
MyRadio radio = new MyRadio(category: "test", color: "test",icon: "test", desc: "test", id: 123, image: "test",lang: "test", name: "test", order: 23, tagline: "test",url: "test");
MyRadioList list = new MyRadioList(radios: [radio]);
print(list);
}
class MyRadioList {
final List<MyRadio> radios;
MyRadioList({
required this.radios,
});
MyRadioList copyWith({
List<MyRadio>? radios,
}) {
return MyRadioList(
radios: radios ?? this.radios,
);
}
Map<String, dynamic> toMap() {
return {
'radios': radios.map((x) => x.toMap()).toList(),
};
}
factory MyRadioList.fromMap(Map<String, dynamic> map) {
return MyRadioList(
radios: List<MyRadio>.from(map['radios']?.map((x) => MyRadio.fromMap(x))),
);
}
String toJson() => json.encode(toMap());
factory MyRadioList.fromJson(String source) =>
MyRadioList.fromMap(json.decode(source));
@override
String toString() => 'MyRadioList(radios: $radios)';
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
return o is MyRadioList && listEquals(o.radios, radios);
}
@override
int get hashCode => radios.hashCode;
}
class MyRadio {
final int id;
final int order;
final String name;
final String tagline;
final String color;
final String desc;
final String url;
final String category;
final String icon;
final String image;
final String lang;
MyRadio({
required this.id,
required this.order,
required this.name,
required this.tagline,
required this.color,
required this.desc,
required this.url,
required this.category,
required this.icon,
required this.image,
required this.lang,
});
MyRadio copyWith({
int? id,
int? order,
String? name,
String? tagline,
String? color,
String? desc,
String? url,
String? category,
String? icon,
String? image,
String? lang,
}) {
return MyRadio(
id: id ?? this.id,
order: order ?? this.order,
name: name ?? this.name,
tagline: tagline ?? this.tagline,
color: color ?? this.color,
desc: desc ?? this.desc,
url: url ?? this.url,
category: category ?? this.category,
icon: icon ?? this.icon,
image: image ?? this.image,
lang: lang ?? this.lang,
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'order': order,
'name': name,
'tagline': tagline,
'color': color,
'desc': desc,
'url': url,
'category': category,
'icon': icon,
'image': image,
'lang': lang,
};
}
factory MyRadio.fromMap(Map<String, dynamic> map) {
return MyRadio(
id: map['id'],
order: map['order'],
name: map['name'],
tagline: map['tagline'],
color: map['color'],
desc: map['desc'],
url: map['url'],
category: map['category'],
icon: map['icon'],
image: map['image'],
lang: map['lang'],
);
}
String toJson() => json.encode(toMap());
factory MyRadio.fromJson(String source) =>
MyRadio.fromMap(json.decode(source));
@override
String toString() {
return 'MyRadio(id: $id, order: $order, name: $name, tagline: $tagline, color: $color, desc: $desc, url: $url, category: $category, icon: $icon, image: $image, lang: $lang)';
}
@override
bool operator ==(Object o) {
if (identical(this, o)) return true;
return o is MyRadio &&
o.id == id &&
o.order == order &&
o.name == name &&
o.tagline == tagline &&
o.color == color &&
o.desc == desc &&
o.url == url &&
o.category == category &&
o.icon == icon &&
o.image == image &&
o.lang == lang;
}
@override
int get hashCode {
return id.hashCode ^
order.hashCode ^
name.hashCode ^
tagline.hashCode ^
color.hashCode ^
desc.hashCode ^
url.hashCode ^
category.hashCode ^
icon.hashCode ^
image.hashCode ^
lang.hashCode;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment