diff --git a/lib/application/auth/auth_bloc.dart b/lib/application/auth/auth_bloc.dart index fb746907..27daae42 100644 --- a/lib/application/auth/auth_bloc.dart +++ b/lib/application/auth/auth_bloc.dart @@ -78,6 +78,7 @@ class AuthBloc extends Bloc { ); } + // TODO: Move to ProfileBloc FutureOr _mapUpdateProfilePhotoToState( Emitter emit, _UpdateProfilePhoto event, diff --git a/lib/application/user/profile/profile_bloc.dart b/lib/application/user/profile/profile_bloc.dart index fe7ce549..a6b9f435 100644 --- a/lib/application/user/profile/profile_bloc.dart +++ b/lib/application/user/profile/profile_bloc.dart @@ -42,7 +42,7 @@ class ProfileBloc extends Bloc { }); on((event, emit) { - emit(state.copyWith(isPicEditing: true)); + emit(state.copyWith(isPicEditing: true, didPicSaveFail: false)); }); on((event, emit) async { @@ -69,12 +69,14 @@ class ProfileBloc extends Bloc { await _avatarRepository.uploadAvatar(event.image!); } - // TODO handle could not upload profile picture! final userOrFailure = await _profileRepository.getUserProfile(); emit( userOrFailure.fold( - (failure) => state.copyWith(isPicEditing: false), + (failure) => state.copyWith( + isPicEditing: false, + didPicSaveFail: true, + ), (userProfile) => state.copyWith( userProfile: userProfile, isPicEditing: false, diff --git a/lib/application/user/profile/profile_state.dart b/lib/application/user/profile/profile_state.dart index da4fbbd1..e664c8c9 100644 --- a/lib/application/user/profile/profile_state.dart +++ b/lib/application/user/profile/profile_state.dart @@ -6,18 +6,21 @@ class ProfileState extends Equatable { this.isPicEditing, this.isBioEditing, this.wasProfilePictureUpdated, + this.didPicSaveFail, }); final UserProfile? userProfile; final bool? isPicEditing; final bool? isBioEditing; final bool? wasProfilePictureUpdated; + final bool? didPicSaveFail; factory ProfileState.initial() => const ProfileState( userProfile: null, isPicEditing: false, isBioEditing: false, wasProfilePictureUpdated: false, + didPicSaveFail: false, ); ProfileState copyWith({ @@ -25,6 +28,7 @@ class ProfileState extends Equatable { bool? isPicEditing, bool? isBioEditing, bool? wasProfilePictureUpdated, + bool? didPicSaveFail, }) { return ProfileState( userProfile: userProfile ?? this.userProfile, @@ -32,10 +36,16 @@ class ProfileState extends Equatable { isBioEditing: isBioEditing ?? this.isBioEditing, wasProfilePictureUpdated: wasProfilePictureUpdated ?? false, // Reset state implicitly + didPicSaveFail: didPicSaveFail ?? this.didPicSaveFail, ); } @override - List get props => - [userProfile, isPicEditing, isBioEditing, wasProfilePictureUpdated]; + List get props => [ + userProfile, + isPicEditing, + isBioEditing, + wasProfilePictureUpdated, + didPicSaveFail + ]; } diff --git a/lib/presentation/core/app_widget.dart b/lib/presentation/core/app_widget.dart index db9b4925..c4222876 100644 --- a/lib/presentation/core/app_widget.dart +++ b/lib/presentation/core/app_widget.dart @@ -16,24 +16,28 @@ class AppWidget extends StatelessWidget { return MultiBlocProvider( providers: [ BlocProvider( - create: (_) => getIt()..add(AuthEvent.initial()), + create: (_) => getIt()..add(AuthEvent.authCheckRequested()), ), - BlocProvider( - create: (_) => getIt()..add(GetUserProfile()), - ), - BlocProvider( - create: (_) => getIt()..add(FetchProfileTabInfo()), - ) + BlocProvider(create: (_) => getIt()), + BlocProvider(create: (_) => getIt()) ], child: BlocListener( listener: (context, state) { - BlocProvider.of(context).add(GetUserProfile()); - BlocProvider.of(context).add(FetchProfileTabInfo()); - - state.whenOrNull( + state.maybeWhen( + authenticated: (_) { + BlocProvider.of(context).add(GetUserProfile()); + BlocProvider.of(context) + .add(FetchProfileTabInfo()); + }, + loggedIn: (_) { + BlocProvider.of(context).add(GetUserProfile()); + BlocProvider.of(context) + .add(FetchProfileTabInfo()); + }, unauthenticated: () { _appRouter.replaceAll([const UnauthenticatedRoute()]); }, + orElse: () {}, ); }, child: MaterialApp.router( diff --git a/lib/presentation/profile/profile_screen.dart b/lib/presentation/profile/profile_screen.dart index 4129265c..cf54a308 100644 --- a/lib/presentation/profile/profile_screen.dart +++ b/lib/presentation/profile/profile_screen.dart @@ -36,6 +36,16 @@ class _UserProfilePageState extends State { value: BlocProvider.of(context), child: BlocBuilder( builder: (context, state) { + if (state.didPicSaveFail ?? false) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text( + 'Something went wrong trying to save profile picture, please try again or reach out to us', + ), + ), + ); + } + bioController.value = TextEditingValue(text: state.userProfile?.profile.bio ?? ''); @@ -55,12 +65,8 @@ class _UserProfilePageState extends State { ).merge( ButtonStyle( elevation: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.pressed)) { - return 5; - } - return 4; - }, + (states) => + states.contains(MaterialState.pressed) ? 5 : 4, ), ), ), diff --git a/lib/presentation/themes/themes.dart b/lib/presentation/themes/themes.dart index 54a6fb5e..f39c36f0 100644 --- a/lib/presentation/themes/themes.dart +++ b/lib/presentation/themes/themes.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:widgetbook_annotation/widgetbook_annotation.dart'; import 'constants.dart'; -@WidgetbookTheme(name: 'Light') ThemeData lightTheme() { final theme = ThemeData.light(); diff --git a/lib/widgetbook/app.dart b/lib/widgetbook/app.dart deleted file mode 100644 index f41aa645..00000000 --- a/lib/widgetbook/app.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:widgetbook_annotation/widgetbook_annotation.dart'; - -@WidgetbookApp.material(name: 'CollAction Widgetbook') -class App extends StatelessWidget { - const App({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - return MaterialApp(); - } -} diff --git a/lib/widgetbook/main.dart b/lib/widgetbook/main.dart deleted file mode 100644 index ca985449..00000000 --- a/lib/widgetbook/main.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:flutter/material.dart'; - -import 'app.dart'; - -void main() async { - runApp(App()); -} diff --git a/lib/widgetbook/usecases/expandable_text/expandable_text.dart b/lib/widgetbook/usecases/expandable_text/expandable_text.dart deleted file mode 100644 index f93022f3..00000000 --- a/lib/widgetbook/usecases/expandable_text/expandable_text.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:widgetbook_annotation/widgetbook_annotation.dart'; - -import '../../../presentation/shared_widgets/expandable_text.dart'; - -@WidgetbookUseCase(name: 'ExpandableText', type: ExpandableText) -Widget expandableText(BuildContext context) { - return Center( - child: ExpandableText( - "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi blandit a mi non hendrerit. Aliquam posuere pellentesque sodales. Integer mattis enim id dictum lacinia. Nam consectetur ornare vulputate. Nam euismod pulvinar auctor. Etiam eleifend imperdiet ligula a commodo. Donec sed lacinia ipsum. \n\nUt ut metus at leo aliquam mattis ullamcorper vel metus. Nunc neque ipsum, interdum non lectus in, pharetra viverra sapien. Proin urna felis, vestibulum eu ligula vitae, sodales finibus massa. Integer laoreet nunc ac volutpat faucibus. Cras blandit id elit quis mollis. Aliquam semper elementum ultrices. Suspendisse fermentum luctus nulla, ac ullamcorper est. Praesent enim arcu, sodales nec semper et, ultricies at urna. Nunc in rutrum nibh, sed luctus quam.", - ), - ); -} diff --git a/pubspec.lock b/pubspec.lock index d1299a70..8d0387fe 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -313,14 +313,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.10.1" - device_frame: - dependency: transitive - description: - name: device_frame - sha256: afe76182aec178d171953d9b4a50a43c57c7cf3c77d8b09a48bf30c8fa04dd9d - url: "https://pub.dev" - source: hosted - version: "1.1.0" diff_match_patch: dependency: transitive description: @@ -600,14 +592,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" - go_router: - dependency: transitive - description: - name: go_router - sha256: "25ae21384b758eb80daff113fe8bfb785c2dd17b69fe4885008fe764b26fd1ca" - url: "https://pub.dev" - source: hosted - version: "3.1.1" graphs: dependency: transitive description: @@ -1501,38 +1485,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.1" - widgetbook: - dependency: "direct dev" - description: - name: widgetbook - sha256: c42a3d414d19c008d90f0b6df669c18bb151c5f3012ed073498d96cf133e9caf - url: "https://pub.dev" - source: hosted - version: "2.4.1" - widgetbook_annotation: - dependency: "direct main" - description: - name: widgetbook_annotation - sha256: "1f12e090865200191ab6b79b7ed4b108a191bf5de3140f92917c8c75e7e3f916" - url: "https://pub.dev" - source: hosted - version: "2.1.0" - widgetbook_generator: - dependency: "direct dev" - description: - name: widgetbook_generator - sha256: b6d00fef564fa5c0b98e26a72a27d52d03400c36409e56be25c0f09cfee3307b - url: "https://pub.dev" - source: hosted - version: "2.4.1" - widgetbook_models: - dependency: transitive - description: - name: widgetbook_models - sha256: "40899314ab0cce1a52b189ee12b79138ba59f445229f850fb326f579c8f63045" - url: "https://pub.dev" - source: hosted - version: "0.0.7" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ede9d741..49eec0f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -50,7 +50,6 @@ dependencies: shimmer: ^2.0.0 url_launcher: ^6.1.6 webview_flutter: ^4.0.2 - widgetbook_annotation: ^2.1.0 dev_dependencies: auto_route_generator: ^5.0.2 @@ -66,8 +65,6 @@ dev_dependencies: injectable_generator: ^2.1.3 json_serializable: ^6.5.3 lint: ^2.0.1 - widgetbook: ^2.4.1 - widgetbook_generator: ^2.4.1 flutter_icons: android: true