build method

  1. @override
Settings build()

Initialize a Notifier.

It is safe to use Ref.watch or Ref.listen inside this method.

If a dependency of this Notifier (when using Ref.watch) changes, then build will be re-executed. On the other hand, the Notifier will not be recreated. Its instance will be preserved between executions of build.

If this method throws, reading this provider will rethrow the error.

Implementation

@override
Settings build() {
  NotifierPersistX(this).persist<String, String>(
    ref.watch(storageProvider.future),
    key: 'SettingStorage',
    encode: (state) => jsonEncode(state.toJson()),
    decode: (encoded) => Settings.fromJson(
      jsonDecode(encoded) as Map<String, dynamic>,
    ),
    options: StorageOptions(cacheTime: StorageCacheTime.unsafe_forever),
  );

  return const Settings(
    interfaceScale: null,
    denseExplorer: false,
    optInFeatures: {},
  );
}