feat : Modèle avec sérialisation automatique
This commit is contained in:
30
lib/models/event.dart
Normal file
30
lib/models/event.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'event.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class Event {
|
||||
String name;
|
||||
String picture;
|
||||
String organizer = 'Organizer';
|
||||
String? place;
|
||||
DateTime? date;
|
||||
bool isFavorite;
|
||||
|
||||
Event({
|
||||
required this.name,
|
||||
required this.picture,
|
||||
required this.organizer,
|
||||
this.date,
|
||||
this.place,
|
||||
this.isFavorite = false,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Event{name: $name, picture: $picture}';
|
||||
}
|
||||
|
||||
factory Event.fromJson(Map<String, dynamic> json) => _$EventFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$EventToJson(this);
|
||||
}
|
||||
26
lib/models/event.g.dart
Normal file
26
lib/models/event.g.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'event.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Event _$EventFromJson(Map<String, dynamic> json) => Event(
|
||||
name: json['name'] as String,
|
||||
picture: json['picture'] as String,
|
||||
organizer: json['organizer'] as String,
|
||||
date:
|
||||
json['date'] == null ? null : DateTime.parse(json['date'] as String),
|
||||
place: json['place'] as String?,
|
||||
isFavorite: json['isFavorite'] as bool? ?? false,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$EventToJson(Event instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'picture': instance.picture,
|
||||
'organizer': instance.organizer,
|
||||
'place': instance.place,
|
||||
'date': instance.date?.toIso8601String(),
|
||||
'isFavorite': instance.isFavorite,
|
||||
};
|
||||
33
lib/models/post.dart
Normal file
33
lib/models/post.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'post.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class Post {
|
||||
final String title;
|
||||
final String content;
|
||||
final String authorName;
|
||||
final String authorImageUrl;
|
||||
final DateTime publishDate;
|
||||
final List<String>? imageUrls;
|
||||
final int likesCount;
|
||||
final int commentsCount;
|
||||
final int sharesCount;
|
||||
final double? aspectRatio; // Nouveau paramètre pour le ratio (largeur/hauteur)
|
||||
|
||||
Post({
|
||||
required this.title,
|
||||
required this.content,
|
||||
required this.authorName,
|
||||
required this.authorImageUrl,
|
||||
required this.publishDate,
|
||||
this.imageUrls,
|
||||
this.likesCount = 0,
|
||||
this.commentsCount = 0,
|
||||
this.sharesCount = 0,
|
||||
this.aspectRatio,
|
||||
});
|
||||
|
||||
factory Post.fromJson(Map<String, dynamic> json) => _$PostFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$PostToJson(this);
|
||||
}
|
||||
35
lib/models/post.g.dart
Normal file
35
lib/models/post.g.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'post.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Post _$PostFromJson(Map<String, dynamic> json) => Post(
|
||||
title: json['title'] as String,
|
||||
content: json['content'] as String,
|
||||
authorName: json['authorName'] as String,
|
||||
authorImageUrl: json['authorImageUrl'] as String,
|
||||
publishDate: DateTime.parse(json['publishDate'] as String),
|
||||
imageUrls: (json['imageUrls'] as List<dynamic>?)
|
||||
?.map((e) => e as String)
|
||||
.toList(),
|
||||
likesCount: (json['likesCount'] as num?)?.toInt() ?? 0,
|
||||
commentsCount: (json['commentsCount'] as num?)?.toInt() ?? 0,
|
||||
sharesCount: (json['sharesCount'] as num?)?.toInt() ?? 0,
|
||||
aspectRatio: (json['aspectRatio'] as num?)?.toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$PostToJson(Post instance) => <String, dynamic>{
|
||||
'title': instance.title,
|
||||
'content': instance.content,
|
||||
'authorName': instance.authorName,
|
||||
'authorImageUrl': instance.authorImageUrl,
|
||||
'publishDate': instance.publishDate.toIso8601String(),
|
||||
'imageUrls': instance.imageUrls,
|
||||
'likesCount': instance.likesCount,
|
||||
'commentsCount': instance.commentsCount,
|
||||
'sharesCount': instance.sharesCount,
|
||||
'aspectRatio': instance.aspectRatio,
|
||||
};
|
||||
Reference in New Issue
Block a user