title: flutter cannot write in hive: HiveError: Cannot write, unknown type: RecipeModel. Did you forget to register an adapter?
body: <p>I have a model of Recipes and as the name suggests the model is for recipes. The recipe model has</p>
  <ol>
  <li>name,</li>
  <li>authorName,</li>
  <li>category</li>
  <li>List --&gt; separate model</li>
  <li>Lis ---&gt;separate model</li>
  </ol>
  <p>And <code>toJson</code> and <code>fromJson</code> methods. Now I want a list which will be saved locally, the list will be of all the recipes the user has marked as favorite.</p>
  <p>So, I made this FavoriteRecipeModel:</p>
  <pre><code>class FavoriteRecipeModel {
    List&lt;RecipeModel&gt;? recipeList;
    FavoriteRecipeModel({this.recipeList});
    factory FavoriteRecipeModel.fromJson(Map&lt;String, dynamic&gt; json) =&gt;
        FavoriteRecipeModel(
          recipeList: json[&quot;recipeList&quot;] == null ? null : json[&quot;recipeList&quot;],
        );
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;recipe&quot;: recipeList == null ? null : recipeList,
        };
  }
  </code></pre>
  <p>And this is how the function is written:</p>
  <pre><code>  FavoriteRecipeModel frm = FavoriteRecipeModel();
    void addToFavorites() async {
      await Hive.initFlutter();
      var box = await Hive.openBox('favoriteRecipeList');
      box.put('frm1', widget.recipe!);
      print(frm);
    }
  </code></pre>
  <p>The widget.recipe! is coming in like this:</p>
  <pre><code>  final RecipeModel? recipe;
  
    RecipeDetailsScreen({required this.recipe});
  </code></pre>
  <p>I'm using the recipe model to load all the data in the screen.</p>
  <p>But I'm getting:</p>
  <p><code>Unhandled Exception: HiveError: Cannot write, unknown type: RecipeModel. Did you forget to register an adapter?</code></p>
  <p>What did I do wrong and how can I fix it?</p>
  <p><strong>Update 1:</strong> here's my full FavoritesModel</p>
  <pre><code>class FavoriteRecipeModel {
    List&lt;RecipeModel&gt;? recipeList;
    FavoriteRecipeModel({this.recipeList});
    factory FavoriteRecipeModel.fromJson(Map&lt;String, dynamic&gt; json) =&gt;
        FavoriteRecipeModel(
          recipeList: json[&quot;recipeList&quot;] == null ? null : json[&quot;recipeList&quot;],
        );
    Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;recipe&quot;: recipeList == null ? null : recipeList,
        };
  }
  
  class FavoriteAdapter extends TypeAdapter&lt;FavoriteRecipeModel&gt; {
    @override
    final typeId = 0;
    @override
    FavoriteRecipeModel read(BinaryReader reader) {
      return FavoriteRecipeModel();
    }
  
    @override
    void write(BinaryWriter writer, FavoriteRecipeModel obj) {
      // TODO: implement write
      writer.write(obj.recipeList);
    }
  }
  </code></pre>
  <p>and here's the method that should list the all recipe's selected as favorite:</p>
  <pre><code>  FavoriteRecipeModel frm = FavoriteRecipeModel();
    void addToFavorites() async {
      Hive.registerAdapter(FavoriteAdapter());
      await Hive.initFlutter();
      var box = await Hive.openBox&lt;FavoriteRecipeModel&gt;('favoriteRecipeList');
      box.put('frm1', FavoriteRecipeModel());
      print(box.values);
    }
  </code></pre>