content: import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:tasky_app/Core/helpers/extensions.dart';
  import 'package:tasky_app/features/login/logic/cubit/login_cubit.dart';
  import 'package:tasky_app/features/login/logic/cubit/login_state.dart';
  import '../../../../core/routing/routes.dart';
  import '../../../../core/theming/colors.dart';
  import '../../../../core/theming/styles.dart';
  
  class LoginBlocListener extends StatelessWidget {
    const LoginBlocListener({super.key});
  
    @override
    Widget build(BuildContext context) {
      return BlocListener<LoginCubit, LoginState>(
        listenWhen: (previous, current) =>
            current is Loading || current is Success || current is Error,
        listener: (context, state) {
          state.whenOrNull(
            loading: () {
              showDialog(
                context: context,
                builder: (context) => const Center(
                  child: CircularProgressIndicator(
                    color: ColorsManager.mainColor,
                  ),
                ),
              );
            },
            success: (loginResponse) {
         
                     context.pushNamedAndRemoveUntil(
                              Routes.homeScreen,
                              predicate: (Route<dynamic> route) {
                             return false;
                              },
                            );
                  
  
             
            },
            error: (error) {
              setupErrorState(context, error);
            },
          );
        },
        child: const SizedBox.shrink(),
      );
    }
  
    void setupErrorState(BuildContext context, String error) {
      context.pop();
      showDialog(
        context: context,
        builder: (context) => AlertDialog(
          icon: const Icon(
            Icons.error,
            color: Colors.red,
            size: 32,
          ),
          content: Text(
            error,
            style: TextStyles.font15DarkBlueMedium,
          ),
          actions: [
            TextButton(
              onPressed: () {
                context.pop();
              },
              child: Text(
                'Got it',
                style: TextStyles.font14BlueSemiBold,
              ),
            ),
          ],
        ),
      );
    }
  }
  