title: Unhandled error LateInitializationError: Field 'currentUser' has not been initialized. occurred in Instance of 'HomeBloc'
body: <p>so i do get this error : Unhandled Exception: Unhandled error LateInitializationError: Field 'currentUser' has not been initialized. occurred in Instance of 'HomeBloc'.</p>
  <blockquote>
  <p>E/flutter (11536): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)]
  Unhandled Exception: Unhandled error LateInitializationError: Field
  'currentUser' has not been initialized. occurred in Instance of
  'HomeBloc'. E/flutter (11536): #0      GlobalConstants.currentUser
  (package:fitness_flutter/core/const/global_constants.dart) E/flutter
  (11536): #1      DataService.getWorkoutsForUser
  (package:fitness_flutter/core/service/data_service.dart:9:43)
  E/flutter (11536): #2      HomeBloc.mapEventToState
  (package:fitness_flutter/screens/home/bloc/home_bloc.dart:27:36)
  E/flutter (11536): </p>
  </blockquote>
  <p>Line 9 from data_service.dart : <code>final currUserEmail = GlobalConstants.currentUser.mail;</code></p>
  <p>Line 27 from home_bloc.dart :  <code>workouts = await DataService.getWorkoutsForUser();</code></p>
  <p>This is my data_service.dart</p>
  <pre><code>import 'dart:convert';
  
  import 'package:fitness_flutter/core/const/global_constants.dart';
  import 'package:fitness_flutter/core/service/user_storage_service.dart';
  import 'package:fitness_flutter/data/workout_data.dart';
  
  class DataService {
    static Future&lt;List&lt;WorkoutData&gt;&gt; getWorkoutsForUser() async {
      final currUserEmail = GlobalConstants.currentUser.mail;
  
      // await UserStorageService.deleteSecureData('${currUserEmail}Workouts');
  
      final workoutsStr =
          await UserStorageService.readSecureData('${currUserEmail}Workouts');
      if (workoutsStr == null) return [];
      final decoded = (json.decode(workoutsStr) as List?) ?? [];
      final workouts = decoded.map((e) {
        final decodedE = json.decode(e) as Map&lt;String, dynamic&gt;?;
        return WorkoutData.fromJson(decodedE!);
      }).toList();
      GlobalConstants.workouts = workouts;
      return workouts;
    }
  
    static Future&lt;void&gt; saveWorkout(WorkoutData workout) async {
      final allWorkouts = await getWorkoutsForUser();
      final index = allWorkouts.indexWhere((w) =&gt; w.id == workout.id);
      if (index != -1) {
        allWorkouts[index] = workout;
      } else {
        allWorkouts.add(workout);
      }
      GlobalConstants.workouts = allWorkouts;
      final workoutsStr = allWorkouts.map((e) =&gt; e.toJsonString()).toList();
      final encoded = json.encode(workoutsStr);
      final currUserEmail = GlobalConstants.currentUser.mail;
      await UserStorageService.writeSecureData(
        '${currUserEmail}Workouts',
        encoded,
      );
    }
  }
  </code></pre>
  <p>This is my global_constants.dart :</p>
  <pre><code>import 'package:fitness_flutter/data/user_data.dart';
  import 'package:fitness_flutter/data/workout_data.dart';
  
  class GlobalConstants {
    static late UserData currentUser;
    static late List&lt;WorkoutData&gt; workouts;
  }
  </code></pre>
  <p>This is my home_bloc.dart</p>
  <pre><code>class HomeBloc extends Bloc&lt;HomeEvent, HomeState&gt; {
    HomeBloc() : super(HomeInitial());
  
    List&lt;WorkoutData&gt; workouts = &lt;WorkoutData&gt;[];
    List&lt;ExerciseData&gt; exercises = &lt;ExerciseData&gt;[];
    int timeSent = 0;
  
    @override
    Stream&lt;HomeState&gt; mapEventToState(
      HomeEvent event,
    ) async* {
      if (event is HomeInitialEvent) {
        workouts = await DataService.getWorkoutsForUser();
        yield WorkoutsGotState(workouts: workouts);
      } else if (event is ReloadImageEvent) {
        String? photoURL = await UserStorageService.readSecureData('image');
        if (photoURL == null) {
          photoURL = AuthService.auth.currentUser?.photoURL;
          photoURL != null
              ? await UserStorageService.writeSecureData('image', photoURL)
              : print('no image');
        }
        yield ReloadImageState(photoURL: photoURL);
      } else if (event is ReloadDisplayNameEvent) {
        final displayName = await UserStorageService.readSecureData('name');
        yield ReloadDisplayNameState(displayName: displayName);
      }
    }
  </code></pre>