From ccae6d59ad2b1847a1d4986cb922785b2c3546a4 Mon Sep 17 00:00:00 2001 From: Benjamin Canape Date: Mon, 5 Feb 2024 22:37:36 +0100 Subject: [PATCH] improve loading activity --- .../activity/view_model/activity_item_view_model.dart | 6 ++++++ .../my_activities/view_model/activity_list_view_model.dart | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/presentation/common/activity/view_model/activity_item_view_model.dart b/lib/presentation/common/activity/view_model/activity_item_view_model.dart index d348e450..10a778a7 100644 --- a/lib/presentation/common/activity/view_model/activity_item_view_model.dart +++ b/lib/presentation/common/activity/view_model/activity_item_view_model.dart @@ -2,6 +2,7 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import '../../../my_activities/view_model/activity_list_view_model.dart'; import '../../../../data/repositories/activity_repository_impl.dart'; import '../../../../domain/entities/activity.dart'; import '../../../../data/repositories/user_repository_impl.dart'; @@ -37,6 +38,7 @@ class ActivityItemViewModel extends StateNotifier { /// Retrieves the details of an activity. Future getActivityDetails(Activity activity) async { try { + ref.read(activityListViewModelProvider.notifier).setIsLoading(true); final activityDetails = await ref .read(activityRepositoryProvider) .getActivityById(id: activity.id); @@ -49,6 +51,10 @@ class ActivityItemViewModel extends StateNotifier { /// 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), diff --git a/lib/presentation/my_activities/view_model/activity_list_view_model.dart b/lib/presentation/my_activities/view_model/activity_list_view_model.dart index 92592e7f..63ed23fd 100644 --- a/lib/presentation/my_activities/view_model/activity_list_view_model.dart +++ b/lib/presentation/my_activities/view_model/activity_list_view_model.dart @@ -69,4 +69,8 @@ class ActivityListViewModel extends StateNotifier { ), ); } + + void setIsLoading(bool isLoading) { + state = state.copyWith(isLoading: isLoading); + } }