'how to handle object null value to string flutter

how to handle object null value to string flutter Value according to the red circle. I tried to make Null = ' ' like this, but I tried many different solutions and still can't get it. this code object for JSON

  final String communityId;
  final String groupId;
  final int id;
  final Name name;
  final String image;

  const Object(
      {required this.communityId,
      required this.groupId,
      required this.id,
      required this.name,
      required this.image});

  factory Object.fromJson(Map<String, dynamic> json) {
    return Object(
        communityId: json['community_id'] as String,
        groupId: json['group_id'] as String,
        id: json['id'] as int,
        name: Name.fromJson(json['name'] ),
        image: json['image'] as String);
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['community_id'] = communityId;
    data['group_id'] = groupId;
    data['id'] = id;
    data['name'] = name.toJson();
    data['image'] = image;
    return data;
  }
}

class Name {
  String? th;
  String? en = null;

  Name({this.th, this.en});

  factory Name.fromJson(Map<String, dynamic> json) {
    return Name(
        th: json['th'] as String,
        en: json['en'] != null ? json['en'] as String : '');
  }

  Map<String, dynamic> toJson() => {'th': th, 'en': en ?? ''};

this image error enter image description here

. . . . .. . . .. .. .. . .



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source