feat : Modèle avec sérialisation automatique
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format width=80
|
||||
|
||||
// **************************************************************************
|
||||
// StackedBottomsheetGenerator
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format width=80
|
||||
|
||||
// **************************************************************************
|
||||
// StackedDialogGenerator
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format width=80
|
||||
|
||||
// **************************************************************************
|
||||
// StackedLocatorGenerator
|
||||
@@ -13,10 +14,8 @@ import 'package:stacked_shared/stacked_shared.dart';
|
||||
|
||||
final locator = StackedLocator.instance;
|
||||
|
||||
Future<void> setupLocator({
|
||||
String? environment,
|
||||
EnvironmentFilter? environmentFilter,
|
||||
}) async {
|
||||
Future<void> setupLocator(
|
||||
{String? environment, EnvironmentFilter? environmentFilter}) async {
|
||||
// Register environments
|
||||
locator.registerEnvironment(
|
||||
environment: environment, environmentFilter: environmentFilter);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// dart format width=80
|
||||
|
||||
// **************************************************************************
|
||||
// StackedNavigatorGenerator
|
||||
@@ -16,6 +17,8 @@ import 'package:stacked/stacked.dart' as _i1;
|
||||
import 'package:stacked_services/stacked_services.dart' as _i7;
|
||||
|
||||
class Routes {
|
||||
static const homeView = '/home-view';
|
||||
|
||||
static const startupView = '/startup-view';
|
||||
|
||||
static const mainView = '/main-view';
|
||||
@@ -24,6 +27,8 @@ class Routes {
|
||||
|
||||
static const eventDetailsView = '/event-details-view';
|
||||
|
||||
static const eventDetailsView = '/event-details-view';
|
||||
|
||||
static const all = <String>{
|
||||
homeView,
|
||||
startupView,
|
||||
@@ -34,6 +39,10 @@ class Routes {
|
||||
|
||||
class StackedRouter extends _i1.RouterBase {
|
||||
final _routes = <_i1.RouteDef>[
|
||||
_i1.RouteDef(
|
||||
Routes.homeView,
|
||||
page: _i2.HomeView,
|
||||
),
|
||||
_i1.RouteDef(
|
||||
Routes.startupView,
|
||||
page: _i3.StartupView,
|
||||
@@ -50,24 +59,37 @@ class StackedRouter extends _i1.RouterBase {
|
||||
Routes.eventDetailsView,
|
||||
page: _i5.EventDetailsView,
|
||||
),
|
||||
_i1.RouteDef(
|
||||
Routes.eventDetailsView,
|
||||
page: _i5.EventDetailsView,
|
||||
),
|
||||
];
|
||||
|
||||
final _pagesMap = <Type, _i1.StackedRouteFactory>{
|
||||
_i2.HomeView: (data) {
|
||||
final args = data.getArgs<HomeViewArguments>(
|
||||
orElse: () => const HomeViewArguments(),
|
||||
);
|
||||
return _i6.MaterialPageRoute<dynamic>(
|
||||
builder: (context) => const _i2.HomeView(),
|
||||
builder: (context) => _i2.HomeView(key: args.key),
|
||||
settings: data,
|
||||
);
|
||||
},
|
||||
_i3.StartupView: (data) {
|
||||
final args = data.getArgs<StartupViewArguments>(
|
||||
orElse: () => const StartupViewArguments(),
|
||||
);
|
||||
return _i6.MaterialPageRoute<dynamic>(
|
||||
builder: (context) => const _i3.StartupView(),
|
||||
builder: (context) => _i3.StartupView(key: args.key),
|
||||
settings: data,
|
||||
);
|
||||
},
|
||||
_i4.MainView: (data) {
|
||||
final args = data.getArgs<MainViewArguments>(
|
||||
orElse: () => const MainViewArguments(),
|
||||
);
|
||||
return _i6.MaterialPageRoute<dynamic>(
|
||||
builder: (context) => const _i4.MainView(),
|
||||
builder: (context) => _i4.MainView(key: args.key),
|
||||
settings: data,
|
||||
);
|
||||
},
|
||||
@@ -88,6 +110,72 @@ class StackedRouter extends _i1.RouterBase {
|
||||
Map<Type, _i1.StackedRouteFactory> get pagesMap => _pagesMap;
|
||||
}
|
||||
|
||||
class HomeViewArguments {
|
||||
const HomeViewArguments({this.key});
|
||||
|
||||
final _i6.Key? key;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '{"key": "$key"}';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant HomeViewArguments other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other.key == key;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return key.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class StartupViewArguments {
|
||||
const StartupViewArguments({this.key});
|
||||
|
||||
final _i6.Key? key;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '{"key": "$key"}';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant StartupViewArguments other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other.key == key;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return key.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class MainViewArguments {
|
||||
const MainViewArguments({this.key});
|
||||
|
||||
final _i6.Key? key;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '{"key": "$key"}';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant MainViewArguments other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other.key == key;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return key.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class EventDetailsViewArguments {
|
||||
const EventDetailsViewArguments({
|
||||
this.key,
|
||||
@@ -116,42 +204,64 @@ class EventDetailsViewArguments {
|
||||
}
|
||||
|
||||
extension NavigatorStateExtension on _i7.NavigationService {
|
||||
Future<dynamic> navigateToStartupView([
|
||||
Future<dynamic> navigateToHomeView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return navigateTo<dynamic>(Routes.startupView,
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> navigateToMainView([
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return navigateTo<dynamic>(Routes.mainView,
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> navigateToHomeView([
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
}) async {
|
||||
return navigateTo<dynamic>(Routes.homeView,
|
||||
arguments: HomeViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> navigateToStartupView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
}) async {
|
||||
return navigateTo<dynamic>(Routes.startupView,
|
||||
arguments: StartupViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> navigateToMainView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
}) async {
|
||||
return navigateTo<dynamic>(Routes.mainView,
|
||||
arguments: MainViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> navigateToHomeView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
}) async {
|
||||
return navigateTo<dynamic>(Routes.homeView,
|
||||
arguments: HomeViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
@@ -175,42 +285,98 @@ extension NavigatorStateExtension on _i7.NavigationService {
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithStartupView([
|
||||
Future<dynamic> navigateToEventDetailsView({
|
||||
_i6.Key? key,
|
||||
required int eventId,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return replaceWith<dynamic>(Routes.startupView,
|
||||
}) async {
|
||||
return navigateTo<dynamic>(Routes.eventDetailsView,
|
||||
arguments: EventDetailsViewArguments(key: key, eventId: eventId),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithMainView([
|
||||
Future<dynamic> replaceWithHomeView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
return replaceWith<dynamic>(Routes.mainView,
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithHomeView([
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
]) async {
|
||||
}) async {
|
||||
return replaceWith<dynamic>(Routes.homeView,
|
||||
arguments: HomeViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithStartupView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
}) async {
|
||||
return replaceWith<dynamic>(Routes.startupView,
|
||||
arguments: StartupViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithMainView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
}) async {
|
||||
return replaceWith<dynamic>(Routes.mainView,
|
||||
arguments: MainViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithHomeView({
|
||||
_i6.Key? key,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
}) async {
|
||||
return replaceWith<dynamic>(Routes.homeView,
|
||||
arguments: HomeViewArguments(key: key),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
transition: transition);
|
||||
}
|
||||
|
||||
Future<dynamic> replaceWithEventDetailsView({
|
||||
_i6.Key? key,
|
||||
required int eventId,
|
||||
int? routerId,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
Widget Function(BuildContext, Animation<double>, Animation<double>, Widget)?
|
||||
transition,
|
||||
}) async {
|
||||
return replaceWith<dynamic>(Routes.eventDetailsView,
|
||||
arguments: EventDetailsViewArguments(key: key, eventId: eventId),
|
||||
id: routerId,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
|
||||
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,
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import 'package:bahla_front/app/app.locator.dart';
|
||||
import 'package:bahla_front/app/app.router.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
import '../../../models/event.dart';
|
||||
|
||||
class HomeViewModel extends BaseViewModel {
|
||||
final _navigationService = locator<NavigationService>();
|
||||
@@ -45,25 +46,4 @@ class HomeViewModel extends BaseViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
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}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user