title: Flutter freezed data conflict with model data
body: <p>I'm new to Flutter and following various guides to learn and, actually, after trying doing something simple by myself I found a weird issue and I don't know how to get rid of it...</p>
  <p>These are my dependencies:</p>
  <pre><code>dependencies:
    flutter:
      sdk: flutter
  
    flutter_riverpod: ^0.12.4
    json_annotation: ^3.1.1
    dio: ^3.0.10
  
  dev_dependencies:
    flutter_test:
      sdk: flutter
  
    freezed: ^0.12.7
    build_runner: ^1.11.1
    json_serializable: ^3.5.1
  </code></pre>
  <p>I create a small nodejs endpoint <code>/status</code> that returns a simple object: <code>{ message: 'success' }</code></p>
  <p>I created a model for the <code>Status</code>:</p>
  <pre><code>part 'status_data.g.dart';
  
  @JsonSerializable()
  class StatusData {
    StatusData({
      this.message,
    });
  
    String message;
  
    factory StatusData.fromRawJson(String str) =&gt;
        StatusData.fromJson(json.decode(str));
  
    factory StatusData.fromJson(Map&lt;String, dynamic&gt; json) =&gt; StatusData(
          message: json['message'],
        );
  }
  </code></pre>
  <p>I created a <code>Status_notifier</code>:</p>
  <pre><code>class StatusNotifier extends StateNotifier&lt;StatusState&gt; {
    final StatusClient _statusClient;
  
    StatusNotifier(this._statusClient) : super(StatusState());
  
    Future&lt;void&gt; getStatus() async {
      try {
        state = StatusState.loading();
        final status = await _statusClient.getStatus();
        state = StatusState.loaded(status); // ERROR (see below)
      } catch (e) {
        state = StatusState.error(message: 'Error: $e');
      }
    }
  }
  </code></pre>
  <blockquote>
  <p>ERROR: The argument type 'StatusData (where StatusData is defined in
  /my_long_path/lib/models/status_data.dart)' can't be assigned to the
  parameter type 'StatusData (where StatusData is defined in
  /my_long_path/lib/application/state/status_state.freezed.dart)'.</p>
  </blockquote>
  <p>I created a <code>Status_state</code>:</p>
  <p>For some reason here the <code>import</code> for my <code>StatusData</code> model is &quot;grey&quot;, not used... It looks like it is using <code>StatusData</code> coming from some generated file...</p>
  <pre><code>@freezed
  abstract class StatusState with _$StatusState {
    const factory StatusState() = Initial;
    const factory StatusState.loading() = Loading;
    const factory StatusState.loaded(StatusData status) = StatusData;
    const factory StatusState.error({String message}) = Error;
  }
  </code></pre>
  <p>I created the <code>Status_client</code> to fetch data:</p>
  <pre><code>class StatusClient {
    Future&lt;StatusData&gt; getStatus() async {
      Response response =
          await dio.get('https://my-api.com/status');
      if (response.statusCode == 200) {
        StatusData status = StatusData.fromJson(response.data);
        return status;
      }
      throw response;
    }
  }
  </code></pre>
  <p>And finally the <code>Status_provider</code>:</p>
  <pre><code>final statusClientProvider = Provider&lt;StatusClient&gt;((ref) =&gt; StatusClient());
  
  final statusNotifierProvider = StateNotifierProvider(
    (ref) =&gt; StatusNotifier(ref.watch(statusClientProvider)),
  );
  </code></pre>
  <p>I also executed the command <code>flutter pub run build_runner serve --delete-conflicting-outputs</code> to generate the files.</p>
  <p>Also in my UI, withing the <code>Consumer</code>, when the state is <code>loaded</code> I have an error:</p>
  <p><code>loaded: (status) =&gt; HomePageLoaded(status: status),</code></p>
  <p>The error is identical at the one wrote above...</p>
  <p>Can someone explain what is wrong with my implementation so that I can get better on it? Thanks in advance!</p>