content: // ignore_for_file: avoid_dynamic_calls
  
  import 'package:flutter_riverpod/experimental/persist.dart';
  import 'package:freezed_annotation/freezed_annotation.dart';
  import 'package:riverpod_annotation/experimental/json_persist.dart';
  import 'package:riverpod_annotation/riverpod_annotation.dart';
  
  import '../storage/codegen.dart';
  
  part 'codegen.g.dart';
  part 'codegen.freezed.dart';
  
  Future<List<Todo>> fetchTodosFromServer() async => [];
  
  @freezed
  abstract class Todo with _$Todo {
    const factory Todo({
      required String id,
      required String title,
      required bool completed,
    }) = _Todo;
  
    factory Todo.fromJson(Map<String, dynamic> json) => _$TodoFromJson(json);
  }
  
  /* SNIPPET START */
  @riverpod
  @JsonPersist()
  class TodoList extends _$TodoList {
    @override
    Future<List<Todo>> build() async {
      persist(
        ref.watch(storageProvider.future),
        // We can optionally pass a "destroyKey". When a new version of the application
        // is release with a different destroyKey, the old persisted state will be
        // deleted, and a brand new state will be created.
        // highlight-next-line
        options: const StorageOptions(destroyKey: '1.0'),
      );
  
      return fetchTodosFromServer();
    }
  }
  