From 3bd7b0951fa2cbd3a36143f4772cc970612edb74 Mon Sep 17 00:00:00 2001 From: mike doornenbal Date: Thu, 1 Aug 2024 09:32:09 +0200 Subject: [PATCH] fix: remove gorouter --- README.md | 40 +-- .../example/lib/apps/go_router/app.dart | 41 --- .../flutter_timeline/example/lib/main.dart | 10 +- .../flutter_timeline/example/pubspec.yaml | 1 - .../lib/flutter_timeline.dart | 1 - .../flutter_timeline_gorouter_userstory.dart | 293 ------------------ .../flutter_timeline/lib/src/go_router.dart | 30 -- packages/flutter_timeline/pubspec.yaml | 5 +- 8 files changed, 4 insertions(+), 417 deletions(-) delete mode 100644 packages/flutter_timeline/example/lib/apps/go_router/app.dart delete mode 100644 packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart delete mode 100644 packages/flutter_timeline/lib/src/go_router.dart diff --git a/README.md b/README.md index 1279960..1ecc8bc 100644 --- a/README.md +++ b/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 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: [ - 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), diff --git a/packages/flutter_timeline/example/lib/apps/go_router/app.dart b/packages/flutter_timeline/example/lib/apps/go_router/app.dart deleted file mode 100644 index 082edae..0000000 --- a/packages/flutter_timeline/example/lib/apps/go_router/app.dart +++ /dev/null @@ -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 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, - ), - ); - } -} diff --git a/packages/flutter_timeline/example/lib/main.dart b/packages/flutter_timeline/example/lib/main.dart index 0d097aa..8599ddf 100644 --- a/packages/flutter_timeline/example/lib/main.dart +++ b/packages/flutter_timeline/example/lib/main.dart @@ -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()); } diff --git a/packages/flutter_timeline/example/pubspec.yaml b/packages/flutter_timeline/example/pubspec.yaml index 9008d45..4f0c7fc 100644 --- a/packages/flutter_timeline/example/pubspec.yaml +++ b/packages/flutter_timeline/example/pubspec.yaml @@ -38,7 +38,6 @@ dependencies: flutter_timeline: path: ../ intl: ^0.19.0 - go_router: ^13.0.1 dev_dependencies: flutter_test: diff --git a/packages/flutter_timeline/lib/flutter_timeline.dart b/packages/flutter_timeline/lib/flutter_timeline.dart index f03d1f1..071b8aa 100644 --- a/packages/flutter_timeline/lib/flutter_timeline.dart +++ b/packages/flutter_timeline/lib/flutter_timeline.dart @@ -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'; diff --git a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart b/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart deleted file mode 100644 index 0ad5869..0000000 --- a/packages/flutter_timeline/lib/src/flutter_timeline_gorouter_userstory.dart +++ /dev/null @@ -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 getTimelineStoryRoutes({ - TimelineUserStoryConfiguration? configuration, -}) { - var config = configuration ?? - TimelineUserStoryConfiguration( - userId: 'test_user', - service: TimelineService( - postService: LocalTimelinePostService(), - ), - optionsBuilder: (context) => const TimelineOptions(), - ); - - return [ - 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, - ), - ); - }, - ), - ]; -} diff --git a/packages/flutter_timeline/lib/src/go_router.dart b/packages/flutter_timeline/lib/src/go_router.dart deleted file mode 100644 index c9113db..0000000 --- a/packages/flutter_timeline/lib/src/go_router.dart +++ /dev/null @@ -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({ - required BuildContext context, - required GoRouterState state, - required Widget child, -}) => - CustomTransitionPage( - key: state.pageKey, - child: child, - transitionsBuilder: (context, animation, secondaryAnimation, child) => - FadeTransition(opacity: animation, child: child), - ); - -CustomTransitionPage buildScreenWithoutTransition({ - required BuildContext context, - required GoRouterState state, - required Widget child, -}) => - CustomTransitionPage( - key: state.pageKey, - child: child, - transitionsBuilder: (context, animation, secondaryAnimation, child) => - child, - ); diff --git a/packages/flutter_timeline/pubspec.yaml b/packages/flutter_timeline/pubspec.yaml index ffefefb..d7fa66d 100644 --- a/packages/flutter_timeline/pubspec.yaml +++ b/packages/flutter_timeline/pubspec.yaml @@ -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