Skip to content

Commit

Permalink
improve loading activity
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCanape committed Feb 5, 2024
1 parent c36fd6c commit ccae6d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
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 @@ -69,4 +69,8 @@ class ActivityListViewModel extends StateNotifier<ActivityListState> {
),
);
}

void setIsLoading(bool isLoading) {
state = state.copyWith(isLoading: isLoading);
}
}

0 comments on commit ccae6d5

Please sign in to comment.