mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +02:00
fix: Fix some issues liek go router config
This commit is contained in:
parent
e5e2eb5c22
commit
9125c47ac4
6 changed files with 91 additions and 5 deletions
33
README.md
33
README.md
|
@ -26,6 +26,39 @@ If you are going to use Firebase as the back-end of the Timeline, you should als
|
||||||
## How to use
|
## How to use
|
||||||
To use the module within your Flutter-application with predefined `Go_router` routes you should add the following:
|
To use the module within your Flutter-application with predefined `Go_router` routes you should add the following:
|
||||||
|
|
||||||
|
Add go_router as dependency to your project.
|
||||||
|
Add the following configuration to your flutter_application:
|
||||||
|
|
||||||
|
```
|
||||||
|
List<GoRoute> getTimelineStoryRoutes() => getTimelineStoryRoutes(
|
||||||
|
TimelineUserStoryConfiguration(
|
||||||
|
service: FirebaseTimelineService(),
|
||||||
|
userService: FirebaseUserService(),
|
||||||
|
userId: currentUserId,
|
||||||
|
categoriesBuilder: (context) {},
|
||||||
|
optionsBuilder: (context) {},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the `getTimelineStoryRoutes()` to your go_router routes like so:
|
||||||
|
|
||||||
|
```
|
||||||
|
final GoRouter _router = GoRouter(
|
||||||
|
routes: <RouteBase>[
|
||||||
|
GoRoute(
|
||||||
|
path: '/',
|
||||||
|
builder: (BuildContext context, GoRouterState state) {
|
||||||
|
return const MyHomePage(
|
||||||
|
title: "home",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
...getTimelineStoryRoutes()
|
||||||
|
],
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
To add the `TimelineScreen` add the following code:
|
To add the `TimelineScreen` add the following code:
|
||||||
|
|
||||||
````
|
````
|
||||||
|
|
|
@ -25,7 +25,7 @@ class _PostScreenState extends State<PostScreen> {
|
||||||
options: TimelineOptions(),
|
options: TimelineOptions(),
|
||||||
post: widget.post,
|
post: widget.post,
|
||||||
onPostDelete: () {
|
onPostDelete: () {
|
||||||
print('delete post');
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,8 +16,6 @@ List<GoRoute> getTimelineStoryRoutes(
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: TimelineUserStoryRoutes.timelineHome,
|
path: TimelineUserStoryRoutes.timelineHome,
|
||||||
pageBuilder: (context, state) {
|
pageBuilder: (context, state) {
|
||||||
var timelineFilter =
|
|
||||||
Container(); // TODO(anyone): create a filter widget
|
|
||||||
var timelineScreen = TimelineScreen(
|
var timelineScreen = TimelineScreen(
|
||||||
userId: configuration.userId,
|
userId: configuration.userId,
|
||||||
onUserTap: (user) => configuration.onUserTap?.call(context, user),
|
onUserTap: (user) => configuration.onUserTap?.call(context, user),
|
||||||
|
@ -31,7 +29,6 @@ List<GoRoute> getTimelineStoryRoutes(
|
||||||
state: state,
|
state: state,
|
||||||
child: configuration.mainPageBuilder?.call(
|
child: configuration.mainPageBuilder?.call(
|
||||||
context,
|
context,
|
||||||
timelineFilter,
|
|
||||||
timelineScreen,
|
timelineScreen,
|
||||||
) ??
|
) ??
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
|
|
@ -25,7 +25,7 @@ class TimelineUserStoryConfiguration {
|
||||||
|
|
||||||
final Function(BuildContext context, String userId)? onUserTap;
|
final Function(BuildContext context, String userId)? onUserTap;
|
||||||
|
|
||||||
final Widget Function(BuildContext context, Widget filterBar, Widget child)?
|
final Widget Function(BuildContext context, Widget child)?
|
||||||
mainPageBuilder;
|
mainPageBuilder;
|
||||||
|
|
||||||
final Widget Function(
|
final Widget Function(
|
||||||
|
|
|
@ -7,3 +7,4 @@ library flutter_timeline_firebase;
|
||||||
|
|
||||||
export 'src/config/firebase_timeline_options.dart';
|
export 'src/config/firebase_timeline_options.dart';
|
||||||
export 'src/service/firebase_timeline_service.dart';
|
export 'src/service/firebase_timeline_service.dart';
|
||||||
|
export 'src/service/firebase_user_service.dart';
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Iconica
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
|
import 'package:flutter_timeline_firebase/src/config/firebase_timeline_options.dart';
|
||||||
|
import 'package:flutter_timeline_firebase/src/models/firebase_user_document.dart';
|
||||||
|
import 'package:flutter_timeline_interface/flutter_timeline_interface.dart';
|
||||||
|
|
||||||
|
class FirebaseUserService implements TimelineUserService {
|
||||||
|
FirebaseUserService({
|
||||||
|
FirebaseApp? app,
|
||||||
|
options = const FirebaseTimelineOptions(),
|
||||||
|
}) {
|
||||||
|
var appInstance = app ?? Firebase.app();
|
||||||
|
_db = FirebaseFirestore.instanceFor(app: appInstance);
|
||||||
|
_options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
late FirebaseFirestore _db;
|
||||||
|
late FirebaseTimelineOptions _options;
|
||||||
|
|
||||||
|
final Map<String, TimelinePosterUserModel> _users = {};
|
||||||
|
|
||||||
|
CollectionReference<FirebaseUserDocument> get _userCollection => _db
|
||||||
|
.collection(_options.usersCollectionName)
|
||||||
|
.withConverter<FirebaseUserDocument>(
|
||||||
|
fromFirestore: (snapshot, _) => FirebaseUserDocument.fromJson(
|
||||||
|
snapshot.data()!,
|
||||||
|
snapshot.id,
|
||||||
|
),
|
||||||
|
toFirestore: (user, _) => user.toJson(),
|
||||||
|
);
|
||||||
|
@override
|
||||||
|
Future<TimelinePosterUserModel?> getUser(String userId) async {
|
||||||
|
if (_users.containsKey(userId)) {
|
||||||
|
return _users[userId]!;
|
||||||
|
}
|
||||||
|
var data = (await _userCollection.doc(userId).get()).data();
|
||||||
|
|
||||||
|
var user = data == null
|
||||||
|
? TimelinePosterUserModel(userId: userId)
|
||||||
|
: TimelinePosterUserModel(
|
||||||
|
userId: userId,
|
||||||
|
firstName: data.firstName,
|
||||||
|
lastName: data.lastName,
|
||||||
|
imageUrl: data.imageUrl,
|
||||||
|
);
|
||||||
|
|
||||||
|
_users[userId] = user;
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue