mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +02:00
fix
This commit is contained in:
parent
a7b62c4eb5
commit
fa759ba28e
3 changed files with 1 additions and 264 deletions
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_timeline/flutter_timeline.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:timeline_widgetbook/main.directories.g.dart';
|
||||
import 'package:timeline_widgetbook/mock_timeline_service.dart';
|
||||
import 'package:widgetbook/widgetbook.dart';
|
||||
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;
|
||||
|
||||
|
@ -55,24 +54,6 @@ class WidgetBookApp extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
@widgetbook.UseCase(
|
||||
designLink:
|
||||
'https://www.figma.com/file/PRJoVXQ5aOjAICfkQdAq2A/Iconica-User-Stories?type=design&node-id=34-2763&mode=design&t=W72P3tkEascAKDCk-4',
|
||||
name: 'Timeline post screen',
|
||||
type: TimelinePostScreen,
|
||||
)
|
||||
Widget postScreenUseCase(BuildContext context) {
|
||||
var service = TestTimelineService()..fetchPosts(null);
|
||||
var options = const TimelineOptions();
|
||||
return TimelinePostScreen(
|
||||
userId: '1',
|
||||
service: service,
|
||||
options: options,
|
||||
post: service.posts.first,
|
||||
onPostDelete: () {},
|
||||
);
|
||||
}
|
||||
|
||||
@widgetbook.UseCase(
|
||||
designLink:
|
||||
'https://www.figma.com/file/PRJoVXQ5aOjAICfkQdAq2A/Iconica-User-Stories?type=design&node-id=34-2763&mode=design&t=W72P3tkEascAKDCk-4',
|
||||
|
@ -80,12 +61,10 @@ Widget postScreenUseCase(BuildContext context) {
|
|||
type: TimelineScreen,
|
||||
)
|
||||
Widget timelineUseCase(BuildContext context) {
|
||||
var service = TestTimelineService()..fetchPosts(null);
|
||||
var options = const TimelineOptions();
|
||||
return TimelineScreen(
|
||||
userId: '1',
|
||||
options: options,
|
||||
onPostTap: (_) {},
|
||||
service: service,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -16,15 +16,6 @@ final directories = <_i1.WidgetbookNode>[
|
|||
_i1.WidgetbookFolder(
|
||||
name: 'screens',
|
||||
children: [
|
||||
_i1.WidgetbookLeafComponent(
|
||||
name: 'TimelinePostScreen',
|
||||
useCase: _i1.WidgetbookUseCase(
|
||||
name: 'Timeline post screen',
|
||||
builder: _i2.postScreenUseCase,
|
||||
designLink:
|
||||
'https://www.figma.com/file/PRJoVXQ5aOjAICfkQdAq2A/Iconica-User-Stories?type=design&node-id=34-2763&mode=design&t=W72P3tkEascAKDCk-4',
|
||||
),
|
||||
),
|
||||
_i1.WidgetbookLeafComponent(
|
||||
name: 'TimelineScreen',
|
||||
useCase: _i1.WidgetbookUseCase(
|
||||
|
@ -33,7 +24,7 @@ final directories = <_i1.WidgetbookNode>[
|
|||
designLink:
|
||||
'https://www.figma.com/file/PRJoVXQ5aOjAICfkQdAq2A/Iconica-User-Stories?type=design&node-id=34-2763&mode=design&t=W72P3tkEascAKDCk-4',
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
];
|
||||
|
|
|
@ -1,233 +0,0 @@
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_timeline/flutter_timeline.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class TestTimelineService
|
||||
with ChangeNotifier
|
||||
implements TimelineService, TimelineUserService {
|
||||
List<TimelinePost> _posts = [];
|
||||
|
||||
List<TimelinePost> get posts => _posts;
|
||||
|
||||
@override
|
||||
Future<TimelinePost> createPost(TimelinePost post) async {
|
||||
_posts.add(
|
||||
post.copyWith(
|
||||
creator: const TimelinePosterUserModel(userId: 'test_user'),
|
||||
),
|
||||
);
|
||||
notifyListeners();
|
||||
return post;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deletePost(TimelinePost post) async {
|
||||
_posts = _posts.where((element) => element.id != post.id).toList();
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TimelinePost> deletePostReaction(
|
||||
TimelinePost post,
|
||||
String reactionId,
|
||||
) async {
|
||||
if (post.reactions != null && post.reactions!.isNotEmpty) {
|
||||
var reaction =
|
||||
post.reactions!.firstWhere((element) => element.id == reactionId);
|
||||
var updatedPost = post.copyWith(
|
||||
reaction: post.reaction - 1,
|
||||
reactions: (post.reactions ?? [])..remove(reaction),
|
||||
);
|
||||
_posts = _posts
|
||||
.map(
|
||||
(p) => p.id == post.id ? updatedPost : p,
|
||||
)
|
||||
.toList();
|
||||
|
||||
notifyListeners();
|
||||
return updatedPost;
|
||||
}
|
||||
return post;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TimelinePost> fetchPostDetails(TimelinePost post) async {
|
||||
var reactions = post.reactions ?? [];
|
||||
var updatedReactions = <TimelinePostReaction>[];
|
||||
for (var reaction in reactions) {
|
||||
updatedReactions.add(reaction.copyWith(
|
||||
creator: const TimelinePosterUserModel(userId: 'test_user')));
|
||||
}
|
||||
var updatedPost = post.copyWith(reactions: updatedReactions);
|
||||
_posts = _posts.map((p) => (p.id == post.id) ? updatedPost : p).toList();
|
||||
notifyListeners();
|
||||
return updatedPost;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<TimelinePost>> fetchPosts(String? category) async {
|
||||
var posts = getMockedPosts();
|
||||
_posts = posts;
|
||||
notifyListeners();
|
||||
return posts;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<TimelinePost>> fetchPostsPaginated(
|
||||
String? category,
|
||||
int limit,
|
||||
) async {
|
||||
notifyListeners();
|
||||
return _posts;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TimelinePost> fetchPost(TimelinePost post) async {
|
||||
notifyListeners();
|
||||
return post;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<TimelinePost>> refreshPosts(String? category) async {
|
||||
var posts = <TimelinePost>[];
|
||||
|
||||
_posts = [...posts, ..._posts];
|
||||
notifyListeners();
|
||||
return posts;
|
||||
}
|
||||
|
||||
@override
|
||||
TimelinePost? getPost(String postId) =>
|
||||
(_posts.any((element) => element.id == postId))
|
||||
? _posts.firstWhere((element) => element.id == postId)
|
||||
: null;
|
||||
|
||||
@override
|
||||
List<TimelinePost> getPosts(String? category) => _posts
|
||||
.where((element) => category == null || element.category == category)
|
||||
.toList();
|
||||
|
||||
@override
|
||||
Future<TimelinePost> likePost(String userId, TimelinePost post) async {
|
||||
var updatedPost = post.copyWith(
|
||||
likes: post.likes + 1,
|
||||
likedBy: (post.likedBy ?? [])..add(userId),
|
||||
);
|
||||
_posts = _posts
|
||||
.map(
|
||||
(p) => p.id == post.id ? updatedPost : p,
|
||||
)
|
||||
.toList();
|
||||
|
||||
notifyListeners();
|
||||
return updatedPost;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TimelinePost> unlikePost(String userId, TimelinePost post) async {
|
||||
var updatedPost = post.copyWith(
|
||||
likes: post.likes - 1,
|
||||
likedBy: post.likedBy?..remove(userId),
|
||||
);
|
||||
_posts = _posts
|
||||
.map(
|
||||
(p) => p.id == post.id ? updatedPost : p,
|
||||
)
|
||||
.toList();
|
||||
|
||||
notifyListeners();
|
||||
return updatedPost;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TimelinePost> reactToPost(
|
||||
TimelinePost post,
|
||||
TimelinePostReaction reaction, {
|
||||
Uint8List? image,
|
||||
}) async {
|
||||
var reactionId = const Uuid().v4();
|
||||
var updatedReaction = reaction.copyWith(
|
||||
id: reactionId,
|
||||
creator: const TimelinePosterUserModel(userId: 'test_user'));
|
||||
|
||||
var updatedPost = post.copyWith(
|
||||
reaction: post.reaction + 1,
|
||||
reactions: post.reactions?..add(updatedReaction),
|
||||
);
|
||||
|
||||
_posts = _posts
|
||||
.map(
|
||||
(p) => p.id == post.id ? updatedPost : p,
|
||||
)
|
||||
.toList();
|
||||
notifyListeners();
|
||||
return updatedPost;
|
||||
}
|
||||
|
||||
List<TimelinePost> getMockedPosts() {
|
||||
return [
|
||||
for (var i = 0; i < 20; i++) ...[
|
||||
if (i == 0) ...[
|
||||
TimelinePost(
|
||||
id: 'Post$i',
|
||||
creatorId: 'test_user',
|
||||
title: 'Post $i',
|
||||
category: 'text',
|
||||
content: "Post $i content",
|
||||
likes: i,
|
||||
reaction: 0,
|
||||
reactions: getMockedReactions('Post$i'),
|
||||
createdAt: DateTime.now().subtract(Duration(days: i % 10)),
|
||||
reactionEnabled: true,
|
||||
imageUrl: 'https://picsum.photos/seed/$i/200/300',
|
||||
)
|
||||
] else ...[
|
||||
TimelinePost(
|
||||
id: 'Post$i',
|
||||
creatorId: 'test_user',
|
||||
title: 'Post $i',
|
||||
category: 'text',
|
||||
content: "Post $i content",
|
||||
likes: i,
|
||||
reaction: 0,
|
||||
createdAt: DateTime.now().subtract(Duration(days: i % 10)),
|
||||
reactionEnabled: false,
|
||||
imageUrl: 'https://picsum.photos/seed/$i/200/300',
|
||||
)
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
List<TimelinePostReaction> getMockedReactions(String posdId) {
|
||||
return [
|
||||
for (var i = 0; i < 20; i++) ...[
|
||||
TimelinePostReaction(
|
||||
id: 'Reaction$i',
|
||||
postId: posdId,
|
||||
reaction: 'Reaction $i',
|
||||
createdAt: DateTime.now().subtract(Duration(days: i % 10)),
|
||||
creatorId: 'test_user',
|
||||
imageUrl:
|
||||
(i % 2 == 0) ? 'https://picsum.photos/seed/$i/200/300' : null,
|
||||
)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TimelinePosterUserModel?> getUser(String userId) async {
|
||||
return TimelinePosterUserModel(
|
||||
userId: userId,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
set posts(List<TimelinePost> posts) {
|
||||
_posts = posts;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue