title: UI Not updating on bloc state change
body: <p>I am new in using bloc library with freezed package. I have a scenario where a list of objects is coming from API is displayed. Now the list tile has a Marked as Fav button and clicking upon it a event is trigged and fav bool is toggled and state is emitted.</p>
  <p>The Issue :
  The value of the object is changed but the UI is not updated accordingly.</p>
  <p>Main.dart</p>
  <pre class="lang-dart prettyprint-override"><code>
  import 'package:flutter/material.dart';
  import 'package:flutter_bloc/flutter_bloc.dart';
  import 'package:freezed_bloc_update/bloc/fakeapi_bloc.dart';
  
  void main() {
    runApp(
      BlocProvider(
        create: (context) =&gt; FakeapiBloc(),
        child: const MyApp(),
      ),
    );
  }
  
  class MyApp extends StatelessWidget {
    const MyApp({Key? key}) : super(key: key);
  
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const Scaffold(
          body: SafeArea(child: MyHomePage()),
        ),
      );
    }
  }
  
  class MyHomePage extends StatefulWidget {
    const MyHomePage({Key? key}) : super(key: key);
  
    @override
    State&lt;MyHomePage&gt; createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
    @override
    void initState() {
      context.read&lt;FakeapiBloc&gt;().add(const FakeapiEvent.loadData());
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return BlocBuilder&lt;FakeapiBloc, FakeapiState&gt;(
        builder: (context, state) {
          return state.map(
            inital: (_) =&gt; const Center(
              child: CircularProgressIndicator(),
            ),
            loading: (_) =&gt; const Center(
              child: CircularProgressIndicator(),
            ),
            loaded: (state) {
              return ListView.builder(itemBuilder: (ctx, pos) {
                return ListTile(
                  title: Text(state.posts[pos].title),
                  trailing: IconButton(
                    onPressed: () {
                      context
                          .read&lt;FakeapiBloc&gt;()
                          .add(FakeapiEvent.markedFav(pos: pos));
                    },
                    icon: Icon(state.posts[pos].isFav
                        ? Icons.favorite
                        : Icons.favorite_border_outlined),
                  ),
                );
              });
            },
            error: (_) =&gt; const Center(
              child: CircularProgressIndicator(),
            ),
          );
        },
      );
    }
  }
  
  </code></pre>
  <p>Post.dart</p>
  <pre class="lang-dart prettyprint-override"><code>
  import 'dart:convert';
  
  List&lt;Post&gt; postFromJson(String str) =&gt;
      List&lt;Post&gt;.from(json.decode(str).map((x) =&gt; Post.fromJson(x)));
  
  String postToJson(List&lt;Post&gt; data) =&gt;
      json.encode(List&lt;dynamic&gt;.from(data.map((x) =&gt; x.toJson())));
  
  class Post {
    Post({
      required this.userId,
      required this.id,
      required this.title,
      required this.body,
    });
  
    final int userId;
    final int id;
    final String title;
    final String body;
    bool isFav = false;
  
    factory Post.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Post(
          userId: json[&quot;userId&quot;],
          id: json[&quot;id&quot;],
          title: json[&quot;title&quot;],
          body: json[&quot;body&quot;],
        );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;userId&quot;: userId,
          &quot;id&quot;: id,
          &quot;title&quot;: title,
          &quot;body&quot;: body,
        };
  }
  
  </code></pre>
  <p>bloc.dart</p>
  <pre class="lang-dart prettyprint-override"><code>
  import 'package:bloc/bloc.dart';
  import 'package:freezed_annotation/freezed_annotation.dart';
  import 'package:freezed_bloc_update/post.dart';
  import 'package:http/http.dart' as http;
  
  part 'fakeapi_event.dart';
  part 'fakeapi_state.dart';
  part 'fakeapi_bloc.freezed.dart';
  
  class FakeapiBloc extends Bloc&lt;FakeapiEvent, FakeapiState&gt; {
    FakeapiBloc() : super(const FakeapiState.inital()) {
      on&lt;LoadData&gt;(
        (event, emit) async {
          try {
            emit(const FakeapiState.loading());
            Uri uri = Uri.parse('https://jsonplaceholder.typicode.com/posts');
            final response = await http.get(uri);
            if (response.statusCode == 200) {
              emit(FakeapiState.loaded(posts: postFromJson(response.body)));
            } else {
              emit(const FakeapiState.error(errorMessage: 'Api Call Failed'));
            }
          } catch (err) {
            emit(const FakeapiState.error(errorMessage: 'Api Call Failed'));
          }
        },
      );
  
      on&lt;MarkedFav&gt;((event, emit) {
        final previousState = state as Loaded;
        previousState.posts[event.pos].isFav =
            !previousState.posts[event.pos].isFav;
        emit(FakeapiState.loaded(posts: [...previousState.posts]));
      });
    }
  }
  
  </code></pre>
  <p>events.dart</p>
  <pre class="lang-dart prettyprint-override"><code>
  part of 'fakeapi_bloc.dart';
  
  @freezed
  class FakeapiEvent with _$FakeapiEvent {
    const factory FakeapiEvent.loadData() = LoadData;
    const factory FakeapiEvent.markedFav({required int pos}) = MarkedFav;
  }
  
  </code></pre>
  <p>states.dart</p>
  <pre class="lang-dart prettyprint-override"><code>
  part of 'fakeapi_bloc.dart';
  
  @freezed
  class FakeapiState with _$FakeapiState {
    const factory FakeapiState.inital() = Initial;
    const factory FakeapiState.loading() = Loading;
    const factory FakeapiState.loaded({required List&lt;Post&gt; posts}) = Loaded;
    const factory FakeapiState.error({required String errorMessage}) = Error;
  }
  
  </code></pre>
  <p>One solution which I did was keeping a bool variable(outside of model class) in state itself and clicking upon the fav toggling the bool value. Which is retriggering the UI update.</p>