Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve loaders #44

Merged
merged 7 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../../core/widgets/view_model/infinite_scroll_list_view_model.dart';

import '../../../../data/repositories/activity_repository_impl.dart';
import '../../../../domain/entities/activity.dart';
import '../../core/enums/infinite_scroll_list.enum.dart';
import '../../core/utils/activity_utils.dart';
import '../../core/widgets/view_model/infinite_scroll_list_view_model.dart';
import 'state/activity_item_like_state.dart';

/// Provider for the activity item like view model.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../../user/view_model/profile_picture_view_model.dart';
import '../../../my_activities/view_model/activity_list_view_model.dart';
import '../../../../data/repositories/activity_repository_impl.dart';
import '../../../../domain/entities/activity.dart';
import '../../../../main.dart';
Expand Down Expand Up @@ -37,6 +38,7 @@ class ActivityItemViewModel extends StateNotifier<ActivityItemState> {
/// Retrieves the details of an activity.
Future<Activity> getActivityDetails(Activity activity) async {
try {
ref.read(activityListViewModelProvider.notifier).setIsLoading(true);
final activityDetails = await ref
.read(activityRepositoryProvider)
.getActivityById(id: activity.id);
Expand All @@ -49,6 +51,10 @@ class ActivityItemViewModel extends StateNotifier<ActivityItemState> {

/// Navigates to the activity details screen.
void goToActivity(Activity activityDetails) {
Future.delayed(const Duration(milliseconds: 500), () {
ref.read(activityListViewModelProvider.notifier).setIsLoading(false);
});

navigatorKey.currentState?.push(
PageRouteBuilder(
transitionDuration: const Duration(milliseconds: 500),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../../user/view_model/profile_picture_view_model.dart';

import '../../../../domain/entities/activity.dart';
import '../../core/utils/color_utils.dart';
import '../../core/utils/ui_utils.dart';
import '../../core/utils/user_utils.dart';
import '../../user/view_model/profile_picture_view_model.dart';
import '../view_model/activity_item_view_model.dart';

class ActivityItemUserInformation extends HookConsumerWidget {
Expand Down
10 changes: 6 additions & 4 deletions lib/presentation/common/user/screens/profile_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../view_model/profile_picture_view_model.dart';

import '../../../../domain/entities/activity.dart';
import '../../../../domain/entities/enum/friend_request_status.dart';
Expand All @@ -10,6 +9,7 @@ import '../../activity/widgets/activity_list.dart';
import '../../core/enums/infinite_scroll_list.enum.dart';
import '../../core/utils/ui_utils.dart';
import '../../core/utils/user_utils.dart';
import '../view_model/profile_picture_view_model.dart';
import '../view_model/profile_view_model.dart';
import '../widgets/friend_request.dart';

Expand Down Expand Up @@ -47,7 +47,7 @@ class ProfileScreen extends HookConsumerWidget {
var activitiesStateProvider = ref.watch(activitiesDataFutureProvider(user));

return state.isLoading
? Center(child: UIUtils.loader)
? Expanded(child: Center(child: UIUtils.loader))
: Scaffold(
body: SafeArea(
child: Column(
Expand Down Expand Up @@ -93,7 +93,8 @@ class ProfileScreen extends HookConsumerWidget {
return widget;
},
loading: () {
return Center(child: UIUtils.loader);
return Expanded(
child: Center(child: UIUtils.loader));
},
error: (error, stackTrace) {
return Text('$error');
Expand Down Expand Up @@ -126,7 +127,8 @@ class ProfileScreen extends HookConsumerWidget {
provider.fetchActivities);
},
loading: () {
return Center(child: UIUtils.loader);
return Expanded(
child: Center(child: UIUtils.loader));
},
error: (error, stackTrace) {
return Text('$error');
Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/community/screens/community_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CommunityScreen extends HookConsumerWidget {
: Container();
},
loading: () {
return Center(child: UIUtils.loader);
return Expanded(child: Center(child: UIUtils.loader));
},
error: (error, stackTrace) {
return Text('$error');
Expand All @@ -134,7 +134,7 @@ class CommunityScreen extends HookConsumerWidget {
);
},
loading: () {
return Center(child: UIUtils.loader);
return Expanded(child: Center(child: UIUtils.loader));
},
error: (error, stackTrace) {
return Text('$error');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PendingRequestsScreen extends HookConsumerWidget {
ref.watch(pendingRequestsDataFutureProvider);

return state.isLoading
? Center(child: UIUtils.loader)
? Expanded(child: Center(child: UIUtils.loader))
: Scaffold(
body: SafeArea(
child: Column(children: [
Expand All @@ -46,7 +46,7 @@ class PendingRequestsScreen extends HookConsumerWidget {
);
},
loading: () {
return Center(child: UIUtils.loader);
return Expanded(child: Center(child: UIUtils.loader));
},
error: (error, stackTrace) {
return Text('$error');
Expand Down
26 changes: 14 additions & 12 deletions lib/presentation/my_activities/screens/activity_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,20 @@ class ActivityDetailsScreen extends HookConsumerWidget {
tooltip: 'Remove',
onPressed: () {
QuickAlert.show(
context: context,
type: QuickAlertType.confirm,
title: AppLocalizations.of(context)!
.ask_activity_removal,
confirmBtnText:
AppLocalizations.of(context)!.delete,
cancelBtnText: AppLocalizations.of(context)!.cancel,
confirmBtnColor: ColorUtils.red,
onCancelBtnTap: () => Navigator.of(context).pop(),
onConfirmBtnTap: () =>
provider.removeActivity(displayedActivity),
);
context: context,
type: QuickAlertType.confirm,
title: AppLocalizations.of(context)!
.ask_activity_removal,
confirmBtnText:
AppLocalizations.of(context)!.delete,
cancelBtnText:
AppLocalizations.of(context)!.cancel,
confirmBtnColor: ColorUtils.red,
onCancelBtnTap: () => Navigator.of(context).pop(),
onConfirmBtnTap: () {
Navigator.of(context).pop();
provider.removeActivity(displayedActivity);
});
},
icon: Icon(
Icons.delete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ActivityListScreen extends HookConsumerWidget {

return Scaffold(
body: isLoading
? Center(child: UIUtils.loader)
? Expanded(child: Center(child: UIUtils.loader))
: SafeArea(
child: Column(
children: [
Expand All @@ -41,7 +41,7 @@ class ActivityListScreen extends HookConsumerWidget {
);
},
loading: () {
return Center(child: UIUtils.loader);
return Expanded(child: Center(child: UIUtils.loader));
},
error: (error, stackTrace) {
return Text('$error');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class ActivityDetailsViewModel extends StateNotifier<ActivityDetailsState> {
ActivityUtils.updateActivity(
ref, activityWithoutLocations, ActivityUpdateActionEnum.remove);

navigatorKey.currentState?.pop();
navigatorKey.currentState?.pop();
ref.read(homeViewModelProvider.notifier).setCurrentIndex(Tabs.list.index);
navigatorKey.currentState?.pushReplacement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ class ActivityListViewModel extends StateNotifier<ActivityListState> {
),
);
}

void setIsLoading(bool isLoading) {
state = state.copyWith(isLoading: isLoading);
}
}
48 changes: 25 additions & 23 deletions lib/presentation/settings/screens/edit_password_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,32 @@ class EditPasswordScreen extends HookConsumerWidget {
],
),
),
floatingActionButton: Stack(
children: [
Positioned(
bottom: 16,
right: 80,
child: FloatingActionButton(
backgroundColor: ColorUtils.main,
elevation: 4.0,
child: Icon(
Icons.save,
color: ColorUtils.white,
),
onPressed: () {
provider.submitForm(context, formKey);
},
floatingActionButton: state.isEditing
? Container()
: Stack(
children: [
Positioned(
bottom: 16,
right: 80,
child: FloatingActionButton(
backgroundColor: ColorUtils.main,
elevation: 4.0,
child: Icon(
Icons.save,
color: ColorUtils.white,
),
onPressed: () {
provider.submitForm(context, formKey);
},
),
),
Positioned(
bottom: 16,
left: 80,
child: UIUtils.createBackButton(context),
),
],
),
),
Positioned(
bottom: 16,
left: 80,
child: UIUtils.createBackButton(context),
),
],
),
);
}
}
Loading
Loading