Skip to content

Commit

Permalink
Merge pull request #400 from CollActionteam/fix/rc1.2.0-5
Browse files Browse the repository at this point in the history
Fix/rc1.2.0 5
  • Loading branch information
Xazin committed Apr 18, 2023
2 parents 1e9981e + 3eca475 commit 6ac2c69
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 107 deletions.
1 change: 1 addition & 0 deletions lib/application/auth/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
);
}

// TODO: Move to ProfileBloc
FutureOr<void> _mapUpdateProfilePhotoToState(
Emitter<AuthState> emit,
_UpdateProfilePhoto event,
Expand Down
8 changes: 5 additions & 3 deletions lib/application/user/profile/profile_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
});

on<EditProfilePic>((event, emit) {
emit(state.copyWith(isPicEditing: true));
emit(state.copyWith(isPicEditing: true, didPicSaveFail: false));
});

on<SaveBio>((event, emit) async {
Expand All @@ -69,12 +69,14 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
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,
Expand Down
14 changes: 12 additions & 2 deletions lib/application/user/profile/profile_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,46 @@ 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({
UserProfile? userProfile,
bool? isPicEditing,
bool? isBioEditing,
bool? wasProfilePictureUpdated,
bool? didPicSaveFail,
}) {
return ProfileState(
userProfile: userProfile ?? this.userProfile,
isPicEditing: isPicEditing ?? this.isPicEditing,
isBioEditing: isBioEditing ?? this.isBioEditing,
wasProfilePictureUpdated:
wasProfilePictureUpdated ?? false, // Reset state implicitly
didPicSaveFail: didPicSaveFail ?? this.didPicSaveFail,
);
}

@override
List<Object?> get props =>
[userProfile, isPicEditing, isBioEditing, wasProfilePictureUpdated];
List<Object?> get props => [
userProfile,
isPicEditing,
isBioEditing,
wasProfilePictureUpdated,
didPicSaveFail
];
}
26 changes: 15 additions & 11 deletions lib/presentation/core/app_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ class AppWidget extends StatelessWidget {
return MultiBlocProvider(
providers: [
BlocProvider<AuthBloc>(
create: (_) => getIt<AuthBloc>()..add(AuthEvent.initial()),
create: (_) => getIt<AuthBloc>()..add(AuthEvent.authCheckRequested()),
),
BlocProvider<ProfileBloc>(
create: (_) => getIt<ProfileBloc>()..add(GetUserProfile()),
),
BlocProvider<ProfileTabBloc>(
create: (_) => getIt<ProfileTabBloc>()..add(FetchProfileTabInfo()),
)
BlocProvider<ProfileBloc>(create: (_) => getIt<ProfileBloc>()),
BlocProvider<ProfileTabBloc>(create: (_) => getIt<ProfileTabBloc>())
],
child: BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
BlocProvider.of<ProfileBloc>(context).add(GetUserProfile());
BlocProvider.of<ProfileTabBloc>(context).add(FetchProfileTabInfo());

state.whenOrNull(
state.maybeWhen(
authenticated: (_) {
BlocProvider.of<ProfileBloc>(context).add(GetUserProfile());
BlocProvider.of<ProfileTabBloc>(context)
.add(FetchProfileTabInfo());
},
loggedIn: (_) {
BlocProvider.of<ProfileBloc>(context).add(GetUserProfile());
BlocProvider.of<ProfileTabBloc>(context)
.add(FetchProfileTabInfo());
},
unauthenticated: () {
_appRouter.replaceAll([const UnauthenticatedRoute()]);
},
orElse: () {},
);
},
child: MaterialApp.router(
Expand Down
18 changes: 12 additions & 6 deletions lib/presentation/profile/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class _UserProfilePageState extends State<UserProfilePage> {
value: BlocProvider.of<ProfileBloc>(context),
child: BlocBuilder<ProfileBloc, ProfileState>(
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 ?? '');

Expand All @@ -55,12 +65,8 @@ class _UserProfilePageState extends State<UserProfilePage> {
).merge(
ButtonStyle(
elevation: MaterialStateProperty.resolveWith<double?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) {
return 5;
}
return 4;
},
(states) =>
states.contains(MaterialState.pressed) ? 5 : 4,
),
),
),
Expand Down
2 changes: 0 additions & 2 deletions lib/presentation/themes/themes.dart
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
12 changes: 0 additions & 12 deletions lib/widgetbook/app.dart

This file was deleted.

7 changes: 0 additions & 7 deletions lib/widgetbook/main.dart

This file was deleted.

13 changes: 0 additions & 13 deletions lib/widgetbook/usecases/expandable_text/expandable_text.dart

This file was deleted.

48 changes: 0 additions & 48 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6ac2c69

Please sign in to comment.