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/Core/theming/colors.dart';
  import 'package:tasky_app/features/home/logic/home_cubit.dart';
  import 'package:tasky_app/features/sign_up/logic/sign_up_cubit.dart';
  import '../../../../core/routing/routes.dart';
  import '../../../../core/theming/styles.dart';
  import '../../logic/sign_up_state.dart';
  
  class SignupBlocListener extends StatelessWidget {
    const SignupBlocListener({super.key});
  
    @override
    Widget build(BuildContext context) {
      return BlocListener<SignupCubit, SignupState>(
        listenWhen: (previous, current) =>
            current is SignupLoading ||
            current is SignupSuccess ||
            current is SignupError,
        listener: (context, state) {
          state.whenOrNull(
            signupLoading: () {
              showDialog(
                context: context,
                builder: (context) => const Center(
                  child: CircularProgressIndicator(
                    color: ColorsManager.mainColor,
                  ),
                ),
              );
            },
            signupSuccess: (signupResponse) {
              context.read<HomeCubit>().getTasksForFirstTime().then((_) {
                context.pushNamedAndRemoveUntil(
                  Routes.homeScreen,
                  predicate: (Route<dynamic> route) {
                    return false;
                  },
                );
              });
            },
            signupError: (error) {
              setupErrorState(context, error);
            },
          );
        },
        child: const SizedBox.shrink(),
      );
    }
  
    void showSuccessDialog(BuildContext context) {
      showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: const Text('Signup Successful'),
            content: const SingleChildScrollView(
              child: ListBody(
                children: <Widget>[
                  Text('Congratulations, you have signed up successfully!'),
                ],
              ),
            ),
            actions: <Widget>[
              TextButton(
                style: TextButton.styleFrom(
                  foregroundColor: Colors.white,
                  backgroundColor: ColorsManager.mainColor,
                  disabledForegroundColor: Colors.grey.withOpacity(0.38),
                ),
                onPressed: () {
                  context.pop();
                },
                child: const Text('Continue'),
              ),
            ],
          );
        },
      );
    }
  
    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,
              ),
            ),
          ],
        ),
      );
    }
  }
  