I have an api where i get my users data. I made a user model which holds the data of the user after decoding it. After making some changes and POST to the user resource in the api (e.g profile name) the toJson() method of the user model sends other user object as null values to the api, excluding the updated field.
Expected behavior:
The toJson() method supposed to check for null objects and replace it with the previous data gotten from the api instead of sending null to the api.
Is there any way to make the user model holds the user value when sending to the api?
This is my UserModel class
String userModelToJson(UserModel data) => jsonEncode(data);
#JsonSerializable()
class UserModel {
UserModel({
this.type,
this.bio,
this.name,
this.interests,
this.presentation,
this.links,
this.location,
this.school,
this.occupation,
this.createdAt,
this.lastUpdatedAt,
});
final String? type;
final String? bio;
final String? name;
final List<dynamic>? interests;
final Presentation? presentation;
final Links? links;
final Location? location;
final School? school;
final Occupation? occupation;
final int? createdAt;
final int? lastUpdatedAt;
factory UserModel.fromJson(Map<String, dynamic> json) =>
_$UserModelFromJson(json);
Map<String, dynamic> toJson() => _$UserModelToJson(this);
}
json_serializable of user model
UserModel _$UserModelFromJson(Map<String, dynamic> json) => UserModel(
type: json['type'] as String?,
bio: json['bio'] as String?,
name: json['name'] as String?,
interests: json['interests'] as List<dynamic>?,
presentation: json['presentation'] == null
? null
: Presentation.fromJson(json['presentation'] as Map<String, dynamic>),
links: json['links'] == null
? null
: Links.fromJson(json['links'] as Map<String, dynamic>),
location: json['location'] == null
? null
: Location.fromJson(json['location'] as Map<String, dynamic>),
school: json['school'] == null
? null
: School.fromJson(json['school'] as Map<String, dynamic>),
occupation: json['occupation'] == null
? null
: Occupation.fromJson(json['occupation'] as Map<String, dynamic>),
createdAt: json['createdAt'] as int?,
lastUpdatedAt: json['lastUpdatedAt'] as int?,
);
Map<String, dynamic> _$UserModelToJson(UserModel instance) => <String, dynamic>{
'type': instance.type,
'bio': instance.bio,
'name': instance.name,
'interests': instance.interests,
'presentation': instance.presentation,
'links': instance.links,
'location': instance.location,
'school': instance.school,
'occupation': instance.occupation,
};
Get user method
Future<UserModel> getUserData() async {
UserModel? user;
final token = await _storage.getKey("Token");
ApiService.client.options.headers['Authorization'] = 'Bearer $token';
final response = await ApiService.client.get(ApiEndpoint.profile);
if (response.statusCode == 200 || response.statusCode == 201) {
user = UserModel.fromJson(response.data);
return user;
} else {
throw "Couldn't load user";
}
}
create file static_variable.dart
class StaticVariable {
static UserModel? user;
}
save user data to StaticVariable
Future<UserModel> getUserData() async {
UserModel? user;
final token = await _storage.getKey("Token");
ApiService.client.options.headers['Authorization'] = 'Bearer $token';
final response = await ApiService.client.get(ApiEndpoint.profile);
if (response.statusCode == 200 || response.statusCode == 201) {
user = UserModel.fromJson(response.data);
StaticVariable.user = user; //save user variable to StaticVariable
return user;
} else {
throw "Couldn't load user";
}
}
use ?? operation for check null
Map<String, dynamic> _$UserModelToJson(UserModel instance) => <String, dynamic>{
'type': instance.type ?? StaticVariable!.user.type,
'bio': instance.bio ?? StaticVariable!.user.bio,
'name': instance.name ?? StaticVariable!.user.name,
'interests': instance.interests ?? StaticVariable!.user.interests,
'presentation': instance.presentation ?? StaticVariable!.user.presentation,
'links': instance.links ?? StaticVariable!.user.links,
'location': instance.location ?? StaticVariable!.user.location,
'school': instance.school ?? StaticVariable!.user.school,
'occupation': instance.occupation ?? StaticVariable!.user.ccupation,
};
'type': instance.type ?? "", mean:
if(instance.type == null){
'type': StaticVariable.user.type
} else {
'type': instance.type
}
Related
this is my database image
import 'dart:convert';
class ReviewcountInfo{
List<String> uid;
ReviewcountInfo({
required this.uid,
})
List<String> toList() {
return
}
factory ReviewcountInfo.fromMap(Map<String, dynamic> map) {
return ReviewcountInfo(
uid: ['uid'] ?? 0,
);}
String toJson() => json.encode(toList());
factory ReviewcountInfo.fromJson(String source) =>
ReviewcountInfo.fromMap(json.decode(source));
}
I want to get data in the form of an array from firebase, how can I get it?
I don't know how to fill 'List toList()','factory ReviewcountInfo' part.
class BrandingInfo {
num price;
BrandingInfo({
required this.price,
});
Map<String, dynamic> toMap() {
return {
'price': price,
};
}
factory BrandingInfo.fromMap(Map<String, dynamic> map) {
return BrandingInfo(
price: map['price'] ?? 0,
);
}
String toJson() => json.encode(toMap());
factory BrandingInfo.fromJson(String source) =>
BrandingInfo.fromMap(json.decode(source));
}
this is my example Code
I am coding by referring to the code above.
try this model
import 'dart:convert';
List<ReviewCount> reviewCountFromJson(String str) => List<ReviewCount>.from(json.decode(str).map((x) => ReviewCount.fromJson(x)));
String reviewCountToJson(List<ReviewCount> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class ReviewCount {
ReviewCount({
this.reviewcount,
});
final Reviewcount? reviewcount;
factory ReviewCount.fromJson(Map<String, dynamic> json) => ReviewCount(
reviewcount: json["reviewcount"] == null ? null : Reviewcount.fromJson(json["reviewcount"]),
);
Map<String, dynamic> toJson() => {
"reviewcount": reviewcount == null ? null : reviewcount.toJson(),
};
}
class Reviewcount {
Reviewcount({
this.uid,
});
final List<String>? uid;
factory Reviewcount.fromJson(Map<String, dynamic> json) => Reviewcount(
uid: json["uid"] == null ? null : List<String>.from(json["uid"].map((x) => x)),
);
Map<String, dynamic> toJson() => {
"uid": uid == null ? null : List<dynamic>.from(uid!.map((x) => x)),
};
}
then for getting the data from firestore
Future<Reviewcount> getuidList({String? pathDocuid}) async{
final response = await FirebaseFirestore.instance.collection("service").doc(pathDocuid!).get();
final mapItFirst = response.data() as Map<String,dynamic>;
// but first print the data using log so you can see if it
// gettingdata
log("${mapItFirst['reviewcount']}");
log("${mapItFirst['reviewcount']['uid']}");
return Reviewcount.fromJson(mapItFirst["reviewcount"]);
}
try this if it works if not mention me.
I'm trying to show my json response after user login. It successfully displaying response in my app when user put correct info. But the app getting crashed when user putting wrong credentials
Here is my json response when user put wrong info. It should displaying Status=0 in my app display(or whatever response I want to display
I/flutter (16426): {"Status":"0","Message":"Wrong Password provided","UserData":null}
Here is my API call when user press the login button
Future<void> login() async{
var jsonResponse = null;
if (passwordontroller.text.isNotEmpty && emailController.text.isNotEmpty) {
var response = await http.post(Uri.parse("http://jhhjhjhjhjhjhj"),
body: ({
'LoginId': emailController.text,
'Password': passwordontroller.text
}));
if (response.statusCode == 200) {
print("Correct");
print(response.body);
jsonResponse = json.decode(response.body.toString());
print(jsonResponse);
Navigator.push(context, MaterialPageRoute(builder: (context)=>AfterLoginResPage(response: ApiResponse.fromJson(jsonResponse))));
}
else {
print("Wronggooooooooooooooooooooooooooo");
print(response.body);
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text("Invalid credentials")));
}
} else {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text("Blank field is not allowed")));
}
}
My Model class
class ApiResponse {
ApiResponse({
required this.status,
required this.message,
required this.userData,
});
String status;
String message;
UserData userData;
factory ApiResponse.fromJson(Map<String, dynamic> json) => ApiResponse(
status: json["Status"],
message: json["Message"],
//userData: UserData.fromJson(json["UserData"]),
userData: json["UserData"] == null? null:UserData.fromJson(json["UserData"]), //======== Updated
);
}
class UserData {
UserData({
required this.name,
required this.encUserId,
});
String name;
String encUserId;
factory UserData.fromJson(Map<String, dynamic> json) => UserData(
name: json["Name"],
encUserId: json["EncUserId"],
);
}
And then here I'm displaying my response which is successfully getting executed when User putting correct credentials. but got crashed when putting wrong credentials
children: [
Text("Status: ${widget.response.status}"),
Text("Message: ${widget.response.message}"),
one more problem I'm facing ,here im able to display status and message What If I want to display Name & EncUserId also?.
here is my json response in postman after putting right info
{
"Status": "1",
"Message": "You are Logged in successfully",
"UserData": {
"Name": "tuhinroy881#gmail.com",
"EncUserId": "bbA/HajfPdswT0fhhiMvEg=="
}
}
.
Since null safety is enabled, you need to change UserData userData to UserData? userData; and userData: json["UserData"] == null? null:UserData.fromJson(json["UserData"] as Map<String, dynamic>)
Your problem is that you are trying to parse UserData while your error response doesn't have any UserData related information.
class ApiResponse {
ApiResponse({
required this.status,
required this.message,
required this.userData,
});
String status;
String message;
UserData? userData;
factory ApiResponse.fromJson(Map<String, dynamic> json) => ApiResponse(
status: json["Status"],
message: json["Message"],
userData: json["UserData"] == null? null:UserData.fromJson(json["UserData"]),
);
}
I have used Node/MongoDB for my back end and everything works fine wrt requests and responses.
For my front end, I am building a mobile app with flutter and therefore have to create model classes to represent my response.
Sample response:
{success: true, message: Logged in Successfully, user: {_id: 6028965c16056b37eca50076, username: spideyr, email: peterparker#gmail.com, password: $2b$10$R4kYBA3Ezk7z2EBIY3dfk.6Qy.IXQuXJocKVS5PCzLf4fXYckUMju, phone: 89066060484, __v: 0}, accessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTM1NDg3ODIsImV4cCI6MTYxNjE0MDc4MiwiYXVkIjoiNjAyODk2NWMxNjA1NmIzN2VjYTUwMDc2IiwiaXNzIjoicGlja3VycGFnZS5jb20ifQ.DX8-WGRkCQ9geAaQASOIzoPGpvpjdI7aV0C5o1i5Thw, refreshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTM1NDg3ODIsImV4cCI6MTY0NTEwNjM4MiwiYXVkIjoiNjAyODk2NWMxNjA1NmIzN2VjYTUwMDc2IiwiaXNzIjoicGlja3VycGFnZS5jb20ifQ.RkVCGK9FfU0rxs2qf5QtJsyFaGShsL05CI320GsmAwg}
In this response body, I am only interested in the user field and therefore have created my POJO/PODO class like below:
class UserModel {
final String id;
final String username;
final String email;
final String phone;
const UserModel({
this.id,
#required this.email,
#required this.username,
#required this.phone,
});
UserModel copyWith({String id, String username, String email, String phone}){
if (
(id == null) || identical(id, this.id) &&
(username == null) || identical(id, this.username) &&
(email == null || identical(email, this.email)) &&
(phone == null || identical(phone, this.phone))) {
return this;
}
return new UserModel(
id: id ?? this.id,
username: username ?? this.username,
email: email ?? this.email,
phone: phone ?? this.phone,
);
}
static const empty = UserModel(email: '', username: null, phone: null, id: '');
#override
String toString() {
return 'User{id: $id, username: $username, email: $email, phone: $phone}';
}
factory UserModel.fromMap(Map<String, dynamic> map){
return new UserModel(
id:map['_id'], // unable to understand why it shows error here
username:map['username'],
email:map['email'],
phone:map['phone'],
);
}
Map<String, dynamic> toMap(){
return {
'id': id,
'username': username,
'email': email,
'phone': phone,
};
}
}
I am able to login and register a user but this error keeps appearing regarding my mapping from mongo db's _id to id in my model class UserModel.fromJSON() method. Here's the error:
I/flutter (19353): NoSuchMethodError: The method '[]' was called on null.
I/flutter (19353): Receiver: null
I/flutter (19353): Tried calling: []("_id")
Does anyone know what changes I need to make in my UserModel class? Thanks.
I converted your JSON to class
class Model {
Model({
this.success,
this.message,
this.user,
this.accessToken,
this.refreshToken,
});
bool success;
String message;
User user;
String accessToken;
String refreshToken;
factory Model.fromJson(Map<String, dynamic> json) => Model(
success: json["success"],
message: json["message"],
user: User.fromJson(json["user"]),
accessToken: json["accessToken"],
refreshToken: json["refreshToken"],
);
Map<String, dynamic> toJson() => {
"success": success,
"message": message,
"user": user.toJson(),
"accessToken": accessToken,
"refreshToken": refreshToken,
};
}
class User {
User({
this.id,
this.username,
this.email,
this.password,
this.phone,
this.v,
});
String id;
String username;
String email;
String password;
String phone;
int v;
factory User.fromJson(Map<String, dynamic> json) => User(
id: json["_id"],
username: json["username"],
email: json["email"],
password: json["password"],
phone: json["phone"],
v: json["__v"],
);
Map<String, dynamic> toJson() => {
"_id": id,
"username": username,
"email": email,
"password": password,
"phone": phone,
"__v": v,
};
}
thanks to everyone that tried to help me understand the issue. I was missing a return statement in my APIClient class and that ensured that all the values in my map in fromJSON method were null.
Here's the correction:
class APIClient {
dynamic post(String pathSegment, Map<String, dynamic> body) async {
Dio dio = Dio();
Response response = await dio.post(
'${APIConstants.BASE_URL}${APIConstants.AUTH_URL}/$pathSegment',
data: body
);
if(response.statusCode == 200) {
print(response.data);
return response.data; // here's the change
} else {
print(response.statusMessage);
throw Exception(response.statusMessage);
}
}
}
The problem is in the UserResponseModel class. You are assigning Map to user.
Try this:
factory UserResponseModel.fromJSON(Map<String, dynamic> json) {
return UserResponseModel(
user: UserModel.fromJSON(json['user']),
success: json['success'],
message: json['message'],
accessToken: json['accessToken'],
refreshToken: json['refreshToken'],
);
}
I have this code where am able to get values from an online json data and print its value
main.dart
final String url = 'https://raw.githubusercontent.com/BrightCode1/ohms-json/master/categories.json';
List<JsonModel> myModel = [];
List<CatSubcategory> subCate = [];
int localInt;
#override
void initState() {
// TODO: implement initState
super.initState();
localInt = 0;
loadData(localInt);
}
loadData(int dataInt) async {
var res = await http.get(url, headers: {"Accept": "application/json"});
if (res.statusCode == 200) {
String resBody = res.body;
var jsonDecode = json.decode(resBody);
for (var data in jsonDecode) {
data['cat_subcategory'].map((x) {
return subCate.add(
CatSubcategory(subName: x['sub_name'], subImage: x['sub_image']));
}).toList();
myModel.add(JsonModel(
category: data['category'],
catId: data['cat_id'],
catIcon: data['cat_icon'],
catSubcategory: subCate));
setState(() {});
}
print(myModel[dataInt].catSubcategory.length);
} else {
print("Something went wrong!");
}
}
my model.dart
class JsonModel {
JsonModel({
this.category,
this.catId,
this.catIcon,
this.catSubcategory,
});
String category;
String catId;
String catIcon;
List<CatSubcategory> catSubcategory;
factory JsonModel.fromJson(Map<String, dynamic> json) => JsonModel(
category: json["category"],
catId: json["cat_id"],
catIcon: json["cat_icon"],
catSubcategory: List<CatSubcategory>.from(
json["cat_subcategory"].map((x) => CatSubcategory.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"category": category,
"cat_id": catId,
"cat_icon": catIcon,
"cat_subcategory":
List<dynamic>.from(catSubcategory.map((x) => x.toJson())),
};
}
class CatSubcategory {
CatSubcategory({
this.subName,
this.subImage,
});
String subName;
String subImage;
factory CatSubcategory.fromJson(Map<String, dynamic> json) => CatSubcategory(
subName: json["sub_name"],
subImage: json["sub_image"],
);
Map<String, dynamic> toJson() => {
"sub_name": subName,
"sub_image": subImage,
};
}
The only problem am having now is that when I try to print the length on the subcategory of the first list it gives me 24 instead of 6 and i printed it like this myModel[dataInt].catSubcategory.length. The dataInt is 0 which means it's supposed to print out the length of the children("cat_subcategory") with category of Design & Creativity but it's printing all the other children of the other lis. So please how do i go about this. And if you need more explanation tell me
I would avoid writing your own model from scratch if you already know the schema of your json.
Just use something like https://app.quicktype.io/ just paste your json and you will get
import 'dart:convert';
class Root {
Root({
this.category,
this.catId,
this.catIcon,
this.catSubcategory,
});
String category;
String catId;
String catIcon;
List<CatSubcategory> catSubcategory;
factory Root.fromJson(Map<String, dynamic> json) => Root(
category: json["category"],
catId: json["cat_id"],
catIcon: json["cat_icon"] == null ? null : json["cat_icon"],
catSubcategory: List<CatSubcategory>.from(json["cat_subcategory"].map((x) => CatSubcategory.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"category": category,
"cat_id": catId,
"cat_icon": catIcon == null ? null : catIcon,
"cat_subcategory": List<dynamic>.from(catSubcategory.map((x) => x.toJson())),
};
}
class CatSubcategory {
CatSubcategory({
this.subName,
this.subImage,
});
String subName;
String subImage;
factory CatSubcategory.fromJson(Map<String, dynamic> json) => CatSubcategory(
subName: json["sub_name"],
subImage: json["sub_image"],
);
Map<String, dynamic> toJson() => {
"sub_name": subName,
"sub_image": subImage,
};
}
and then you should be good to just
loadData(int dataInt) async {
var res = await http.get(url, headers: {"Accept": "application/json"});
if (res.statusCode == 200) {
String resBody = res.body;
var list = json.decode(resBody) as List;
List<Root> items = list.map((i)=>Root.fromJson(i)).toList();
print(items[0].catSubcategory.length);
}
} else {
print("Something went wrong!");
}
}
https://repl.it/talk/share/Sample/118111
I just tried parsing data from a firebase realtime database.
but has problems when converting to Model
I'm trying to parse data from the firebase database on Flutter.
But an error said
MY Complete QUIZ: {-M5-R3BqTajbCFk5mQuQ: {coins: 434, isSubmit: true,
questions: [{answer: sddsd, name: Why do we use it?, options:
[established, adwada, adawda, sddsd], select: }, {answer: adawda,
name: Where can I get some?, options: [established, adwada, adawda,
sddsd], select: sddsd}, {answer: adwada, name: Lorem Ipsum is simply
dummy text of the printing?, options: [established, adwada, adawda,
sddsd], select: established}], quizId: YItWgbYjHm},
-M50HhYPnuR7tSC-9ajw: {isSubmit: true, questions: [{answer: dadada, name: Where does it come from?, options: [vvvv, dadada, dsdsdssd,
bbbbbb], select: dadada}], quizId: 9pdzphz0x8}}
I/flutter ( 6768): type '(dynamic, dynamic) => Null' is not a subtype of type '(dynamic) => dynamic' of 'f'
Here, the database structure
The following function for fetchMyQuiz()
Future<Quiz> fetchMyQuiz(String uid) async {
Quiz _quiz;
var dio = Dio();
dio.options
..baseUrl = Constant.baseUrl
..connectTimeout = 5000 //5s
..receiveTimeout = 5000
..validateStatus = (int status) {
return status > 0;
}
..headers = {
HttpHeaders.userAgentHeader: 'dio',
'common-header': 'xx',
};
_isLoadingUser = true;
notifyListeners();
List<Quiz> _fetchedQuiz = [];
try {
var response = await dio.get(
Constant.userParam + '/$uid' + Constant.quiz + Constant.jsonExt,
options: Options(
contentType: Headers.formUrlEncodedContentType,
),
);
print("MY Complete QUIZ: ${response.data}");
if (response.statusCode == 200) {
var responseData = response.data;
responseData.forEach((String id, dynamic json) {
if (responseData != null) {
_quiz = Quiz.fromJson(id, json);
_fetchedQuiz.add(_quiz);
}
});
} else {
print("FETCH QUIZ error: ${response.data}");
}
} catch (e) {
print(e);
}
_myQuizList = _fetchedQuiz;
_isLoadingUser = false;
notifyListeners();
return _quiz;
}
class Quiz {
String id;
String quizId;
int coins;
bool isSubmit;
List<Questions> questions;
Quiz({this.id, this.quizId, this.coins, this.isSubmit, this.questions});
Quiz.fromJson(String idQuiz, Map<String, dynamic> json) {
id = idQuiz;
quizId = json['quizId'];
coins = json['coins'];
isSubmit = json['isSubmit'] == null ? false : json['isSubmit'];
if (json['questions'] != null) {
questions = new List<Questions>();
json['questions'].forEach((idQuest, vQuest) {
questions.add(new Questions.fromJson(idQuest, vQuest));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['quizId'] = this.quizId;
data['coins'] = this.coins;
data['isSubmit'] = this.isSubmit;
if (this.questions != null) {
data['questions'] = this.questions.map((v) => v.toJson()).toList();
}
return data;
}
}
class Questions {
String id;
String name;
String select;
String answer;
// bool isSave;
List<String> options;
Questions(
{this.id,
this.name,
this.select,
this.answer,
// this.isSave,
this.options});
Questions.fromJson(String id, Map<String, dynamic> json) {
id = id;
name = json['name'];
select = json['select'] == null ? '' : json['select'];
answer = json['answer'];
// isSave = false;
if (json['options'] != null) {
options = json['options'].cast<String>();
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['name'] = this.name;
data['select'] = this.select;
data['answer'] = this.answer;
// data['isSave'] = this.isSave;
data['options'] = this.options;
return data;
}
}
Any answer will appretiated.
I think your problem is in your parsing process. I used quicktype to generate your models. check them below
class Quiz {
final int coins;
final bool isSubmit;
final List<Question> questions;
final String quizId;
Quiz({
this.coins,
this.isSubmit,
this.questions,
this.quizId,
});
Quiz copyWith({
int coins,
bool isSubmit,
List<Question> questions,
String quizId,
}) =>
Quiz(
coins: coins ?? this.coins,
isSubmit: isSubmit ?? this.isSubmit,
questions: questions ?? this.questions,
quizId: quizId ?? this.quizId,
);
factory Quiz.fromRawJson(String str) => Quiz.fromJson(json.decode(str));
String toRawJson() => json.encode(toJson());
factory Quiz.fromJson(Map<String, dynamic> json) => Quiz(
coins: json["coins"] == null ? null : json["coins"],
isSubmit: json["isSubmit"] == null ? null : json["isSubmit"],
questions: json["questions"] == null ? null : List<Question>.from(json["questions"].map((x) => Question.fromJson(x))),
quizId: json["quizId"] == null ? null : json["quizId"],
);
Map<String, dynamic> toJson() => {
"coins": coins == null ? null : coins,
"isSubmit": isSubmit == null ? null : isSubmit,
"questions": questions == null ? null : List<dynamic>.from(questions.map((x) => x.toJson())),
"quizId": quizId == null ? null : quizId,
};
}
class Question {
final String answer;
final String name;
final List<String> options;
final dynamic select;
Question({
this.answer,
this.name,
this.options,
this.select,
});
Question copyWith({
String answer,
String name,
List<String> options,
dynamic select,
}) =>
Question(
answer: answer ?? this.answer,
name: name ?? this.name,
options: options ?? this.options,
select: select ?? this.select,
);
factory Question.fromRawJson(String str) => Question.fromJson(json.decode(str));
String toRawJson() => json.encode(toJson());
factory Question.fromJson(Map<String, dynamic> json) => Question(
answer: json["answer"] == null ? null : json["answer"],
name: json["name"] == null ? null : json["name"],
options: json["options"] == null ? null : List<String>.from(json["options"].map((x) => x)),
select: json["select"],
);
Map<String, dynamic> toJson() => {
"answer": answer == null ? null : answer,
"name": name == null ? null : name,
"options": options == null ? null : List<dynamic>.from(options.map((x) => x)),
"select": select,
};
}