title: Flutter Bloc State not updating when using copywith
body: <p>Outline:</p>
  <ol>
  <li>Navigate to profile page</li>
  <li>Pass in user id to fetch doc from firestore</li>
  <li>Pass the retrieved data to state.copyWith(data:data)</li>
  <li>yield a successful status and present ui</li>
  </ol>
  <p>My problem is that when i am using state.copyWith(data:data) the state is not being updated even though the data 100% exists as I can print it in console.</p>
  <p>Code:</p>
  <pre><code>UI: 
  class ProfileView extends StatelessWidget {
    final String uid;
  
    final UserRepository userRepository = UserRepository();
  
    ProfileView({required this.uid});
  
    @override
    Widget build(BuildContext context) {
      // Init repository
      return BlocProvider&lt;ProfileBloc&gt;(
          create: (context) =&gt; ProfileBloc(
              // Should be able to pull user repo from context
              userRepository: UserRepository(),
              isCurrentUser: UserRepository().isCurrentUser(uid))
            ..add(InitializeProfile(uid: uid)),
          // Get User Doc
          child: _profileView(context));
    }
  
    Widget _profileView(context) {
      return BlocListener&lt;ProfileBloc, ProfileState&gt;(
        listener: (context, state) {
          if (state.imageSourceActionSheetIsVisible) {
            _showImageSourceActionSheet(context);
          }
          final loadingStatus = state.loadingStatus;
          if (loadingStatus is LoadingFailed) {
            showSnackBar(context, state.loadingStatus.exception.toString());
          }
          if (loadingStatus is LoadingInProgress) {
            LoadingView();
          }
          if (loadingStatus is LoadingFailed) {
            LoadingFailedView(exception: loadingStatus.exception.toString());
          }
        },
        child: Scaffold(
          appBar: _appBar(),
          body: _profilePage(),
          bottomNavigationBar: bottomNavbar(context),
        ),
      );
    }
  
  
  
  BLoC:
  class ProfileBloc extends Bloc&lt;ProfileEvent, ProfileState&gt; {
    final bool isCurrentUser;
    final UserRepository userRepository;
    final _imagePicker = ImagePicker();
  
    ProfileBloc({
      required this.isCurrentUser,
      required this.userRepository,
    }) : super(ProfileState(
              isCurrentUser: isCurrentUser, loadingStatus: LoadingInProgress()));
  
    @override
    Stream&lt;ProfileState&gt; mapEventToState(
      ProfileEvent event,
    ) async* {
      if (event is InitializeProfile) {
        yield* _initProfile(uid: event.uid);
      }
    }
  
    Stream&lt;ProfileState&gt; _initProfile({required String uid}) async* {
      // Loading View
      yield state.copyWith(loadingStatus: LoadingInProgress());
      // Fetch profile data
      try {
        final snapshot = await userRepository.getUserDoc(uid);
        if (snapshot.exists) {
          final data = snapshot.data();
          print(data['fullName']);
  
          yield state.copyWith(
            fullName: data[&quot;fullName&quot;].toString(),
  
          );
          print(state.fullName);
          yield state.copyWith(loadingStatus: LoadingSuccess());
        }
   
        else {
          yield state.copyWith(
              loadingStatus: LoadingFailed(&quot;Profile Data Not present :(&quot;));
        }
      } catch (e) {
        print(e);
      }
    }
  
  
  State:
  part of 'profile_bloc.dart';
  
  class ProfileState {
    final bool isCurrentUser;
    final String? fullName;
    final LoadingStatus loadingStatus;
    bool imageSourceActionSheetIsVisible;
  
    ProfileState({
      required bool isCurrentUser,
      this.fullName,
      this.loadingStatus = const InitialLoadingStatus(),
      imageSourceActionSheetIsVisible = false,
    })  : this.isCurrentUser = isCurrentUser,
          this.imageSourceActionSheetIsVisible = imageSourceActionSheetIsVisible;
  
    ProfileState copyWith({
      bool? isCurrentUser,
      String? fullName,
      LoadingStatus? loadingStatus,
      bool? imageSourceActionSheetIsVisible,
  
    }) {
      print('State $fullName');
      print('State ${this.fullName}');
      return ProfileState(
        isCurrentUser: this.isCurrentUser,
        fullName: fullName ?? this.fullName,
        loadingStatus: loadingStatus ?? this.loadingStatus,
        imageSourceActionSheetIsVisible: imageSourceActionSheetIsVisible ??
            this.imageSourceActionSheetIsVisible,
      );
    }
  }
  
  
  </code></pre>
  <p>Newly updated Code implementing Bloc builder as opposed to listener as suggested</p>
  <pre><code>  Widget _profileView(context) {
      return BlocBuilder&lt;ProfileBloc, ProfileState&gt;(builder: (context, state) {
        final loadingStatus = state.loadingStatus;
        if (loadingStatus is LoadingInProgress) {
          return LoadingView();
        }
        if (loadingStatus is LoadingFailed) {
          return LoadingFailedView(exception: loadingStatus.exception.toString());
        }
        if (loadingStatus is LoadingSuccess) {
          return Scaffold(
            appBar: _appBar(),
            body: _profilePage(),
            bottomNavigationBar: bottomNavbar(context),
          );
        }
        return LoadingView();
      });
    }
  </code></pre>
  <p>This code remains stuck on loading screen, when i print out the various states it is registered as an event however the state prints out null after using copy with</p>
  <p>Thanks for the help</p>