From 7c61ac2df453af8d4dd797c5dac401a508c6b1d3 Mon Sep 17 00:00:00 2001 From: enzo soares Date: Thu, 11 Jul 2024 16:02:31 +0200 Subject: [PATCH 1/3] Moving profile cache from bloc state to repository --- packages/app/lib/app/app_router.gr.dart | 287 +++++++----------- .../app/lib/event/fragments/user_events.dart | 5 +- .../lib/event/widgets/map/journey_map.dart | 3 - packages/app/lib/main.dart | 2 - .../profile_bloc/events/profile_event.dart | 31 ++ .../events/profile_load_event.dart | 63 ++++ .../profile_bloc/events/user_load_event.dart | 83 +++++ .../bloc/profile_bloc/profile_bloc.dart | 140 +++++---- .../bloc/profile_bloc/profile_event.dart | 21 -- .../bloc/profile_bloc/profile_state.dart | 109 ++----- .../app/lib/profile/screens/me_screen.dart | 19 +- .../lib/profile/screens/profile_screen.dart | 43 ++- .../app/lib/profile/services/profile_api.dart | 12 +- .../profile/services/profile_repository.dart | 31 +- .../widgets/profile_bottom_bar_button.dart | 40 ++- .../profile_modal/profile_modal_list.dart | 2 +- .../search_profile_card.dart | 2 +- 17 files changed, 513 insertions(+), 380 deletions(-) create mode 100644 packages/app/lib/profile/bloc/profile_bloc/events/profile_event.dart create mode 100644 packages/app/lib/profile/bloc/profile_bloc/events/profile_load_event.dart create mode 100644 packages/app/lib/profile/bloc/profile_bloc/events/user_load_event.dart delete mode 100644 packages/app/lib/profile/bloc/profile_bloc/profile_event.dart diff --git a/packages/app/lib/app/app_router.gr.dart b/packages/app/lib/app/app_router.gr.dart index 7916ca03..df44b6d7 100644 --- a/packages/app/lib/app/app_router.gr.dart +++ b/packages/app/lib/app/app_router.gr.dart @@ -8,41 +8,38 @@ // coverage:ignore-file // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:io' as _i19; - -import 'package:auto_route/auto_route.dart' as _i13; -import 'package:flutter/material.dart' as _i14; -import 'package:hollybike/auth/screens/login_screen.dart' as _i8; -import 'package:hollybike/auth/screens/signup_screen.dart' as _i12; +import 'package:auto_route/auto_route.dart' as _i12; +import 'package:flutter/material.dart' as _i13; +import 'package:hollybike/auth/screens/login_screen.dart' as _i7; +import 'package:hollybike/auth/screens/signup_screen.dart' as _i11; import 'package:hollybike/event/screens/event_details_screen.dart' as _i2; import 'package:hollybike/event/screens/events_screen.dart' as _i4; import 'package:hollybike/event/screens/participations/event_candidates_screen.dart' as _i1; import 'package:hollybike/event/screens/participations/event_participations_screen.dart' as _i3; -import 'package:hollybike/event/types/event_details.dart' as _i16; -import 'package:hollybike/event/types/minimal_event.dart' as _i15; +import 'package:hollybike/event/types/event_details.dart' as _i15; +import 'package:hollybike/event/types/minimal_event.dart' as _i14; import 'package:hollybike/event/types/participation/event_participation.dart' - as _i17; -import 'package:hollybike/image/bloc/image_list_bloc.dart' as _i18; + as _i16; +import 'package:hollybike/image/bloc/image_list_bloc.dart' as _i17; import 'package:hollybike/image/screens/image_gallery_page_view_screen.dart' as _i5; -import 'package:hollybike/journey/screen/import_gpx_tool_screen.dart' as _i6; -import 'package:hollybike/profile/screens/me_screen.dart' as _i9; -import 'package:hollybike/profile/screens/profile_screen.dart' as _i10; -import 'package:hollybike/search/screens/search_screen.dart' as _i11; -import 'package:hollybike/shared/routes/loading_route.dart' as _i7; +import 'package:hollybike/profile/screens/me_screen.dart' as _i8; +import 'package:hollybike/profile/screens/profile_screen.dart' as _i9; +import 'package:hollybike/search/screens/search_screen.dart' as _i10; +import 'package:hollybike/shared/routes/loading_route.dart' as _i6; -abstract class $AppRouter extends _i13.RootStackRouter { +abstract class $AppRouter extends _i12.RootStackRouter { $AppRouter({super.navigatorKey}); @override - final Map pagesMap = { + final Map pagesMap = { EventCandidatesRoute.name: (routeData) { final args = routeData.argsAs(); - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: _i13.WrappedRoute( + child: _i12.WrappedRoute( child: _i1.EventCandidatesScreen( key: args.key, eventId: args.eventId, @@ -51,9 +48,9 @@ abstract class $AppRouter extends _i13.RootStackRouter { }, EventDetailsRoute.name: (routeData) { final args = routeData.argsAs(); - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: _i13.WrappedRoute( + child: _i12.WrappedRoute( child: _i2.EventDetailsScreen( key: args.key, event: args.event, @@ -64,9 +61,9 @@ abstract class $AppRouter extends _i13.RootStackRouter { }, EventParticipationsRoute.name: (routeData) { final args = routeData.argsAs(); - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: _i13.WrappedRoute( + child: _i12.WrappedRoute( child: _i3.EventParticipationsScreen( key: args.key, eventDetails: args.eventDetails, @@ -75,16 +72,16 @@ abstract class $AppRouter extends _i13.RootStackRouter { ); }, EventsRoute.name: (routeData) { - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: _i13.WrappedRoute(child: const _i4.EventsScreen()), + child: _i12.WrappedRoute(child: const _i4.EventsScreen()), ); }, ImageGalleryViewRoute.name: (routeData) { final args = routeData.argsAs(); - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: _i13.WrappedRoute( + child: _i12.WrappedRoute( child: _i5.ImageGalleryViewScreen( key: args.key, imageIndex: args.imageIndex, @@ -94,29 +91,17 @@ abstract class $AppRouter extends _i13.RootStackRouter { )), ); }, - ImportGpxToolRoute.name: (routeData) { - final args = routeData.argsAs(); - return _i13.AutoRoutePage( - routeData: routeData, - child: _i6.ImportGpxToolScreen( - key: args.key, - url: args.url, - onGpxDownloaded: args.onGpxDownloaded, - onClose: args.onClose, - ), - ); - }, LoadingRoute.name: (routeData) { - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: const _i7.LoadingRoute(), + child: const _i6.LoadingRoute(), ); }, LoginRoute.name: (routeData) { final args = routeData.argsAs(); - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: _i8.LoginScreen( + child: _i7.LoginScreen( key: args.key, onAuthSuccess: args.onAuthSuccess, canPop: args.canPop, @@ -124,35 +109,35 @@ abstract class $AppRouter extends _i13.RootStackRouter { ); }, MeRoute.name: (routeData) { - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: const _i9.MeScreen(), + child: const _i8.MeScreen(), ); }, ProfileRoute.name: (routeData) { final pathParams = routeData.inheritedPathParams; final args = routeData.argsAs( - orElse: () => ProfileRouteArgs(id: pathParams.optString('id'))); - return _i13.AutoRoutePage( + orElse: () => ProfileRouteArgs(urlId: pathParams.optString('id'))); + return _i12.AutoRoutePage( routeData: routeData, - child: _i10.ProfileScreen( + child: _i9.ProfileScreen( key: args.key, - id: args.id, + urlId: args.urlId, ), ); }, SearchRoute.name: (routeData) { - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: const _i11.SearchScreen(), + child: const _i10.SearchScreen(), ); }, SignupRoute.name: (routeData) { final args = routeData.argsAs( orElse: () => const SignupRouteArgs()); - return _i13.AutoRoutePage( + return _i12.AutoRoutePage( routeData: routeData, - child: _i12.SignupScreen( + child: _i11.SignupScreen( key: args.key, onAuthSuccess: args.onAuthSuccess, canPop: args.canPop, @@ -165,11 +150,11 @@ abstract class $AppRouter extends _i13.RootStackRouter { /// generated route for /// [_i1.EventCandidatesScreen] class EventCandidatesRoute - extends _i13.PageRouteInfo { + extends _i12.PageRouteInfo { EventCandidatesRoute({ - _i14.Key? key, + _i13.Key? key, required int eventId, - List<_i13.PageRouteInfo>? children, + List<_i12.PageRouteInfo>? children, }) : super( EventCandidatesRoute.name, args: EventCandidatesRouteArgs( @@ -181,8 +166,8 @@ class EventCandidatesRoute static const String name = 'EventCandidatesRoute'; - static const _i13.PageInfo page = - _i13.PageInfo(name); + static const _i12.PageInfo page = + _i12.PageInfo(name); } class EventCandidatesRouteArgs { @@ -191,7 +176,7 @@ class EventCandidatesRouteArgs { required this.eventId, }); - final _i14.Key? key; + final _i13.Key? key; final int eventId; @@ -203,13 +188,13 @@ class EventCandidatesRouteArgs { /// generated route for /// [_i2.EventDetailsScreen] -class EventDetailsRoute extends _i13.PageRouteInfo { +class EventDetailsRoute extends _i12.PageRouteInfo { EventDetailsRoute({ - _i14.Key? key, - required _i15.MinimalEvent event, + _i13.Key? key, + required _i14.MinimalEvent event, bool animate = true, String uniqueKey = "default", - List<_i13.PageRouteInfo>? children, + List<_i12.PageRouteInfo>? children, }) : super( EventDetailsRoute.name, args: EventDetailsRouteArgs( @@ -223,8 +208,8 @@ class EventDetailsRoute extends _i13.PageRouteInfo { static const String name = 'EventDetailsRoute'; - static const _i13.PageInfo page = - _i13.PageInfo(name); + static const _i12.PageInfo page = + _i12.PageInfo(name); } class EventDetailsRouteArgs { @@ -235,9 +220,9 @@ class EventDetailsRouteArgs { this.uniqueKey = "default", }); - final _i14.Key? key; + final _i13.Key? key; - final _i15.MinimalEvent event; + final _i14.MinimalEvent event; final bool animate; @@ -252,12 +237,12 @@ class EventDetailsRouteArgs { /// generated route for /// [_i3.EventParticipationsScreen] class EventParticipationsRoute - extends _i13.PageRouteInfo { + extends _i12.PageRouteInfo { EventParticipationsRoute({ - _i14.Key? key, - required _i16.EventDetails eventDetails, - required List<_i17.EventParticipation> participationPreview, - List<_i13.PageRouteInfo>? children, + _i13.Key? key, + required _i15.EventDetails eventDetails, + required List<_i16.EventParticipation> participationPreview, + List<_i12.PageRouteInfo>? children, }) : super( EventParticipationsRoute.name, args: EventParticipationsRouteArgs( @@ -270,8 +255,8 @@ class EventParticipationsRoute static const String name = 'EventParticipationsRoute'; - static const _i13.PageInfo page = - _i13.PageInfo(name); + static const _i12.PageInfo page = + _i12.PageInfo(name); } class EventParticipationsRouteArgs { @@ -281,11 +266,11 @@ class EventParticipationsRouteArgs { required this.participationPreview, }); - final _i14.Key? key; + final _i13.Key? key; - final _i16.EventDetails eventDetails; + final _i15.EventDetails eventDetails; - final List<_i17.EventParticipation> participationPreview; + final List<_i16.EventParticipation> participationPreview; @override String toString() { @@ -295,8 +280,8 @@ class EventParticipationsRouteArgs { /// generated route for /// [_i4.EventsScreen] -class EventsRoute extends _i13.PageRouteInfo { - const EventsRoute({List<_i13.PageRouteInfo>? children}) +class EventsRoute extends _i12.PageRouteInfo { + const EventsRoute({List<_i12.PageRouteInfo>? children}) : super( EventsRoute.name, initialChildren: children, @@ -304,20 +289,20 @@ class EventsRoute extends _i13.PageRouteInfo { static const String name = 'EventsRoute'; - static const _i13.PageInfo page = _i13.PageInfo(name); + static const _i12.PageInfo page = _i12.PageInfo(name); } /// generated route for /// [_i5.ImageGalleryViewScreen] class ImageGalleryViewRoute - extends _i13.PageRouteInfo { + extends _i12.PageRouteInfo { ImageGalleryViewRoute({ - _i14.Key? key, + _i13.Key? key, required int imageIndex, required void Function() onLoadNextPage, required void Function() onRefresh, - required _i18.ImageListBloc bloc, - List<_i13.PageRouteInfo>? children, + required _i17.ImageListBloc bloc, + List<_i12.PageRouteInfo>? children, }) : super( ImageGalleryViewRoute.name, args: ImageGalleryViewRouteArgs( @@ -332,8 +317,8 @@ class ImageGalleryViewRoute static const String name = 'ImageGalleryViewRoute'; - static const _i13.PageInfo page = - _i13.PageInfo(name); + static const _i12.PageInfo page = + _i12.PageInfo(name); } class ImageGalleryViewRouteArgs { @@ -345,7 +330,7 @@ class ImageGalleryViewRouteArgs { required this.bloc, }); - final _i14.Key? key; + final _i13.Key? key; final int imageIndex; @@ -353,7 +338,7 @@ class ImageGalleryViewRouteArgs { final void Function() onRefresh; - final _i18.ImageListBloc bloc; + final _i17.ImageListBloc bloc; @override String toString() { @@ -362,57 +347,9 @@ class ImageGalleryViewRouteArgs { } /// generated route for -/// [_i6.ImportGpxToolScreen] -class ImportGpxToolRoute extends _i13.PageRouteInfo { - ImportGpxToolRoute({ - _i14.Key? key, - required String url, - required void Function(_i19.File) onGpxDownloaded, - required void Function() onClose, - List<_i13.PageRouteInfo>? children, - }) : super( - ImportGpxToolRoute.name, - args: ImportGpxToolRouteArgs( - key: key, - url: url, - onGpxDownloaded: onGpxDownloaded, - onClose: onClose, - ), - initialChildren: children, - ); - - static const String name = 'ImportGpxToolRoute'; - - static const _i13.PageInfo page = - _i13.PageInfo(name); -} - -class ImportGpxToolRouteArgs { - const ImportGpxToolRouteArgs({ - this.key, - required this.url, - required this.onGpxDownloaded, - required this.onClose, - }); - - final _i14.Key? key; - - final String url; - - final void Function(_i19.File) onGpxDownloaded; - - final void Function() onClose; - - @override - String toString() { - return 'ImportGpxToolRouteArgs{key: $key, url: $url, onGpxDownloaded: $onGpxDownloaded, onClose: $onClose}'; - } -} - -/// generated route for -/// [_i7.LoadingRoute] -class LoadingRoute extends _i13.PageRouteInfo { - const LoadingRoute({List<_i13.PageRouteInfo>? children}) +/// [_i6.LoadingRoute] +class LoadingRoute extends _i12.PageRouteInfo { + const LoadingRoute({List<_i12.PageRouteInfo>? children}) : super( LoadingRoute.name, initialChildren: children, @@ -420,17 +357,17 @@ class LoadingRoute extends _i13.PageRouteInfo { static const String name = 'LoadingRoute'; - static const _i13.PageInfo page = _i13.PageInfo(name); + static const _i12.PageInfo page = _i12.PageInfo(name); } /// generated route for -/// [_i8.LoginScreen] -class LoginRoute extends _i13.PageRouteInfo { +/// [_i7.LoginScreen] +class LoginRoute extends _i12.PageRouteInfo { LoginRoute({ - _i14.Key? key, + _i13.Key? key, required dynamic Function() onAuthSuccess, bool canPop = false, - List<_i13.PageRouteInfo>? children, + List<_i12.PageRouteInfo>? children, }) : super( LoginRoute.name, args: LoginRouteArgs( @@ -443,8 +380,8 @@ class LoginRoute extends _i13.PageRouteInfo { static const String name = 'LoginRoute'; - static const _i13.PageInfo page = - _i13.PageInfo(name); + static const _i12.PageInfo page = + _i12.PageInfo(name); } class LoginRouteArgs { @@ -454,7 +391,7 @@ class LoginRouteArgs { this.canPop = false, }); - final _i14.Key? key; + final _i13.Key? key; final dynamic Function() onAuthSuccess; @@ -467,9 +404,9 @@ class LoginRouteArgs { } /// generated route for -/// [_i9.MeScreen] -class MeRoute extends _i13.PageRouteInfo { - const MeRoute({List<_i13.PageRouteInfo>? children}) +/// [_i8.MeScreen] +class MeRoute extends _i12.PageRouteInfo { + const MeRoute({List<_i12.PageRouteInfo>? children}) : super( MeRoute.name, initialChildren: children, @@ -477,52 +414,52 @@ class MeRoute extends _i13.PageRouteInfo { static const String name = 'MeRoute'; - static const _i13.PageInfo page = _i13.PageInfo(name); + static const _i12.PageInfo page = _i12.PageInfo(name); } /// generated route for -/// [_i10.ProfileScreen] -class ProfileRoute extends _i13.PageRouteInfo { +/// [_i9.ProfileScreen] +class ProfileRoute extends _i12.PageRouteInfo { ProfileRoute({ - _i14.Key? key, - String? id, - List<_i13.PageRouteInfo>? children, + _i13.Key? key, + String? urlId, + List<_i12.PageRouteInfo>? children, }) : super( ProfileRoute.name, args: ProfileRouteArgs( key: key, - id: id, + urlId: urlId, ), - rawPathParams: {'id': id}, + rawPathParams: {'id': urlId}, initialChildren: children, ); static const String name = 'ProfileRoute'; - static const _i13.PageInfo page = - _i13.PageInfo(name); + static const _i12.PageInfo page = + _i12.PageInfo(name); } class ProfileRouteArgs { const ProfileRouteArgs({ this.key, - this.id, + this.urlId, }); - final _i14.Key? key; + final _i13.Key? key; - final String? id; + final String? urlId; @override String toString() { - return 'ProfileRouteArgs{key: $key, id: $id}'; + return 'ProfileRouteArgs{key: $key, urlId: $urlId}'; } } /// generated route for -/// [_i11.SearchScreen] -class SearchRoute extends _i13.PageRouteInfo { - const SearchRoute({List<_i13.PageRouteInfo>? children}) +/// [_i10.SearchScreen] +class SearchRoute extends _i12.PageRouteInfo { + const SearchRoute({List<_i12.PageRouteInfo>? children}) : super( SearchRoute.name, initialChildren: children, @@ -530,17 +467,17 @@ class SearchRoute extends _i13.PageRouteInfo { static const String name = 'SearchRoute'; - static const _i13.PageInfo page = _i13.PageInfo(name); + static const _i12.PageInfo page = _i12.PageInfo(name); } /// generated route for -/// [_i12.SignupScreen] -class SignupRoute extends _i13.PageRouteInfo { +/// [_i11.SignupScreen] +class SignupRoute extends _i12.PageRouteInfo { SignupRoute({ - _i14.Key? key, + _i13.Key? key, dynamic Function()? onAuthSuccess, bool canPop = false, - List<_i13.PageRouteInfo>? children, + List<_i12.PageRouteInfo>? children, }) : super( SignupRoute.name, args: SignupRouteArgs( @@ -553,8 +490,8 @@ class SignupRoute extends _i13.PageRouteInfo { static const String name = 'SignupRoute'; - static const _i13.PageInfo page = - _i13.PageInfo(name); + static const _i12.PageInfo page = + _i12.PageInfo(name); } class SignupRouteArgs { @@ -564,7 +501,7 @@ class SignupRouteArgs { this.canPop = false, }); - final _i14.Key? key; + final _i13.Key? key; final dynamic Function()? onAuthSuccess; diff --git a/packages/app/lib/event/fragments/user_events.dart b/packages/app/lib/event/fragments/user_events.dart index 6a973a66..eb1accb7 100644 --- a/packages/app/lib/event/fragments/user_events.dart +++ b/packages/app/lib/event/fragments/user_events.dart @@ -16,12 +16,13 @@ class UserEvents extends StatelessWidget { Widget build(BuildContext context) { return BlocProvidedBuilder( builder: (context, bloc, state) { - if (bloc.currentProfile == null) return const Text("loading"); + final currentProfile = bloc.currentProfile; + if (currentProfile is! ProfileLoadSuccessEvent) return const Text("loading"); return BlocProvider( create: (context) => UserEventsBloc( eventRepository: RepositoryProvider.of(context), - userId: bloc.currentProfile!.id, + userId: currentProfile.profile.id, )..add(SubscribeToEvents()), child: Builder( builder: (context) { diff --git a/packages/app/lib/event/widgets/map/journey_map.dart b/packages/app/lib/event/widgets/map/journey_map.dart index 7bebe871..668e41d8 100644 --- a/packages/app/lib/event/widgets/map/journey_map.dart +++ b/packages/app/lib/event/widgets/map/journey_map.dart @@ -259,11 +259,9 @@ class _JourneyMapState extends State { PointAnnotationManager pointManager, UserPositionsState userPositionsState, ) async { - final profileBloc = BlocProvider.of(context); final colorScheme = Theme.of(context).colorScheme; final options = await Future.wait( userPositionsState.userPositions.map((position) async { - final user = profileBloc.getProfileById(position.userId); final icon = await rootBundle .load("assets/images/placeholder_profile_picture.jpg"); return PointAnnotationOptions( @@ -278,7 +276,6 @@ class _JourneyMapState extends State { iconAnchor: IconAnchor.BOTTOM, textAnchor: TextAnchor.TOP, textSize: 12, - textField: user?.username, textHaloWidth: 2, textHaloColor: colorScheme.primary.value, textColor: colorScheme.onPrimary.value, diff --git a/packages/app/lib/main.dart b/packages/app/lib/main.dart index 42d96b2d..883a9b44 100644 --- a/packages/app/lib/main.dart +++ b/packages/app/lib/main.dart @@ -170,8 +170,6 @@ class _MyAppState extends State { BlocProvider( lazy: false, create: (context) => ProfileBloc( - authRepository: - RepositoryProvider.of(context), authSessionRepository: RepositoryProvider.of(context), profileRepository: diff --git a/packages/app/lib/profile/bloc/profile_bloc/events/profile_event.dart b/packages/app/lib/profile/bloc/profile_bloc/events/profile_event.dart new file mode 100644 index 00000000..748a1a87 --- /dev/null +++ b/packages/app/lib/profile/bloc/profile_bloc/events/profile_event.dart @@ -0,0 +1,31 @@ +part of '../profile_bloc.dart'; + +@immutable +abstract class ProfileEvent { + const ProfileEvent(); +} + +class SubscribeToCurrentSessionChange extends ProfileEvent {} + +extension ProfileEventOperations on List { + int? elementIndex(T profileEvent) { + for (int i = 0; i < length; i++) { + if (profileEvent == this[i]) return i; + } + return null; + } + + copyUpdatedFromNullable(T? profileEvent) { + final copy = [...this]; + if (profileEvent == null) return copy; + + final alreadyExistingLoadEvent = elementIndex(profileEvent); + if (alreadyExistingLoadEvent is int) { + copy[alreadyExistingLoadEvent] = profileEvent; + } else { + copy.add(profileEvent); + } + + return copy; + } +} diff --git a/packages/app/lib/profile/bloc/profile_bloc/events/profile_load_event.dart b/packages/app/lib/profile/bloc/profile_bloc/events/profile_load_event.dart new file mode 100644 index 00000000..4838feba --- /dev/null +++ b/packages/app/lib/profile/bloc/profile_bloc/events/profile_load_event.dart @@ -0,0 +1,63 @@ +part of '../profile_bloc.dart'; + +abstract class ProfileLoadEvent extends ProfileEvent { + final AuthSession session; + + const ProfileLoadEvent({required this.session}) : super(); + + @override + bool operator ==(covariant ProfileLoadEvent other) { + return session == other.session; + } + + @override + int get hashCode => Object.hash(session, super.hashCode); +} + +class ProfileLoadingEvent extends ProfileLoadEvent { + const ProfileLoadingEvent({required super.session}); + + ProfileLoadSuccessEvent succeeded(Profile profile) => + ProfileLoadSuccessEvent(session: session, profile: profile); + + ProfileLoadErrorEvent failed(Error error) => + ProfileLoadErrorEvent(session: session, error: error); +} + +class ProfileLoadSuccessEvent extends ProfileLoadEvent { + final Profile profile; + + const ProfileLoadSuccessEvent({ + required super.session, + required this.profile, + }); +} + +class ProfileLoadErrorEvent extends ProfileLoadEvent { + final Error error; + + const ProfileLoadErrorEvent({ + required super.session, + required this.error, + }); +} + +extension ProfileLoadEventFactories on ProfileLoadEvent { + static ProfileLoadingEvent loading({ + required AuthSession session, + }) => + ProfileLoadingEvent(session: session); + + static ProfileLoadSuccessEvent success({ + required AuthSession session, + required Profile profile, + }) => + ProfileLoadSuccessEvent(session: session, profile: profile); + + static ProfileLoadErrorEvent error({ + required AuthSession session, + required Error error, + }) => + ProfileLoadErrorEvent(session: session, error: error); +} + diff --git a/packages/app/lib/profile/bloc/profile_bloc/events/user_load_event.dart b/packages/app/lib/profile/bloc/profile_bloc/events/user_load_event.dart new file mode 100644 index 00000000..50796d76 --- /dev/null +++ b/packages/app/lib/profile/bloc/profile_bloc/events/user_load_event.dart @@ -0,0 +1,83 @@ +part of '../profile_bloc.dart'; + +abstract class UserLoadEvent extends ProfileEvent { + final AuthSession observerSession; + final int id; + + const UserLoadEvent({required this.observerSession, required this.id}) + : super(); + + @override + bool operator ==(covariant UserLoadEvent other) { + return observerSession == other.observerSession && id == other.id; + } + + @override + int get hashCode => Object.hash(observerSession, id.hashCode); +} + +class UserLoadingEvent extends UserLoadEvent { + const UserLoadingEvent({required super.observerSession, required super.id}); + + UserLoadSuccessEvent succeeded(MinimalUser user) => UserLoadSuccessEvent( + observerSession: observerSession, + id: id, + user: user, + ); + + UserLoadErrorEvent failed(Error error) => UserLoadErrorEvent( + observerSession: observerSession, + id: id, + error: error, + ); +} + +class UserLoadSuccessEvent extends UserLoadEvent { + final MinimalUser user; + + const UserLoadSuccessEvent({ + required super.observerSession, + required super.id, + required this.user, + }); +} + +class UserLoadErrorEvent extends UserLoadEvent { + final Error error; + + const UserLoadErrorEvent({ + required super.observerSession, + required super.id, + required this.error, + }); +} + +extension UserLoadEventFactories on UserLoadEvent { + static UserLoadingEvent loading({ + required AuthSession observerSession, + required int id, + }) => + UserLoadingEvent(observerSession: observerSession, id: id); + + static UserLoadSuccessEvent success({ + required AuthSession observerSession, + required int id, + required MinimalUser user, + }) => + UserLoadSuccessEvent( + observerSession: observerSession, + id: id, + user: user, + ); + + static UserLoadErrorEvent error({ + required AuthSession observerSession, + required int id, + required Error error, + }) => + UserLoadErrorEvent( + observerSession: observerSession, + id: id, + error: error, + ); +} diff --git a/packages/app/lib/profile/bloc/profile_bloc/profile_bloc.dart b/packages/app/lib/profile/bloc/profile_bloc/profile_bloc.dart index b62a18db..20c80b81 100644 --- a/packages/app/lib/profile/bloc/profile_bloc/profile_bloc.dart +++ b/packages/app/lib/profile/bloc/profile_bloc/profile_bloc.dart @@ -1,6 +1,5 @@ import 'package:bloc/bloc.dart'; import 'package:flutter/material.dart'; -import 'package:hollybike/auth/services/auth_repository.dart'; import 'package:hollybike/auth/services/auth_session_repository.dart'; import 'package:hollybike/auth/types/auth_session.dart'; import 'package:hollybike/profile/types/profile.dart'; @@ -8,53 +7,98 @@ import 'package:hollybike/user/types/minimal_user.dart'; import '../../services/profile_repository.dart'; -part 'profile_event.dart'; +part 'events/profile_event.dart'; + +part 'events/profile_load_event.dart'; + +part 'events/user_load_event.dart'; + part 'profile_state.dart'; class ProfileBloc extends Bloc { final ProfileRepository profileRepository; - final AuthRepository authRepository; final AuthSessionRepository authSessionRepository; - bool _loading = false; + ProfileLoadEvent? get currentProfile { + final session = state.currentSession; + return session == null ? null : getProfile(session); + } - Profile? get currentProfile { - final profile = state.currentProfile; - if (profile == null && state.currentSession != null && !_loading) { - _loading = true; - add(ProfileLoadBySession(session: state.currentSession as AuthSession)); + ProfileLoadEvent? getProfile(AuthSession session) { + try { + return state.profilesLoad + .firstWhere((loadEvent) => loadEvent.session == session); + } catch (_) { + final futureOrProfile = profileRepository.getProfile(session); + + if (futureOrProfile is Future) { + futureOrProfile.then((profile) { + add(ProfileLoadSuccessEvent(session: session, profile: profile)); + }, onError: (error) { + add(ProfileLoadErrorEvent(session: session, error: error)); + }); + add(ProfileLoadingEvent(session: session)); + } else { + add( + ProfileLoadSuccessEvent( + session: session, + profile: futureOrProfile, + ), + ); + } + return null; } - return profile; } - MinimalUser? getProfileById(int id) { + UserLoadEvent? getUserById(int id) { final currentSession = state.currentSession; if (currentSession == null) return null; - bool isSearchedProfile(MinimalUser profile) => profile.id == id; - try { - return state.sessionProfiles.values - .map((sessionProfile) => sessionProfile.toMinimalUser()) - .firstWhere( - isSearchedProfile, - orElse: () => - state.profiles[currentSession]!.firstWhere(isSearchedProfile), - ); + return state.usersLoad.firstWhere((loadEvent) => + loadEvent.id == id && loadEvent.observerSession == currentSession); } catch (_) { - add(ProfileLoadById(sessionSearching: currentSession, id: id)); + final futureOrUser = profileRepository.getUserById(id, currentSession); + + if (futureOrUser is Future) { + futureOrUser.then((user) { + add( + UserLoadSuccessEvent( + observerSession: currentSession, + id: id, + user: user, + ), + ); + }, onError: (error) { + add( + UserLoadErrorEvent( + observerSession: currentSession, + id: id, + error: error, + ), + ); + }); + add(UserLoadingEvent(observerSession: currentSession, id: id)); + } else { + add( + UserLoadSuccessEvent( + observerSession: currentSession, + id: id, + user: futureOrUser, + ), + ); + } return null; } } ProfileBloc({ required this.profileRepository, - required this.authRepository, required this.authSessionRepository, - }) : super(ProfileInitial()) { + }) : super(InitialProfileState()) { on(_onSubscribeToCurrentSessionChange); - on(_onProfileLoadBySession); - on(_onProfileLoadById); + on(_onProfileLoadEvent); + on(_onUserLoadEvent); } void _onSubscribeToCurrentSessionChange( @@ -64,43 +108,35 @@ class ProfileBloc extends Bloc { await emit.forEach( authSessionRepository.authSessionStream, onData: (session) { - return CurrentSessionChange( + return ChangedSessionProfileState( oldState: state, - session: session, + currentSession: session, ); }, ); } - void _onProfileLoadBySession( - ProfileLoadBySession event, Emitter emit) async { - final session = event.session; - - try { - final profile = await profileRepository.getSessionProfile(session); - - emit(SessionProfileSaving( + void _onProfileLoadEvent( + ProfileLoadEvent event, + Emitter emit, + ) { + emit( + UpdateLoadEventProfileState( oldState: state, - session: session, - profile: profile, - )); - - _loading = false; - } catch (_) {} + profileLoadEvent: event, + ), + ); } - void _onProfileLoadById( - ProfileLoadById event, + void _onUserLoadEvent( + UserLoadEvent event, Emitter emit, - ) async { - final profile = await profileRepository.getIdProfile( - event.id, + ) { + emit( + UpdateLoadEventProfileState( + oldState: state, + userLoadEvent: event, + ), ); - - emit(ProfileSaving( - oldState: state, - session: event.sessionSearching, - profile: profile, - )); } } diff --git a/packages/app/lib/profile/bloc/profile_bloc/profile_event.dart b/packages/app/lib/profile/bloc/profile_bloc/profile_event.dart deleted file mode 100644 index 13d512b5..00000000 --- a/packages/app/lib/profile/bloc/profile_bloc/profile_event.dart +++ /dev/null @@ -1,21 +0,0 @@ -part of 'profile_bloc.dart'; - -@immutable -abstract class ProfileEvent {} - -class ProfileLoadBySession extends ProfileEvent { - final AuthSession session; - - ProfileLoadBySession({ - required this.session, - }); -} - -class ProfileLoadById extends ProfileEvent { - final AuthSession sessionSearching; - final int id; - - ProfileLoadById({required this.sessionSearching, required this.id}); -} - -class SubscribeToCurrentSessionChange extends ProfileEvent {} diff --git a/packages/app/lib/profile/bloc/profile_bloc/profile_state.dart b/packages/app/lib/profile/bloc/profile_bloc/profile_state.dart index bd16ffe0..1c41f812 100644 --- a/packages/app/lib/profile/bloc/profile_bloc/profile_state.dart +++ b/packages/app/lib/profile/bloc/profile_bloc/profile_state.dart @@ -1,100 +1,49 @@ part of 'profile_bloc.dart'; @immutable -abstract class ProfileState { - final Map sessionProfiles; - final Map> profiles; +class ProfileState { + final List profilesLoad; + final List usersLoad; final AuthSession? currentSession; const ProfileState({ - required this.sessionProfiles, - required this.profiles, + required this.profilesLoad, + required this.usersLoad, required this.currentSession, }); - - Profile? get currentProfile => sessionProfiles[currentSession]; - - Profile? findSessionProfile(AuthSession session) { - if (sessionProfiles.isEmpty) return null; - - try { - return sessionProfiles.entries - .firstWhere( - (element) => - element.key.token == session.token && - element.key.host == session.host, - ) - .value; - } catch (_) { - return null; - } - } -} - -class ProfileInitial extends ProfileState { - ProfileInitial() - : super( - sessionProfiles: {}, - profiles: >{}, - currentSession: null, - ); } -class CurrentSessionChange extends ProfileState { - CurrentSessionChange({required ProfileState oldState, AuthSession? session}) +class InitialProfileState extends ProfileState { + InitialProfileState() : super( - sessionProfiles: oldState.sessionProfiles, - profiles: oldState.profiles, - currentSession: session, - ); + profilesLoad: [], + usersLoad: [], + currentSession: null, + ); } -class SessionProfileSaving extends ProfileState { - SessionProfileSaving({ +class ChangedSessionProfileState extends ProfileState { + ChangedSessionProfileState({ required ProfileState oldState, - required Profile profile, - required AuthSession session, + required super.currentSession, }) : super( - sessionProfiles: { - ...oldState.sessionProfiles, - ...{session: profile}, - }, - profiles: oldState.profiles, - currentSession: oldState.currentSession, - ); + profilesLoad: oldState.profilesLoad, + usersLoad: oldState.usersLoad, + ); } -class ProfileSaving extends ProfileState { - ProfileSaving({ +class UpdateLoadEventProfileState extends ProfileState { + UpdateLoadEventProfileState({ required ProfileState oldState, - required MinimalUser profile, - required AuthSession session, + ProfileLoadEvent? profileLoadEvent, + UserLoadEvent? userLoadEvent, }) : super( - sessionProfiles: oldState.sessionProfiles, - profiles: { - ...oldState.profiles, - ..._getNewSessionProfileList(oldState, session, profile), - }, - currentSession: oldState.currentSession, - ); - - static Map> _getNewSessionProfileList( - ProfileState oldState, - AuthSession session, - MinimalUser profile, - ) { - final oldSessionProfileList = oldState.profiles[session]; - if (oldSessionProfileList == null) { - return { - session: [profile], - }; - } - - return { - session: [ - ...oldSessionProfileList, - profile, - ], - }; - } + profilesLoad: oldState.profilesLoad.copyUpdatedFromNullable( + profileLoadEvent, + ), + usersLoad: oldState.usersLoad.copyUpdatedFromNullable( + userLoadEvent, + ), + currentSession: oldState.currentSession, + ); } diff --git a/packages/app/lib/profile/screens/me_screen.dart b/packages/app/lib/profile/screens/me_screen.dart index 8090aae2..2abdd4a2 100644 --- a/packages/app/lib/profile/screens/me_screen.dart +++ b/packages/app/lib/profile/screens/me_screen.dart @@ -27,10 +27,21 @@ class MeScreen extends StatelessWidget { title: const TopBarTitle("Mon profil"), ), body: BlocProvidedBuilder( - builder: (context, bloc, state) => ProfilePage( - profile: bloc.currentProfile?.toMinimalUser(), - association: bloc.currentProfile?.association, - ), + builder: (context, bloc, state) { + final currentProfile = bloc.currentProfile; + + if (currentProfile is ProfileLoadSuccessEvent) { + return ProfilePage( + profile: currentProfile.profile.toMinimalUser(), + association: currentProfile.profile.association, + ); + } + + return const ProfilePage( + profile: null, + association: null, + ); + }, ), ); } diff --git a/packages/app/lib/profile/screens/profile_screen.dart b/packages/app/lib/profile/screens/profile_screen.dart index e8abcdd5..61f7a2de 100644 --- a/packages/app/lib/profile/screens/profile_screen.dart +++ b/packages/app/lib/profile/screens/profile_screen.dart @@ -10,9 +10,9 @@ import '../widgets/profile_page/profile_page.dart'; @RoutePage() class ProfileScreen extends StatelessWidget { - final String? id; + final String? urlId; - const ProfileScreen({super.key, @PathParam('id') this.id}); + const ProfileScreen({super.key, @PathParam('id') this.urlId}); @override Widget build(BuildContext context) { @@ -24,16 +24,37 @@ class ProfileScreen extends StatelessWidget { ), ), body: BlocProvidedBuilder( - builder: (context, bloc, state) => ProfilePage( - id: id == null ? null : int.parse(id as String), - profile: id == null - ? null - : bloc.getProfileById( - int.parse(id as String), - ), - association: bloc.currentProfile?.association, - ), + builder: (context, bloc, state) { + try { + return buildProfilePage(context, bloc, state); + } catch (_) { + return const ProfilePage( + profile: null, + association: null, + ); + } + }, ), ); } + + Widget buildProfilePage( + BuildContext context, + ProfileBloc bloc, + ProfileState state, + ) { + final id = urlId == null ? int.parse(urlId as String) : null; + if (id == null) throw Error(); + + final currentProfile = bloc.currentProfile; + final user = bloc.getUserById(id); + if (user is! UserLoadSuccessEvent || + currentProfile is! ProfileLoadSuccessEvent) throw Error(); + + return ProfilePage( + id: id, + profile: user.user, + association: currentProfile.profile.association, + ); + } } diff --git a/packages/app/lib/profile/services/profile_api.dart b/packages/app/lib/profile/services/profile_api.dart index bad5248a..c812c395 100644 --- a/packages/app/lib/profile/services/profile_api.dart +++ b/packages/app/lib/profile/services/profile_api.dart @@ -11,20 +11,17 @@ class ProfileApi { ProfileApi({required this.client}); - Future getSessionProfile(AuthSession session) async { - final AuthSession(:host, :token) = session; - + Future getProfile(AuthSession profileSession) async { + final AuthSession(:host, :token) = profileSession; final response = await client.dio.get("$host/api/users/me", options: Options( headers: {'Authorization': "Bearer $token"}, )); - return Profile.fromJson(response.data); } - Future getIdProfile(int id) async { - final response = await client.dio.get("/profiles/$id"); - + Future getUserById(int userId) async { + final response = await client.dio.get("/profiles/$userId"); return MinimalUser.fromJson(response.data); } @@ -42,7 +39,6 @@ class ProfileApi { "query": query, }, ); - return PaginatedList.fromJson(response.data, MinimalUser.fromJson); } } diff --git a/packages/app/lib/profile/services/profile_repository.dart b/packages/app/lib/profile/services/profile_repository.dart index 62b02eb8..f9f119e0 100644 --- a/packages/app/lib/profile/services/profile_repository.dart +++ b/packages/app/lib/profile/services/profile_repository.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:hollybike/auth/types/auth_session.dart'; import 'package:hollybike/profile/services/profile_api.dart'; import 'package:hollybike/shared/types/paginated_list.dart'; @@ -6,18 +8,37 @@ import 'package:hollybike/user/types/minimal_user.dart'; import '../types/profile.dart'; class ProfileRepository { + final Map profiles; + final Map> users; final ProfileApi profileApi; ProfileRepository({ required this.profileApi, - }); + }) : profiles = {}, + users = {}; - Future getSessionProfile(AuthSession session) async { - return profileApi.getSessionProfile(session); + FutureOr getProfile(AuthSession session) async { + final cachedProfile = profiles[session]; + if (cachedProfile is Profile) return cachedProfile; + final profile = await profileApi.getProfile(session); + profiles[session] = profile; + return profile; } - Future getIdProfile(int id) async { - return profileApi.getIdProfile(id); + FutureOr getUserById(int id, AuthSession currentSession) async { + try { + bool isSearchedProfile(MinimalUser profile) => profile.id == id; + return profiles.values + .map((sessionProfile) => sessionProfile.toMinimalUser()) + .firstWhere( + isSearchedProfile, + orElse: () => users[currentSession]!.firstWhere(isSearchedProfile), + ); + } catch (_) { + final user = await profileApi.getUserById(id); + users[currentSession] = [...?users[currentSession], user]; + return user; + } } Future> searchProfiles( diff --git a/packages/app/lib/profile/widgets/profile_bottom_bar_button.dart b/packages/app/lib/profile/widgets/profile_bottom_bar_button.dart index d8533f45..42c2d4a0 100644 --- a/packages/app/lib/profile/widgets/profile_bottom_bar_button.dart +++ b/packages/app/lib/profile/widgets/profile_bottom_bar_button.dart @@ -18,9 +18,9 @@ class ProfileBottomBarButton extends StatelessWidget { color: Theme.of(context).colorScheme.onPrimary, shape: BoxShape.circle, ), - child: _renderProfilePicture(), + child: _renderProfilePicture(context), ), - icon: _renderProfilePicture(), + icon: _renderProfilePicture(context), label: 'Profile', ); } @@ -34,20 +34,30 @@ class ProfileBottomBarButton extends StatelessWidget { ); } - Widget _renderProfilePicture() { - return BlocProvidedBuilder( - builder: (context, bloc, state) { - final currentProfile = bloc.currentProfile; - return GestureDetector( - onLongPress: () => _handleLongPress(context), - child: UserProfilePicture( - url: currentProfile?.profilePicture, + Widget _renderProfilePicture(BuildContext context) { + return GestureDetector( + onLongPress: () => _handleLongPress(context), + child: BlocProvidedBuilder( + builder: (context, bloc, state) { + final currentProfile = bloc.currentProfile; + + if (currentProfile is ProfileLoadSuccessEvent) { + return UserProfilePicture( + url: currentProfile.profile.profilePicture, + radius: 12, + isLoading: false, + userId: currentProfile.profile.id, + ); + } + + return const UserProfilePicture( + url: null, radius: 12, - isLoading: currentProfile == null, - userId: currentProfile?.id, - ), - ); - }, + isLoading: true, + userId: null, + ); + }, + ), ); } } diff --git a/packages/app/lib/profile/widgets/profile_modal/profile_modal_list.dart b/packages/app/lib/profile/widgets/profile_modal/profile_modal_list.dart index 7ebf8e57..c523bbdf 100644 --- a/packages/app/lib/profile/widgets/profile_modal/profile_modal_list.dart +++ b/packages/app/lib/profile/widgets/profile_modal/profile_modal_list.dart @@ -65,7 +65,7 @@ class ProfileModalList extends StatelessWidget { bool isCurrentSession = session.getIndexInList(sessions) == 0; return AsyncRenderer( future: RepositoryProvider.of(context) - .getSessionProfile(session), + .getProfile(session), builder: (profile) => ProfileCard( session: session, profile: profile, diff --git a/packages/app/lib/search/widgets/search_profile_card/search_profile_card.dart b/packages/app/lib/search/widgets/search_profile_card/search_profile_card.dart index 3392b0bb..bf189c46 100644 --- a/packages/app/lib/search/widgets/search_profile_card/search_profile_card.dart +++ b/packages/app/lib/search/widgets/search_profile_card/search_profile_card.dart @@ -55,7 +55,7 @@ class SearchProfileCard extends StatelessWidget { Future.delayed( const Duration(milliseconds: 200), () { - context.router.push(ProfileRoute(id: "${profile.id}")); + context.router.push(ProfileRoute(urlId: "${profile.id}")); }, ); } From cbd760f8fb5b8742df3de1dfd96f3e31146fed5e Mon Sep 17 00:00:00 2001 From: enzo soares Date: Thu, 11 Jul 2024 16:12:17 +0200 Subject: [PATCH 2/3] Rebase fixes --- packages/app/lib/app/app_router.gr.dart | 271 +++++++++++------- .../event_participation_journey_modal.dart | 17 +- 2 files changed, 177 insertions(+), 111 deletions(-) diff --git a/packages/app/lib/app/app_router.gr.dart b/packages/app/lib/app/app_router.gr.dart index df44b6d7..4df187aa 100644 --- a/packages/app/lib/app/app_router.gr.dart +++ b/packages/app/lib/app/app_router.gr.dart @@ -8,38 +8,41 @@ // coverage:ignore-file // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:auto_route/auto_route.dart' as _i12; -import 'package:flutter/material.dart' as _i13; -import 'package:hollybike/auth/screens/login_screen.dart' as _i7; -import 'package:hollybike/auth/screens/signup_screen.dart' as _i11; +import 'dart:io' as _i19; + +import 'package:auto_route/auto_route.dart' as _i13; +import 'package:flutter/material.dart' as _i14; +import 'package:hollybike/auth/screens/login_screen.dart' as _i8; +import 'package:hollybike/auth/screens/signup_screen.dart' as _i12; import 'package:hollybike/event/screens/event_details_screen.dart' as _i2; import 'package:hollybike/event/screens/events_screen.dart' as _i4; import 'package:hollybike/event/screens/participations/event_candidates_screen.dart' as _i1; import 'package:hollybike/event/screens/participations/event_participations_screen.dart' as _i3; -import 'package:hollybike/event/types/event_details.dart' as _i15; -import 'package:hollybike/event/types/minimal_event.dart' as _i14; +import 'package:hollybike/event/types/event_details.dart' as _i16; +import 'package:hollybike/event/types/minimal_event.dart' as _i15; import 'package:hollybike/event/types/participation/event_participation.dart' - as _i16; -import 'package:hollybike/image/bloc/image_list_bloc.dart' as _i17; + as _i17; +import 'package:hollybike/image/bloc/image_list_bloc.dart' as _i18; import 'package:hollybike/image/screens/image_gallery_page_view_screen.dart' as _i5; -import 'package:hollybike/profile/screens/me_screen.dart' as _i8; -import 'package:hollybike/profile/screens/profile_screen.dart' as _i9; -import 'package:hollybike/search/screens/search_screen.dart' as _i10; -import 'package:hollybike/shared/routes/loading_route.dart' as _i6; +import 'package:hollybike/journey/screen/import_gpx_tool_screen.dart' as _i6; +import 'package:hollybike/profile/screens/me_screen.dart' as _i9; +import 'package:hollybike/profile/screens/profile_screen.dart' as _i10; +import 'package:hollybike/search/screens/search_screen.dart' as _i11; +import 'package:hollybike/shared/routes/loading_route.dart' as _i7; -abstract class $AppRouter extends _i12.RootStackRouter { +abstract class $AppRouter extends _i13.RootStackRouter { $AppRouter({super.navigatorKey}); @override - final Map pagesMap = { + final Map pagesMap = { EventCandidatesRoute.name: (routeData) { final args = routeData.argsAs(); - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i12.WrappedRoute( + child: _i13.WrappedRoute( child: _i1.EventCandidatesScreen( key: args.key, eventId: args.eventId, @@ -48,9 +51,9 @@ abstract class $AppRouter extends _i12.RootStackRouter { }, EventDetailsRoute.name: (routeData) { final args = routeData.argsAs(); - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i12.WrappedRoute( + child: _i13.WrappedRoute( child: _i2.EventDetailsScreen( key: args.key, event: args.event, @@ -61,9 +64,9 @@ abstract class $AppRouter extends _i12.RootStackRouter { }, EventParticipationsRoute.name: (routeData) { final args = routeData.argsAs(); - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i12.WrappedRoute( + child: _i13.WrappedRoute( child: _i3.EventParticipationsScreen( key: args.key, eventDetails: args.eventDetails, @@ -72,16 +75,16 @@ abstract class $AppRouter extends _i12.RootStackRouter { ); }, EventsRoute.name: (routeData) { - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i12.WrappedRoute(child: const _i4.EventsScreen()), + child: _i13.WrappedRoute(child: const _i4.EventsScreen()), ); }, ImageGalleryViewRoute.name: (routeData) { final args = routeData.argsAs(); - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i12.WrappedRoute( + child: _i13.WrappedRoute( child: _i5.ImageGalleryViewScreen( key: args.key, imageIndex: args.imageIndex, @@ -91,17 +94,29 @@ abstract class $AppRouter extends _i12.RootStackRouter { )), ); }, + ImportGpxToolRoute.name: (routeData) { + final args = routeData.argsAs(); + return _i13.AutoRoutePage( + routeData: routeData, + child: _i6.ImportGpxToolScreen( + key: args.key, + url: args.url, + onGpxDownloaded: args.onGpxDownloaded, + onClose: args.onClose, + ), + ); + }, LoadingRoute.name: (routeData) { - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: const _i6.LoadingRoute(), + child: const _i7.LoadingRoute(), ); }, LoginRoute.name: (routeData) { final args = routeData.argsAs(); - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i7.LoginScreen( + child: _i8.LoginScreen( key: args.key, onAuthSuccess: args.onAuthSuccess, canPop: args.canPop, @@ -109,35 +124,35 @@ abstract class $AppRouter extends _i12.RootStackRouter { ); }, MeRoute.name: (routeData) { - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: const _i8.MeScreen(), + child: const _i9.MeScreen(), ); }, ProfileRoute.name: (routeData) { final pathParams = routeData.inheritedPathParams; final args = routeData.argsAs( orElse: () => ProfileRouteArgs(urlId: pathParams.optString('id'))); - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i9.ProfileScreen( + child: _i10.ProfileScreen( key: args.key, urlId: args.urlId, ), ); }, SearchRoute.name: (routeData) { - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: const _i10.SearchScreen(), + child: const _i11.SearchScreen(), ); }, SignupRoute.name: (routeData) { final args = routeData.argsAs( orElse: () => const SignupRouteArgs()); - return _i12.AutoRoutePage( + return _i13.AutoRoutePage( routeData: routeData, - child: _i11.SignupScreen( + child: _i12.SignupScreen( key: args.key, onAuthSuccess: args.onAuthSuccess, canPop: args.canPop, @@ -150,11 +165,11 @@ abstract class $AppRouter extends _i12.RootStackRouter { /// generated route for /// [_i1.EventCandidatesScreen] class EventCandidatesRoute - extends _i12.PageRouteInfo { + extends _i13.PageRouteInfo { EventCandidatesRoute({ - _i13.Key? key, + _i14.Key? key, required int eventId, - List<_i12.PageRouteInfo>? children, + List<_i13.PageRouteInfo>? children, }) : super( EventCandidatesRoute.name, args: EventCandidatesRouteArgs( @@ -166,8 +181,8 @@ class EventCandidatesRoute static const String name = 'EventCandidatesRoute'; - static const _i12.PageInfo page = - _i12.PageInfo(name); + static const _i13.PageInfo page = + _i13.PageInfo(name); } class EventCandidatesRouteArgs { @@ -176,7 +191,7 @@ class EventCandidatesRouteArgs { required this.eventId, }); - final _i13.Key? key; + final _i14.Key? key; final int eventId; @@ -188,13 +203,13 @@ class EventCandidatesRouteArgs { /// generated route for /// [_i2.EventDetailsScreen] -class EventDetailsRoute extends _i12.PageRouteInfo { +class EventDetailsRoute extends _i13.PageRouteInfo { EventDetailsRoute({ - _i13.Key? key, - required _i14.MinimalEvent event, + _i14.Key? key, + required _i15.MinimalEvent event, bool animate = true, String uniqueKey = "default", - List<_i12.PageRouteInfo>? children, + List<_i13.PageRouteInfo>? children, }) : super( EventDetailsRoute.name, args: EventDetailsRouteArgs( @@ -208,8 +223,8 @@ class EventDetailsRoute extends _i12.PageRouteInfo { static const String name = 'EventDetailsRoute'; - static const _i12.PageInfo page = - _i12.PageInfo(name); + static const _i13.PageInfo page = + _i13.PageInfo(name); } class EventDetailsRouteArgs { @@ -220,9 +235,9 @@ class EventDetailsRouteArgs { this.uniqueKey = "default", }); - final _i13.Key? key; + final _i14.Key? key; - final _i14.MinimalEvent event; + final _i15.MinimalEvent event; final bool animate; @@ -237,12 +252,12 @@ class EventDetailsRouteArgs { /// generated route for /// [_i3.EventParticipationsScreen] class EventParticipationsRoute - extends _i12.PageRouteInfo { + extends _i13.PageRouteInfo { EventParticipationsRoute({ - _i13.Key? key, - required _i15.EventDetails eventDetails, - required List<_i16.EventParticipation> participationPreview, - List<_i12.PageRouteInfo>? children, + _i14.Key? key, + required _i16.EventDetails eventDetails, + required List<_i17.EventParticipation> participationPreview, + List<_i13.PageRouteInfo>? children, }) : super( EventParticipationsRoute.name, args: EventParticipationsRouteArgs( @@ -255,8 +270,8 @@ class EventParticipationsRoute static const String name = 'EventParticipationsRoute'; - static const _i12.PageInfo page = - _i12.PageInfo(name); + static const _i13.PageInfo page = + _i13.PageInfo(name); } class EventParticipationsRouteArgs { @@ -266,11 +281,11 @@ class EventParticipationsRouteArgs { required this.participationPreview, }); - final _i13.Key? key; + final _i14.Key? key; - final _i15.EventDetails eventDetails; + final _i16.EventDetails eventDetails; - final List<_i16.EventParticipation> participationPreview; + final List<_i17.EventParticipation> participationPreview; @override String toString() { @@ -280,8 +295,8 @@ class EventParticipationsRouteArgs { /// generated route for /// [_i4.EventsScreen] -class EventsRoute extends _i12.PageRouteInfo { - const EventsRoute({List<_i12.PageRouteInfo>? children}) +class EventsRoute extends _i13.PageRouteInfo { + const EventsRoute({List<_i13.PageRouteInfo>? children}) : super( EventsRoute.name, initialChildren: children, @@ -289,20 +304,20 @@ class EventsRoute extends _i12.PageRouteInfo { static const String name = 'EventsRoute'; - static const _i12.PageInfo page = _i12.PageInfo(name); + static const _i13.PageInfo page = _i13.PageInfo(name); } /// generated route for /// [_i5.ImageGalleryViewScreen] class ImageGalleryViewRoute - extends _i12.PageRouteInfo { + extends _i13.PageRouteInfo { ImageGalleryViewRoute({ - _i13.Key? key, + _i14.Key? key, required int imageIndex, required void Function() onLoadNextPage, required void Function() onRefresh, - required _i17.ImageListBloc bloc, - List<_i12.PageRouteInfo>? children, + required _i18.ImageListBloc bloc, + List<_i13.PageRouteInfo>? children, }) : super( ImageGalleryViewRoute.name, args: ImageGalleryViewRouteArgs( @@ -317,8 +332,8 @@ class ImageGalleryViewRoute static const String name = 'ImageGalleryViewRoute'; - static const _i12.PageInfo page = - _i12.PageInfo(name); + static const _i13.PageInfo page = + _i13.PageInfo(name); } class ImageGalleryViewRouteArgs { @@ -330,7 +345,7 @@ class ImageGalleryViewRouteArgs { required this.bloc, }); - final _i13.Key? key; + final _i14.Key? key; final int imageIndex; @@ -338,7 +353,7 @@ class ImageGalleryViewRouteArgs { final void Function() onRefresh; - final _i17.ImageListBloc bloc; + final _i18.ImageListBloc bloc; @override String toString() { @@ -347,9 +362,57 @@ class ImageGalleryViewRouteArgs { } /// generated route for -/// [_i6.LoadingRoute] -class LoadingRoute extends _i12.PageRouteInfo { - const LoadingRoute({List<_i12.PageRouteInfo>? children}) +/// [_i6.ImportGpxToolScreen] +class ImportGpxToolRoute extends _i13.PageRouteInfo { + ImportGpxToolRoute({ + _i14.Key? key, + required String url, + required void Function(_i19.File) onGpxDownloaded, + required void Function() onClose, + List<_i13.PageRouteInfo>? children, + }) : super( + ImportGpxToolRoute.name, + args: ImportGpxToolRouteArgs( + key: key, + url: url, + onGpxDownloaded: onGpxDownloaded, + onClose: onClose, + ), + initialChildren: children, + ); + + static const String name = 'ImportGpxToolRoute'; + + static const _i13.PageInfo page = + _i13.PageInfo(name); +} + +class ImportGpxToolRouteArgs { + const ImportGpxToolRouteArgs({ + this.key, + required this.url, + required this.onGpxDownloaded, + required this.onClose, + }); + + final _i14.Key? key; + + final String url; + + final void Function(_i19.File) onGpxDownloaded; + + final void Function() onClose; + + @override + String toString() { + return 'ImportGpxToolRouteArgs{key: $key, url: $url, onGpxDownloaded: $onGpxDownloaded, onClose: $onClose}'; + } +} + +/// generated route for +/// [_i7.LoadingRoute] +class LoadingRoute extends _i13.PageRouteInfo { + const LoadingRoute({List<_i13.PageRouteInfo>? children}) : super( LoadingRoute.name, initialChildren: children, @@ -357,17 +420,17 @@ class LoadingRoute extends _i12.PageRouteInfo { static const String name = 'LoadingRoute'; - static const _i12.PageInfo page = _i12.PageInfo(name); + static const _i13.PageInfo page = _i13.PageInfo(name); } /// generated route for -/// [_i7.LoginScreen] -class LoginRoute extends _i12.PageRouteInfo { +/// [_i8.LoginScreen] +class LoginRoute extends _i13.PageRouteInfo { LoginRoute({ - _i13.Key? key, + _i14.Key? key, required dynamic Function() onAuthSuccess, bool canPop = false, - List<_i12.PageRouteInfo>? children, + List<_i13.PageRouteInfo>? children, }) : super( LoginRoute.name, args: LoginRouteArgs( @@ -380,8 +443,8 @@ class LoginRoute extends _i12.PageRouteInfo { static const String name = 'LoginRoute'; - static const _i12.PageInfo page = - _i12.PageInfo(name); + static const _i13.PageInfo page = + _i13.PageInfo(name); } class LoginRouteArgs { @@ -391,7 +454,7 @@ class LoginRouteArgs { this.canPop = false, }); - final _i13.Key? key; + final _i14.Key? key; final dynamic Function() onAuthSuccess; @@ -404,9 +467,9 @@ class LoginRouteArgs { } /// generated route for -/// [_i8.MeScreen] -class MeRoute extends _i12.PageRouteInfo { - const MeRoute({List<_i12.PageRouteInfo>? children}) +/// [_i9.MeScreen] +class MeRoute extends _i13.PageRouteInfo { + const MeRoute({List<_i13.PageRouteInfo>? children}) : super( MeRoute.name, initialChildren: children, @@ -414,16 +477,16 @@ class MeRoute extends _i12.PageRouteInfo { static const String name = 'MeRoute'; - static const _i12.PageInfo page = _i12.PageInfo(name); + static const _i13.PageInfo page = _i13.PageInfo(name); } /// generated route for -/// [_i9.ProfileScreen] -class ProfileRoute extends _i12.PageRouteInfo { +/// [_i10.ProfileScreen] +class ProfileRoute extends _i13.PageRouteInfo { ProfileRoute({ - _i13.Key? key, + _i14.Key? key, String? urlId, - List<_i12.PageRouteInfo>? children, + List<_i13.PageRouteInfo>? children, }) : super( ProfileRoute.name, args: ProfileRouteArgs( @@ -436,8 +499,8 @@ class ProfileRoute extends _i12.PageRouteInfo { static const String name = 'ProfileRoute'; - static const _i12.PageInfo page = - _i12.PageInfo(name); + static const _i13.PageInfo page = + _i13.PageInfo(name); } class ProfileRouteArgs { @@ -446,7 +509,7 @@ class ProfileRouteArgs { this.urlId, }); - final _i13.Key? key; + final _i14.Key? key; final String? urlId; @@ -457,9 +520,9 @@ class ProfileRouteArgs { } /// generated route for -/// [_i10.SearchScreen] -class SearchRoute extends _i12.PageRouteInfo { - const SearchRoute({List<_i12.PageRouteInfo>? children}) +/// [_i11.SearchScreen] +class SearchRoute extends _i13.PageRouteInfo { + const SearchRoute({List<_i13.PageRouteInfo>? children}) : super( SearchRoute.name, initialChildren: children, @@ -467,17 +530,17 @@ class SearchRoute extends _i12.PageRouteInfo { static const String name = 'SearchRoute'; - static const _i12.PageInfo page = _i12.PageInfo(name); + static const _i13.PageInfo page = _i13.PageInfo(name); } /// generated route for -/// [_i11.SignupScreen] -class SignupRoute extends _i12.PageRouteInfo { +/// [_i12.SignupScreen] +class SignupRoute extends _i13.PageRouteInfo { SignupRoute({ - _i13.Key? key, + _i14.Key? key, dynamic Function()? onAuthSuccess, bool canPop = false, - List<_i12.PageRouteInfo>? children, + List<_i13.PageRouteInfo>? children, }) : super( SignupRoute.name, args: SignupRouteArgs( @@ -490,8 +553,8 @@ class SignupRoute extends _i12.PageRouteInfo { static const String name = 'SignupRoute'; - static const _i12.PageInfo page = - _i12.PageInfo(name); + static const _i13.PageInfo page = + _i13.PageInfo(name); } class SignupRouteArgs { @@ -501,7 +564,7 @@ class SignupRouteArgs { this.canPop = false, }); - final _i13.Key? key; + final _i14.Key? key; final dynamic Function()? onAuthSuccess; diff --git a/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart b/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart index d069e94d..8a0aef2a 100644 --- a/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart +++ b/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart @@ -5,6 +5,7 @@ import 'package:hollybike/profile/bloc/profile_bloc/profile_bloc.dart'; import 'package:hollybike/shared/utils/add_separators.dart'; import 'package:lottie/lottie.dart'; import '../../../shared/utils/dates.dart'; +import '../../../shared/widgets/bloc_provided_builder.dart'; import '../../../shared/widgets/gradient_progress_bar.dart'; enum JourneyModalAction { @@ -52,7 +53,8 @@ class _EventParticipationJourneyModalState }) / isBetterThan.length; - _betterThanCount = isBetterThan.values.where((element) => element == 100).length; + _betterThanCount = + isBetterThan.values.where((element) => element == 100).length; } @override @@ -66,10 +68,13 @@ class _EventParticipationJourneyModalState right: 16, ), child: SafeArea( - child: BlocBuilder( - builder: (context, state) { - final currentProfile = state.currentProfile; - final isCurrentUser = currentProfile?.id == widget.userId; + child: BlocProvidedBuilder( + builder: (context, bloc, state) { + final currentProfile = bloc.currentProfile; + final isCurrentUser = (currentProfile is ProfileLoadSuccessEvent + ? currentProfile.profile.id + : null) == + widget.userId; return Column( mainAxisSize: MainAxisSize.min, @@ -224,7 +229,6 @@ class _EventParticipationJourneyModalState ], ), ), - const SizedBox(height: 16), ]; } @@ -462,7 +466,6 @@ class _StatItem extends StatelessWidget { children: _getStats(context), ), ), - if (value == 100) Positioned( left: 9, From 3ca982745c07801851fa5607e9da355083d55a33 Mon Sep 17 00:00:00 2001 From: enzo soares Date: Thu, 11 Jul 2024 16:14:39 +0200 Subject: [PATCH 3/3] Fixing analyze --- packages/app/lib/event/widgets/map/journey_map.dart | 1 - .../participations/event_participation_journey_modal.dart | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/app/lib/event/widgets/map/journey_map.dart b/packages/app/lib/event/widgets/map/journey_map.dart index 668e41d8..e4ce220c 100644 --- a/packages/app/lib/event/widgets/map/journey_map.dart +++ b/packages/app/lib/event/widgets/map/journey_map.dart @@ -13,7 +13,6 @@ import 'package:hollybike/shared/websocket/recieve/websocket_receive_position.da import 'package:hollybike/theme/bloc/theme_bloc.dart'; import 'package:http/http.dart' as http; import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart'; -import '../../../profile/bloc/profile_bloc/profile_bloc.dart'; import '../../../shared/utils/waiter.dart'; class JourneyMap extends StatefulWidget { diff --git a/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart b/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart index 8a0aef2a..a3bbfcbd 100644 --- a/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart +++ b/packages/app/lib/event/widgets/participations/event_participation_journey_modal.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:hollybike/journey/type/user_journey.dart'; import 'package:hollybike/profile/bloc/profile_bloc/profile_bloc.dart'; import 'package:hollybike/shared/utils/add_separators.dart';