feat: add options

This commit is contained in:
mike doornenbal 2024-10-22 15:13:30 +02:00
parent 9faca7cb99
commit f0c1c265b3
24 changed files with 53 additions and 156 deletions

View file

@ -42,7 +42,6 @@ class FirebaseCategoryRepository implements CategoryRepositoryInterface {
); );
_categories.addAll(categories); _categories.addAll(categories);
} else { } else {
// Replace or update categories in the list while keeping the "All" category intact
_categories _categories
..clear() ..clear()
..add(const TimelineCategory(key: null, title: "All")) ..add(const TimelineCategory(key: null, title: "All"))

View file

@ -1,6 +1,6 @@
import "package:cloud_firestore/cloud_firestore.dart";
import "package:firebase_auth/firebase_auth.dart"; import "package:firebase_auth/firebase_auth.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart"; import "package:timeline_repository_interface/timeline_repository_interface.dart";
import "package:cloud_firestore/cloud_firestore.dart";
class FirebaseUserRepository implements TimelineUserRepositoryInterface { class FirebaseUserRepository implements TimelineUserRepositoryInterface {
final CollectionReference usersCollection = final CollectionReference usersCollection =

View file

@ -20,6 +20,7 @@ dependencies:
cloud_firestore: ^5.4.4 cloud_firestore: ^5.4.4
firebase_auth: ^5.3.1 firebase_auth: ^5.3.1
firebase_storage: ^12.3.2 firebase_storage: ^12.3.2
collection: ^1.18.0
dev_dependencies: dev_dependencies:
flutter_iconica_analysis: flutter_iconica_analysis:

View file

@ -1,7 +1,6 @@
import 'package:example/theme.dart'; import 'package:example/theme.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_timeline/flutter_timeline.dart'; import 'package:flutter_timeline/flutter_timeline.dart';
import 'package:timeline_repository_interface/timeline_repository_interface.dart';
import 'package:intl/date_symbol_data_local.dart'; import 'package:intl/date_symbol_data_local.dart';
void main(List<String> args) { void main(List<String> args) {
@ -25,106 +24,3 @@ class MyApp extends StatelessWidget {
); );
} }
} }
// class Titje extends StatelessWidget {
// const Titje({super.key, required this.initialCategory});
// final String? initialCategory;
// @override
// Widget build(BuildContext context) {
// return TimelineScreen(
// onTapComments: (post) {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (context) => Detail(
// post: post,
// timelineService: timelineService,
// )));
// },
// onTapCreatePost: () {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (context) => ChooseCategory(
// timelineService: timelineService,
// )));
// },
// currentUserId: "1",
// options: TimelineOptions(),
// timelineService: timelineService,
// onTapPost: (post) {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (context) => Detail(
// post: post,
// timelineService: timelineService,
// )));
// },
// );
// }
// }
// class Detail extends StatelessWidget {
// const Detail({super.key, required this.post, required this.timelineService});
// final TimelinePost post;
// final TimelineService timelineService;
// @override
// Widget build(BuildContext context) {
// return TimelinePostDetailScreen(
// onTapComments: (post) {},
// onTapPost: (post) {},
// post: post,
// timelineService: timelineService,
// options: TimelineOptions(),
// currentUserId: "1");
// }
// }
// class ChooseCategory extends StatelessWidget {
// const ChooseCategory({super.key, required this.timelineService});
// final TimelineService timelineService;
// @override
// Widget build(BuildContext context) {
// return TimelineChooseCategoryScreen(
// options: TimelineOptions(),
// timelineService: timelineService,
// ontapCategory: (category) {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (context) =>
// AddInformation(timelineService: timelineService)));
// },
// );
// }
// }
// class AddInformation extends StatelessWidget {
// const AddInformation({super.key, required this.timelineService});
// final TimelineService timelineService;
// @override
// Widget build(BuildContext context) {
// return TimelineAddPostInformationScreen(
// timelineService: timelineService,
// onTaponTapOverview: () {
// Navigator.of(context).push(MaterialPageRoute(
// builder: (context) => Overview(timelineService: timelineService)));
// },
// );
// }
// }
// class Overview extends StatelessWidget {
// const Overview({super.key, required this.timelineService});
// final TimelineService timelineService;
// @override
// Widget build(BuildContext context) {
// return TimelinePostOverview(
// timelineService: timelineService,
// options: TimelineOptions(),
// onTapCreatePost: (post) {
// Navigator.of(context).pushReplacement(MaterialPageRoute(
// builder: (context) => Titje(initialCategory: post.category)));
// },
// );
// }
// }

View file

@ -12,10 +12,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_timeline: flutter_timeline:
git: path: ../
url: https://github.com/Iconica-Development/flutter_timeline
ref: 6.0.0
path: packages/flutter_timeline
intl: 0.19.0 intl: 0.19.0
dev_dependencies: dev_dependencies:
flutter_lints: ^4.0.0 flutter_lints: ^4.0.0

View file

@ -1,10 +1,8 @@
/// flutter_timeline library
// ignore_for_file: directives_ordering // ignore_for_file: directives_ordering
library flutter_timeline;
/// userstory /// userstory
library;
export "src/flutter_timeline_navigator_userstory.dart"; export "src/flutter_timeline_navigator_userstory.dart";
export "package:timeline_repository_interface/timeline_repository_interface.dart"; export "package:timeline_repository_interface/timeline_repository_interface.dart";

View file

@ -1,6 +1,5 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class FlutterTimelineNavigatorUserstory extends StatefulWidget { class FlutterTimelineNavigatorUserstory extends StatefulWidget {
const FlutterTimelineNavigatorUserstory({ const FlutterTimelineNavigatorUserstory({
@ -38,19 +37,26 @@ class _FlutterTimelineNavigatorUserstoryState
options: widget.options, options: widget.options,
onTapComments: (post) async { onTapComments: (post) async {
var currentUser = await timelineService.getCurrentUser(); var currentUser = await timelineService.getCurrentUser();
await widget.options.onTapComments?.call(post, currentUser) ??
await _push(_timelinePostDetailScreenWidget(post, currentUser)); await _push(_timelinePostDetailScreenWidget(post, currentUser));
}, },
onTapCreatePost: () async { onTapCreatePost: () async {
var selectedCategory = timelineService.getSelectedCategory(); var selectedCategory = timelineService.getSelectedCategory();
if (widget.options.onTapCreatePost != null) {
await widget.options.onTapCreatePost!(selectedCategory);
} else {
if (selectedCategory?.key != null) { if (selectedCategory?.key != null) {
await _push(_timelineAddpostInformationScreenWidget()); await _push(_timelineAddpostInformationScreenWidget());
} else { } else {
await _push(_timelineChooseCategoryScreenWidget()); await _push(_timelineChooseCategoryScreenWidget());
} }
}
}, },
onTapPost: (post) async { onTapPost: (post) async {
var currentUser = await timelineService.getCurrentUser(); var currentUser = await timelineService.getCurrentUser();
if (context.mounted) if (context.mounted)
await widget.options.onTapPost?.call(post, currentUser) ??
await _push(_timelinePostDetailScreenWidget(post, currentUser)); await _push(_timelinePostDetailScreenWidget(post, currentUser));
}, },
); );
@ -71,6 +77,7 @@ class _FlutterTimelineNavigatorUserstoryState
timelineService: timelineService, timelineService: timelineService,
options: widget.options, options: widget.options,
ontapCategory: (category) async { ontapCategory: (category) async {
await widget.options.onTapCategory?.call(category) ??
await _push(_timelineAddpostInformationScreenWidget()); await _push(_timelineAddpostInformationScreenWidget());
}, },
); );
@ -80,6 +87,7 @@ class _FlutterTimelineNavigatorUserstoryState
timelineService: timelineService, timelineService: timelineService,
options: widget.options, options: widget.options,
onTapOverview: () async { onTapOverview: () async {
await widget.options.onTapOverview?.call() ??
await _push(_timelinePostOverviewWidget()); await _push(_timelinePostOverviewWidget());
}, },
); );
@ -88,12 +96,8 @@ class _FlutterTimelineNavigatorUserstoryState
timelineService: timelineService, timelineService: timelineService,
options: widget.options, options: widget.options,
onTapCreatePost: (post) async { onTapCreatePost: (post) async {
await Navigator.of(context).pushAndRemoveUntil( await widget.options.onTapCreatePostInOverview?.call(post) ??
MaterialPageRoute( await _pushAndRemoveUntil(_timelineScreenWidget());
builder: (context) => _timelineScreenWidget(),
),
(route) => route.isFirst,
);
}, },
); );
@ -101,4 +105,11 @@ class _FlutterTimelineNavigatorUserstoryState
await Navigator.of(context) await Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => screen)); .push(MaterialPageRoute(builder: (context) => screen));
} }
Future<void> _pushAndRemoveUntil(Widget screen) async {
await Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (context) => screen),
(route) => route.isFirst,
);
}
} }

View file

@ -3,7 +3,6 @@ import "package:flutter/material.dart";
import "package:flutter_image_picker/flutter_image_picker.dart"; import "package:flutter_image_picker/flutter_image_picker.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:intl/intl.dart"; import "package:intl/intl.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class TimelineOptions { class TimelineOptions {
const TimelineOptions({ const TimelineOptions({
@ -30,6 +29,12 @@ class TimelineOptions {
this.timelineScreenDrawer, this.timelineScreenDrawer,
this.timelineScreenAppBarBuilder, this.timelineScreenAppBarBuilder,
this.onCreatePost, this.onCreatePost,
this.onTapComments,
this.onTapCreatePost,
this.onTapPost,
this.onTapCategory,
this.onTapOverview,
this.onTapCreatePostInOverview,
}); });
// Builders // Builders
@ -42,6 +47,12 @@ class TimelineOptions {
//general //general
final TimelineTranslations translations; final TimelineTranslations translations;
final Function(TimelinePost post, TimelineUser user)? onTapComments;
final Function(TimelineCategory? category)? onTapCreatePost;
final Function(TimelinePost post, TimelineUser user)? onTapPost;
final Function(TimelineCategory? category)? onTapCategory;
final Function()? onTapOverview;
final Function(TimelinePost post)? onTapCreatePostInOverview;
// TimelinePostWidget // TimelinePostWidget
final bool everyoneCanDelete; final bool everyoneCanDelete;

View file

@ -2,9 +2,6 @@ import "dart:typed_data";
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:flutter_timeline/src/widgets/image_picker.dart";
import "package:flutter_timeline/src/widgets/post_info_textfield.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class TimelineAddPostInformationScreen extends StatefulWidget { class TimelineAddPostInformationScreen extends StatefulWidget {
const TimelineAddPostInformationScreen({ const TimelineAddPostInformationScreen({

View file

@ -1,7 +1,5 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:flutter_timeline/src/widgets/post_info_textfield.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class TimelineChooseCategoryScreen extends StatelessWidget { class TimelineChooseCategoryScreen extends StatelessWidget {
const TimelineChooseCategoryScreen({ const TimelineChooseCategoryScreen({
@ -99,6 +97,7 @@ class TimelineChooseCategoryScreen extends StatelessWidget {
title: newCategoryController.text, title: newCategoryController.text,
), ),
); );
if (context.mounted)
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),

View file

@ -1,9 +1,6 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_svg/svg.dart"; import "package:flutter_svg/svg.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:flutter_timeline/src/widgets/reaction_textfield.dart";
import "package:flutter_timeline/src/widgets/timeline_post.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class TimelinePostDetailScreen extends StatefulWidget { class TimelinePostDetailScreen extends StatefulWidget {
const TimelinePostDetailScreen({ const TimelinePostDetailScreen({

View file

@ -1,7 +1,5 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:flutter_timeline/src/widgets/timeline_post.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class TimelinePostOverview extends StatefulWidget { class TimelinePostOverview extends StatefulWidget {
const TimelinePostOverview({ const TimelinePostOverview({

View file

@ -1,7 +1,7 @@
import "package:collection/collection.dart";
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/src/widgets/category_widget.dart"; import "package:flutter_timeline/src/widgets/category_widget.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart"; import "package:timeline_repository_interface/timeline_repository_interface.dart";
import "package:collection/collection.dart";
class CategoryList extends StatefulWidget { class CategoryList extends StatefulWidget {
const CategoryList({ const CategoryList({

View file

@ -1,7 +1,6 @@
import "package:cached_network_image/cached_network_image.dart"; import "package:cached_network_image/cached_network_image.dart";
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class CommentSection extends StatefulWidget { class CommentSection extends StatefulWidget {
const CommentSection({ const CommentSection({

View file

@ -1,7 +1,5 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:flutter_timeline/src/widgets/timeline_post.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class PostList extends StatelessWidget { class PostList extends StatelessWidget {
const PostList({ const PostList({

View file

@ -1,6 +1,5 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class MoreOptionsButton extends StatelessWidget { class MoreOptionsButton extends StatelessWidget {
const MoreOptionsButton({ const MoreOptionsButton({

View file

@ -1,6 +1,5 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class ReactionTextfield extends StatelessWidget { class ReactionTextfield extends StatelessWidget {
const ReactionTextfield({ const ReactionTextfield({

View file

@ -1,10 +1,6 @@
import "package:cached_network_image/cached_network_image.dart"; import "package:cached_network_image/cached_network_image.dart";
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_timeline/flutter_timeline.dart"; import "package:flutter_timeline/flutter_timeline.dart";
import "package:flutter_timeline/src/widgets/comment_section.dart";
import "package:flutter_timeline/src/widgets/post_more_options_widget.dart";
import "package:flutter_timeline/src/widgets/tappable_image.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart";
class TimelinePostWidget extends StatefulWidget { class TimelinePostWidget extends StatefulWidget {
const TimelinePostWidget({ const TimelinePostWidget({

View file

@ -24,6 +24,7 @@ dependencies:
intl: 0.19.0 intl: 0.19.0
flutter_svg: ^2.0.10+1 flutter_svg: ^2.0.10+1
dotted_border: ^2.1.0 dotted_border: ^2.1.0
collection: ^1.18.0
dev_dependencies: dev_dependencies:
flutter_iconica_analysis: flutter_iconica_analysis:

View file

@ -13,7 +13,7 @@ class LocalPostRepository implements PostRepositoryInterface {
final StreamController<List<TimelinePost>> _postsController = final StreamController<List<TimelinePost>> _postsController =
BehaviorSubject<List<TimelinePost>>(); BehaviorSubject<List<TimelinePost>>();
TimelinePost? _currentPost; late TimelinePost? _currentPost;
final jane = const TimelineUser( final jane = const TimelineUser(
userId: "1", userId: "1",

View file

@ -1,3 +1,4 @@
import "package:collection/collection.dart";
import "package:timeline_repository_interface/src/interfaces/timeline_user_repository_interface.dart"; import "package:timeline_repository_interface/src/interfaces/timeline_user_repository_interface.dart";
import "package:timeline_repository_interface/src/models/timeline_user.dart"; import "package:timeline_repository_interface/src/models/timeline_user.dart";
@ -31,7 +32,7 @@ class LocalTimelineUserRepository implements TimelineUserRepositoryInterface {
@override @override
Future<TimelineUser?> getUser(String userId) { Future<TimelineUser?> getUser(String userId) {
// TODO: implement getUser var user = _users.firstWhereOrNull((element) => element.userId == userId);
throw UnimplementedError(); return Future.value(user);
} }
} }

View file

@ -1,5 +1,4 @@
import "dart:typed_data"; import "dart:typed_data";
import "package:timeline_repository_interface/src/local/local_timeline_user_repository.dart";
import "package:timeline_repository_interface/timeline_repository_interface.dart"; import "package:timeline_repository_interface/timeline_repository_interface.dart";
class TimelineService { class TimelineService {

View file

@ -11,6 +11,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
rxdart: any rxdart: any
collection: ^1.18.0
dev_dependencies: dev_dependencies:
flutter_iconica_analysis: flutter_iconica_analysis: