Fakultas Ilmu Komputer UI

komentar_posting.dart 1009 Bytes
Newer Older
1
import 'package:intl/intl.dart';
2
3
import 'package:json_annotation/json_annotation.dart';

4
part 'komentar_posting.g.dart';
5
6
7
8
9
10
11
12
13
14
15
16

@JsonSerializable()
class KomentarPostingList {
  final List<KomentarPostingModel> allKomentar;
  KomentarPostingList(this.allKomentar);
}

@JsonSerializable()
class KomentarPostingModel {
  final int id;
  final String deskripsi;
  final String creator;
17
18
  @JsonKey(name: 'creator_email')
  final String creatorEmail;
19
20
  @JsonKey(name: 'creator_picture')
  final String creatorPicture;
21
  @JsonKey(fromJson: _stringToDateTime)
22
  final DateTime created;
23

24
25
26
27
28
  KomentarPostingModel({
    this.id,
    this.deskripsi,
    this.creator,
    this.creatorEmail,
29
    this.creatorPicture,
30
    this.created,
31
  });
32

33
34
  factory KomentarPostingModel.fromJson(Map<String, dynamic> json) =>
      _$KomentarPostingModelFromJson(json);
35
36
37

  Map<String, dynamic> toJson() => _$KomentarPostingModelToJson(this);
}
38
39
40
41

DateTime _stringToDateTime(String date) {
  return DateFormat('dd-MM-yyyy hh:mm').parse(date);
}