mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-18 10:13:43 +02:00
fix: remove gorouter
This commit is contained in:
parent
a8897242e7
commit
3bd7b0951f
8 changed files with 4 additions and 417 deletions
40
README.md
40
README.md
|
@ -35,45 +35,7 @@ And import this package: import 'package:intl/date_symbol_data_local.dart';
|
|||
```
|
||||
|
||||
## How to use
|
||||
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: TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
),
|
||||
optionsBuilder: (context) {
|
||||
return const TimelineOptions();
|
||||
},
|
||||
),
|
||||
);
|
||||
```
|
||||
|
||||
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(configuration: configuration);
|
||||
],
|
||||
);
|
||||
```
|
||||
|
||||
The user story can also be used without go router:
|
||||
Add the following code somewhere in your widget tree:
|
||||
To use the userstory add the following code somewhere in your widget tree:
|
||||
|
||||
````
|
||||
timeLineNavigatorUserStory(TimelineUserStoryConfiguration, context),
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
import 'package:example/config/config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_timeline/flutter_timeline.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
List<GoRoute> getTimelineRoutes() => getTimelineStoryRoutes(
|
||||
configuration: getConfig(TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
)),
|
||||
);
|
||||
|
||||
final _router = GoRouter(
|
||||
initialLocation: '/timeline',
|
||||
routes: [
|
||||
...getTimelineRoutes(),
|
||||
],
|
||||
);
|
||||
|
||||
class GoRouterApp extends StatelessWidget {
|
||||
const GoRouterApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp.router(
|
||||
routerConfig: _router,
|
||||
title: 'Flutter Timeline',
|
||||
theme: ThemeData(
|
||||
textTheme: const TextTheme(
|
||||
titleLarge: TextStyle(
|
||||
color: Color(0xffb71c6d), fontFamily: 'Playfair Display')),
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: const Color(0xFFB8E2E8),
|
||||
primary: const Color(0xffb71c6d),
|
||||
).copyWith(
|
||||
surface: const Color(0XFFFAF9F6),
|
||||
),
|
||||
useMaterial3: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,9 @@
|
|||
// import 'package:example/apps/go_router/app.dart';
|
||||
// import 'package:example/apps/navigator/app.dart';
|
||||
import 'package:example/apps/go_router/app.dart';
|
||||
import 'package:example/apps/navigator/app.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
|
||||
void main() {
|
||||
initializeDateFormatting();
|
||||
|
||||
// Uncomment any, but only one, of these lines to run the example with specific navigation.
|
||||
|
||||
// runApp(const WidgetApp());
|
||||
// runApp(const NavigatorApp());
|
||||
runApp(const GoRouterApp());
|
||||
runApp(const NavigatorApp());
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ dependencies:
|
|||
flutter_timeline:
|
||||
path: ../
|
||||
intl: ^0.19.0
|
||||
go_router: ^13.0.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
/// Flutter Timeline library
|
||||
library flutter_timeline;
|
||||
|
||||
export 'package:flutter_timeline/src/flutter_timeline_gorouter_userstory.dart';
|
||||
export 'package:flutter_timeline/src/flutter_timeline_navigator_userstory.dart';
|
||||
export 'package:flutter_timeline/src/models/timeline_configuration.dart';
|
||||
export 'package:flutter_timeline/src/routes.dart';
|
||||
|
|
|
@ -1,293 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Iconica
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_timeline/flutter_timeline.dart';
|
||||
import 'package:flutter_timeline/src/go_router.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
/// Retrieves a list of GoRouter routes for timeline stories.
|
||||
///
|
||||
/// This function retrieves a list of GoRouter routes for displaying timeline
|
||||
/// stories. It takes an optional [TimelineUserStoryConfiguration] as parameter.
|
||||
/// If no configuration is provided, default values will be used.
|
||||
List<GoRoute> getTimelineStoryRoutes({
|
||||
TimelineUserStoryConfiguration? configuration,
|
||||
}) {
|
||||
var config = configuration ??
|
||||
TimelineUserStoryConfiguration(
|
||||
userId: 'test_user',
|
||||
service: TimelineService(
|
||||
postService: LocalTimelinePostService(),
|
||||
),
|
||||
optionsBuilder: (context) => const TimelineOptions(),
|
||||
);
|
||||
|
||||
return <GoRoute>[
|
||||
GoRoute(
|
||||
path: TimelineUserStoryRoutes.timelineHome,
|
||||
pageBuilder: (context, state) {
|
||||
var service = config.serviceBuilder?.call(context) ?? config.service;
|
||||
var timelineScreen = TimelineScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
onUserTap: (user) => config.onUserTap?.call(context, user),
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
onRefresh: config.onRefresh,
|
||||
service: service,
|
||||
options: config.optionsBuilder(context),
|
||||
onPostTap: (post) async =>
|
||||
config.onPostTap?.call(context, post) ??
|
||||
await context.push(
|
||||
TimelineUserStoryRoutes.timelineViewPath(post.id),
|
||||
),
|
||||
filterEnabled: config.filterEnabled,
|
||||
postWidgetBuilder: config.postWidgetBuilder,
|
||||
);
|
||||
var theme = Theme.of(context);
|
||||
var button = FloatingActionButton(
|
||||
backgroundColor: config
|
||||
.optionsBuilder(context)
|
||||
.theme
|
||||
.postCreationFloatingActionButtonColor ??
|
||||
theme.colorScheme.primary,
|
||||
onPressed: () async => context.push(
|
||||
TimelineUserStoryRoutes.timelineCategorySelection,
|
||||
),
|
||||
shape: const CircleBorder(),
|
||||
child: const Icon(
|
||||
Icons.add,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
);
|
||||
|
||||
return buildScreenWithoutTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: config.homeOpenPageBuilder
|
||||
?.call(context, timelineScreen, button) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
config
|
||||
.optionsBuilder(context)
|
||||
.translations
|
||||
.timeLineScreenTitle,
|
||||
style: theme.textTheme.headlineLarge,
|
||||
),
|
||||
),
|
||||
body: timelineScreen,
|
||||
floatingActionButton: button,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: TimelineUserStoryRoutes.timelineCategorySelection,
|
||||
pageBuilder: (context, state) {
|
||||
var timelineSelectionScreen = TimelineSelectionScreen(
|
||||
postService: config.service.postService,
|
||||
options: config.optionsBuilder(context),
|
||||
categories: config.service.postService.categories,
|
||||
onCategorySelected: (category) async {
|
||||
await context.push(
|
||||
TimelineUserStoryRoutes.timelinepostCreation(category.key ?? ''),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
var backButton = IconButton(
|
||||
color: Colors.white,
|
||||
icon: const Icon(Icons.arrow_back_ios),
|
||||
onPressed: () => context.go(TimelineUserStoryRoutes.timelineHome),
|
||||
);
|
||||
|
||||
return buildScreenWithoutTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: config.categorySelectionOpenPageBuilder
|
||||
?.call(context, timelineSelectionScreen) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: backButton,
|
||||
title: Text(
|
||||
config.optionsBuilder(context).translations.postCreation,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: timelineSelectionScreen,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: TimelineUserStoryRoutes.timelineView,
|
||||
pageBuilder: (context, state) {
|
||||
var service = config.serviceBuilder?.call(context) ?? config.service;
|
||||
var post = service.postService.getPost(state.pathParameters['post']!);
|
||||
var category = service.postService.categories.firstWhereOrNull(
|
||||
(element) => element.key == post?.category,
|
||||
);
|
||||
|
||||
var timelinePostWidget = TimelinePostScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
allowAllDeletion: config.canDeleteAllPosts?.call(context) ?? false,
|
||||
options: config.optionsBuilder(context),
|
||||
service: service,
|
||||
post: post!,
|
||||
onPostDelete: () async =>
|
||||
config.onPostDelete?.call(context, post) ??
|
||||
() async {
|
||||
await service.postService.deletePost(post);
|
||||
if (!context.mounted) return;
|
||||
context.go(TimelineUserStoryRoutes.timelineHome);
|
||||
}.call(),
|
||||
onUserTap: (user) => config.onUserTap?.call(context, user),
|
||||
);
|
||||
|
||||
var backButton = IconButton(
|
||||
color: Colors.white,
|
||||
icon: const Icon(Icons.arrow_back_ios),
|
||||
onPressed: () => context.go(TimelineUserStoryRoutes.timelineHome),
|
||||
);
|
||||
|
||||
return buildScreenWithoutTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: config.postViewOpenPageBuilder?.call(
|
||||
context,
|
||||
timelinePostWidget,
|
||||
backButton,
|
||||
post,
|
||||
category,
|
||||
) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: backButton,
|
||||
title: Text(
|
||||
category?.title ?? post.category ?? 'Category',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: timelinePostWidget,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: TimelineUserStoryRoutes.timelinePostCreation,
|
||||
pageBuilder: (context, state) {
|
||||
var category = state.pathParameters['category'];
|
||||
var service = config.serviceBuilder?.call(context) ?? config.service;
|
||||
var timelinePostCreationWidget = TimelinePostCreationScreen(
|
||||
userId: config.getUserId?.call(context) ?? config.userId,
|
||||
options: config.optionsBuilder(context),
|
||||
service: service,
|
||||
onPostCreated: (post) async {
|
||||
var newPost = await service.postService.createPost(post);
|
||||
if (!context.mounted) return;
|
||||
if (config.afterPostCreationGoHome) {
|
||||
context.go(TimelineUserStoryRoutes.timelineHome);
|
||||
} else {
|
||||
await context
|
||||
.push(TimelineUserStoryRoutes.timelineViewPath(newPost.id));
|
||||
}
|
||||
},
|
||||
onPostOverview: (post) async => context.push(
|
||||
TimelineUserStoryRoutes.timelinePostOverview,
|
||||
extra: post,
|
||||
),
|
||||
enablePostOverviewScreen: config.enablePostOverviewScreen,
|
||||
postCategory: category,
|
||||
);
|
||||
|
||||
var backButton = IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_back_ios,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: () =>
|
||||
context.go(TimelineUserStoryRoutes.timelineCategorySelection),
|
||||
);
|
||||
|
||||
return buildScreenWithoutTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: config.postCreationOpenPageBuilder
|
||||
?.call(context, timelinePostCreationWidget, backButton) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: backButton,
|
||||
title: Text(
|
||||
config.optionsBuilder(context).translations.postCreation,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: timelinePostCreationWidget,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: TimelineUserStoryRoutes.timelinePostOverview,
|
||||
pageBuilder: (context, state) {
|
||||
var post = state.extra! as TimelinePost;
|
||||
var service = config.serviceBuilder?.call(context) ?? config.service;
|
||||
var timelinePostOverviewWidget = TimelinePostOverviewScreen(
|
||||
options: config.optionsBuilder(context),
|
||||
service: service,
|
||||
timelinePost: post,
|
||||
onPostSubmit: (post) async {
|
||||
await service.postService.createPost(post);
|
||||
if (!context.mounted) return;
|
||||
context.go(TimelineUserStoryRoutes.timelineHome);
|
||||
},
|
||||
);
|
||||
var backButton = IconButton(
|
||||
icon: const Icon(
|
||||
Icons.arrow_back_ios,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: () async => context.pop(),
|
||||
);
|
||||
|
||||
return buildScreenWithoutTransition(
|
||||
context: context,
|
||||
state: state,
|
||||
child: config.postOverviewOpenPageBuilder?.call(
|
||||
context,
|
||||
timelinePostOverviewWidget,
|
||||
) ??
|
||||
Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: backButton,
|
||||
title: Text(
|
||||
config.optionsBuilder(context).translations.postOverview,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).primaryColor,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: timelinePostOverviewWidget,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Iconica
|
||||
//
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
CustomTransitionPage buildScreenWithFadeTransition<T>({
|
||||
required BuildContext context,
|
||||
required GoRouterState state,
|
||||
required Widget child,
|
||||
}) =>
|
||||
CustomTransitionPage<T>(
|
||||
key: state.pageKey,
|
||||
child: child,
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
||||
FadeTransition(opacity: animation, child: child),
|
||||
);
|
||||
|
||||
CustomTransitionPage buildScreenWithoutTransition<T>({
|
||||
required BuildContext context,
|
||||
required GoRouterState state,
|
||||
required Widget child,
|
||||
}) =>
|
||||
CustomTransitionPage<T>(
|
||||
key: state.pageKey,
|
||||
child: child,
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
|
||||
child,
|
||||
);
|
|
@ -13,10 +13,6 @@ environment:
|
|||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
go_router: any
|
||||
|
||||
collection: any
|
||||
|
||||
flutter_timeline_view:
|
||||
git:
|
||||
url: https://github.com/Iconica-Development/flutter_timeline
|
||||
|
@ -28,6 +24,7 @@ dependencies:
|
|||
url: https://github.com/Iconica-Development/flutter_timeline
|
||||
path: packages/flutter_timeline_interface
|
||||
ref: 4.1.0
|
||||
collection: any
|
||||
dependency_overrides:
|
||||
flutter_timeline_view:
|
||||
path: ../flutter_timeline_view
|
||||
|
|
Loading…
Reference in a new issue