diff --git a/benchmarks/pubspec.yaml b/benchmarks/pubspec.yaml index a2cd6e07d..701e2aafc 100644 --- a/benchmarks/pubspec.yaml +++ b/benchmarks/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" dependencies: flutter: diff --git a/examples/counter/pubspec_overrides.yaml b/examples/counter/pubspec_overrides.yaml index e738086cd..d2e1fda40 100644 --- a/examples/counter/pubspec_overrides.yaml +++ b/examples/counter/pubspec_overrides.yaml @@ -14,5 +14,3 @@ dependency_overrides: path: ../../packages/riverpod_annotation riverpod_generator: path: ../../packages/riverpod_generator - # https://github.com/vegardit/dart-hotreloader/issues/14 - vm_service: ">=8.0.0 <15.0.0" \ No newline at end of file diff --git a/examples/marvel/pubspec_overrides.yaml b/examples/marvel/pubspec_overrides.yaml index e738086cd..d2e1fda40 100644 --- a/examples/marvel/pubspec_overrides.yaml +++ b/examples/marvel/pubspec_overrides.yaml @@ -14,5 +14,3 @@ dependency_overrides: path: ../../packages/riverpod_annotation riverpod_generator: path: ../../packages/riverpod_generator - # https://github.com/vegardit/dart-hotreloader/issues/14 - vm_service: ">=8.0.0 <15.0.0" \ No newline at end of file diff --git a/examples/pub/pubspec_overrides.yaml b/examples/pub/pubspec_overrides.yaml index e738086cd..d2e1fda40 100644 --- a/examples/pub/pubspec_overrides.yaml +++ b/examples/pub/pubspec_overrides.yaml @@ -14,5 +14,3 @@ dependency_overrides: path: ../../packages/riverpod_annotation riverpod_generator: path: ../../packages/riverpod_generator - # https://github.com/vegardit/dart-hotreloader/issues/14 - vm_service: ">=8.0.0 <15.0.0" \ No newline at end of file diff --git a/examples/random_number/pubspec_overrides.yaml b/examples/random_number/pubspec_overrides.yaml index 978b48d99..74695a9c8 100644 --- a/examples/random_number/pubspec_overrides.yaml +++ b/examples/random_number/pubspec_overrides.yaml @@ -12,5 +12,3 @@ dependency_overrides: path: ../../packages/riverpod_annotation riverpod_generator: path: ../../packages/riverpod_generator - # https://github.com/vegardit/dart-hotreloader/issues/14 - vm_service: ">=8.0.0 <15.0.0" diff --git a/examples/stackoverflow/pubspec_overrides.yaml b/examples/stackoverflow/pubspec_overrides.yaml index e738086cd..d2e1fda40 100644 --- a/examples/stackoverflow/pubspec_overrides.yaml +++ b/examples/stackoverflow/pubspec_overrides.yaml @@ -14,5 +14,3 @@ dependency_overrides: path: ../../packages/riverpod_annotation riverpod_generator: path: ../../packages/riverpod_generator - # https://github.com/vegardit/dart-hotreloader/issues/14 - vm_service: ">=8.0.0 <15.0.0" \ No newline at end of file diff --git a/examples/todos/pubspec_overrides.yaml b/examples/todos/pubspec_overrides.yaml index e738086cd..d2e1fda40 100644 --- a/examples/todos/pubspec_overrides.yaml +++ b/examples/todos/pubspec_overrides.yaml @@ -14,5 +14,3 @@ dependency_overrides: path: ../../packages/riverpod_annotation riverpod_generator: path: ../../packages/riverpod_generator - # https://github.com/vegardit/dart-hotreloader/issues/14 - vm_service: ">=8.0.0 <15.0.0" \ No newline at end of file diff --git a/packages/flutter_riverpod/CHANGELOG.md b/packages/flutter_riverpod/CHANGELOG.md index c886cf4c2..e799309a0 100644 --- a/packages/flutter_riverpod/CHANGELOG.md +++ b/packages/flutter_riverpod/CHANGELOG.md @@ -1,3 +1,21 @@ +## 2.5.2 - 2024-03-18 + +- Fixed various typos in the documentation (thanks to @kevalvavaliya) + +## 2.5.1 - 2024-03-10 + +- Deprecate `ProviderScope.parent` due to fundamentally not working. + See https://github.com/rrousselGit/riverpod/issues/3261 +- Improved `Provider(dependencies: [...])` documentation. +- Fix out of date `pub.dev` description +- `ref.invalidate` now correctly clear all resources associated + with the provider if the provider is no-longer used. +- Fix `selectAsync` sometimes never resolving. +- Fix `ProviderSubscription.read` returned by `ref.listen(provider.future)` not throwing if used after the subscription has been closed. +- Fix `ref.onAddListener` and other life-cycles not being triggered when + listening to `provider.future`/`provider.notifier`. +- Fix a bug that caused `Assertion failed: _lastFuture == null` + ## 2.4.10 - 2024-02-03 - Fix out of date `pub.dev` description diff --git a/packages/flutter_riverpod/example/pubspec.yaml b/packages/flutter_riverpod/example/pubspec.yaml index 5dc9c5207..945b7287e 100644 --- a/packages/flutter_riverpod/example/pubspec.yaml +++ b/packages/flutter_riverpod/example/pubspec.yaml @@ -4,7 +4,7 @@ description: A new Flutter project. publish_to: "none" environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: flutter: diff --git a/packages/flutter_riverpod/lib/src/consumer.dart b/packages/flutter_riverpod/lib/src/consumer.dart index 53b06afab..6fe0c9068 100644 --- a/packages/flutter_riverpod/lib/src/consumer.dart +++ b/packages/flutter_riverpod/lib/src/consumer.dart @@ -642,8 +642,14 @@ class ConsumerStatefulElement extends StatefulElement implements WidgetRef { _assertNotDisposed(); final listeners = _manualListeners ??= []; + // Reading the container using "listen:false" to guarantee that this can + // be used inside initState. + final container = ProviderScope.containerOf(this, listen: false); + final sub = _ListenManual( - ProviderScope.containerOf(this, listen: false).listen( + // TODO somehow pass "this" instead for the devtool's sake + container, + container.listen( provider, listener, onError: onError, @@ -660,16 +666,19 @@ class ConsumerStatefulElement extends StatefulElement implements WidgetRef { BuildContext get context => this; } -class _ListenManual implements ProviderSubscription { - _ListenManual(this._subscription, this._element); +class _ListenManual extends ProviderSubscription { + _ListenManual(super.source, this._subscription, this._element); final ProviderSubscription _subscription; final ConsumerStatefulElement _element; @override void close() { - _subscription.close(); - _element._manualListeners?.remove(this); + if (!closed) { + _subscription.close(); + _element._manualListeners?.remove(this); + } + super.close(); } @override diff --git a/packages/flutter_riverpod/lib/src/framework.dart b/packages/flutter_riverpod/lib/src/framework.dart index c6e592ea1..5cd81488c 100644 --- a/packages/flutter_riverpod/lib/src/framework.dart +++ b/packages/flutter_riverpod/lib/src/framework.dart @@ -1,4 +1,4 @@ -// ignore_for_file: invalid_use_of_internal_member +// ignore_for_file: invalid_use_of_internal_member, deprecated_member_use_from_same_package import 'package:flutter/foundation.dart' hide describeIdentity; import 'package:flutter/material.dart'; @@ -83,6 +83,9 @@ class ProviderScope extends StatefulWidget { super.key, this.overrides = const [], this.observers, + @Deprecated( + 'Will be removed in 3.0.0. See https://github.com/rrousselGit/riverpod/issues/3261#issuecomment-1973514033', + ) this.parent, required this.child, }); @@ -136,6 +139,9 @@ class ProviderScope extends StatefulWidget { /// /// /// The [parent] variable must never change. + @Deprecated( + 'Will be removed in 3.0.0. See https://github.com/rrousselGit/riverpod/issues/3261#issuecomment-1973514033', + ) final ProviderContainer? parent; /// The part of the widget tree that can use Riverpod and has overridden providers. diff --git a/packages/flutter_riverpod/pubspec.yaml b/packages/flutter_riverpod/pubspec.yaml index c7a1a2ef7..cd0ed162f 100644 --- a/packages/flutter_riverpod/pubspec.yaml +++ b/packages/flutter_riverpod/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_riverpod description: > A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze. -version: 2.4.10 +version: 2.5.1 homepage: https://riverpod.dev repository: https://github.com/rrousselGit/riverpod issue_tracker: https://github.com/rrousselGit/riverpod/issues @@ -10,7 +10,7 @@ funding: - https://github.com/sponsors/rrousselGit/ environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: @@ -18,7 +18,7 @@ dependencies: flutter: sdk: flutter meta: ^1.4.0 - riverpod: 2.5.0 + riverpod: 2.5.1 state_notifier: ">=0.7.2 <2.0.0" dev_dependencies: diff --git a/packages/flutter_riverpod/test/framework_test.dart b/packages/flutter_riverpod/test/framework_test.dart index 7796a660a..f2bffa093 100644 --- a/packages/flutter_riverpod/test/framework_test.dart +++ b/packages/flutter_riverpod/test/framework_test.dart @@ -163,6 +163,7 @@ void main() { await tester.pumpWidget( ProviderScope( + // ignore: deprecated_member_use_from_same_package parent: container, child: Consumer( builder: (context, ref, _) { @@ -184,6 +185,7 @@ void main() { await tester.pumpWidget( ProviderScope( + // ignore: deprecated_member_use_from_same_package parent: container, child: Container(), ), @@ -191,6 +193,7 @@ void main() { await tester.pumpWidget( ProviderScope( + // ignore: deprecated_member_use_from_same_package parent: container2, child: Container(), ), diff --git a/packages/hooks_riverpod/CHANGELOG.md b/packages/hooks_riverpod/CHANGELOG.md index aebbbb3fa..d3e980f12 100644 --- a/packages/hooks_riverpod/CHANGELOG.md +++ b/packages/hooks_riverpod/CHANGELOG.md @@ -1,3 +1,17 @@ +## 2.5.1 - 2024-03-10 + +- Deprecate `ProviderScope.parent` due to fundamentally not working. + See https://github.com/rrousselGit/riverpod/issues/3261 +- Improved `Provider(dependencies: [...])` documentation. +- Fix out of date `pub.dev` description +- `ref.invalidate` now correctly clear all resources associated + with the provider if the provider is no-longer used. +- Fix `selectAsync` sometimes never resolving. +- Fix `ProviderSubscription.read` returned by `ref.listen(provider.future)` not throwing if used after the subscription has been closed. +- Fix `ref.onAddListener` and other life-cycles not being triggered when + listening to `provider.future`/`provider.notifier`. +- Fix a bug that caused `Assertion failed: _lastFuture == null` + ## 2.4.10 - 2024-02-03 - Fix out of date `pub.dev` description diff --git a/packages/hooks_riverpod/example/pubspec.yaml b/packages/hooks_riverpod/example/pubspec.yaml index 8fcf462c8..8223d8af7 100644 --- a/packages/hooks_riverpod/example/pubspec.yaml +++ b/packages/hooks_riverpod/example/pubspec.yaml @@ -4,7 +4,7 @@ description: A new Flutter project. publish_to: "none" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" flutter: ">=1.17.0" dependencies: diff --git a/packages/hooks_riverpod/pubspec.yaml b/packages/hooks_riverpod/pubspec.yaml index 5495ff633..66cdd4cde 100644 --- a/packages/hooks_riverpod/pubspec.yaml +++ b/packages/hooks_riverpod/pubspec.yaml @@ -2,7 +2,7 @@ name: hooks_riverpod description: > A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze. -version: 2.4.10 +version: 2.5.1 homepage: https://riverpod.dev repository: https://github.com/rrousselGit/riverpod issue_tracker: https://github.com/rrousselGit/riverpod/issues @@ -10,7 +10,7 @@ funding: - https://github.com/sponsors/rrousselGit/ environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: @@ -18,8 +18,8 @@ dependencies: flutter: sdk: flutter flutter_hooks: '>=0.18.0 <0.21.0' - flutter_riverpod: 2.4.10 - riverpod: 2.5.0 + flutter_riverpod: 2.5.1 + riverpod: 2.5.1 state_notifier: ">=0.7.2 <2.0.0" dev_dependencies: diff --git a/packages/riverpod/CHANGELOG.md b/packages/riverpod/CHANGELOG.md index 4aa05f364..01097f377 100644 --- a/packages/riverpod/CHANGELOG.md +++ b/packages/riverpod/CHANGELOG.md @@ -1,11 +1,18 @@ -## 2.5.0 - 2024-02-03 - -- Add `test` argument to `AsyncValue.guard` method. (thanks to @utamori) - -## Unreleased fix +## 2.5.1 - 2024-03-10 - Improved `Provider(dependencies: [...])` documentation. - Fix out of date `pub.dev` description +- `ref.invalidate` now correctly clear all resources associated + with the provider if the provider is no-longer used. +- Fix `selectAsync` sometimes never resolving. +- Fix `ProviderSubscription.read` returned by `ref.listen(provider.future)` not throwing if used after the subscription has been closed. +- Fix `ref.onAddListener` and other life-cycles not being triggered when + listening to `provider.future`/`provider.notifier`. +- Fix a bug that caused `Assertion failed: _lastFuture == null` + +## 2.5.0 - 2024-02-03 + +- Add `test` argument to `AsyncValue.guard` method. (thanks to @utamori) ## 2.4.9 - 2023-11-27 diff --git a/packages/riverpod/example/pubspec.yaml b/packages/riverpod/example/pubspec.yaml index 5a55da610..e5135ee35 100644 --- a/packages/riverpod/example/pubspec.yaml +++ b/packages/riverpod/example/pubspec.yaml @@ -2,7 +2,7 @@ name: riverpod_example publish_to: "none" environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: crypto: ^3.0.0 diff --git a/packages/riverpod/lib/src/async_notifier/base.dart b/packages/riverpod/lib/src/async_notifier/base.dart index 5b4433a3f..f1a9f80f7 100644 --- a/packages/riverpod/lib/src/async_notifier/base.dart +++ b/packages/riverpod/lib/src/async_notifier/base.dart @@ -466,9 +466,8 @@ mixin FutureHandlerProviderElementMixin @override void visitChildren({ - required void Function(ProviderElementBase element) elementVisitor, - required void Function(ProxyElementValueNotifier element) - notifierVisitor, + required void Function(ProviderElementBase element) elementVisitor, + required void Function(ProxyElementValueNotifier element) notifierVisitor, }) { super.visitChildren( elementVisitor: elementVisitor, @@ -491,9 +490,8 @@ abstract class AsyncNotifierProviderElementBase< @override void visitChildren({ - required void Function(ProviderElementBase element) elementVisitor, - required void Function(ProxyElementValueNotifier element) - notifierVisitor, + required void Function(ProviderElementBase element) elementVisitor, + required void Function(ProxyElementValueNotifier element) notifierVisitor, }) { super.visitChildren( elementVisitor: elementVisitor, diff --git a/packages/riverpod/lib/src/common/env.dart b/packages/riverpod/lib/src/common/env.dart new file mode 100644 index 000000000..eb60eadff --- /dev/null +++ b/packages/riverpod/lib/src/common/env.dart @@ -0,0 +1,82 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// ignore_for_file: do_not_use_environment, comment_references + +/// A constant that is true if the application was compiled in release mode. +/// +/// More specifically, this is a constant that is true if the application was +/// compiled in Dart with the '-Ddart.vm.product=true' flag. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in release mode, and hence +/// can be removed. +/// +/// Generally it is better to use [kDebugMode] or `assert` to gate code, since +/// using [kReleaseMode] will introduce differences between release and profile +/// builds, which makes performance testing less representative. +/// +/// See also: +/// +/// * [kDebugMode], which is true in debug builds. +/// * [kProfileMode], which is true in profile builds. +const bool kReleaseMode = bool.fromEnvironment('dart.vm.product'); + +/// A constant that is true if the application was compiled in profile mode. +/// +/// More specifically, this is a constant that is true if the application was +/// compiled in Dart with the '-Ddart.vm.profile=true' flag. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in profile mode, an hence +/// can be removed. +/// +/// See also: +/// +/// * [kDebugMode], which is true in debug builds. +/// * [kReleaseMode], which is true in release builds. +const bool kProfileMode = bool.fromEnvironment('dart.vm.profile'); + +/// A constant that is true if the application was compiled in debug mode. +/// +/// More specifically, this is a constant that is true if the application was +/// not compiled with '-Ddart.vm.product=true' and '-Ddart.vm.profile=true'. +/// +/// Since this is a const value, it can be used to indicate to the compiler that +/// a particular block of code will not be executed in debug mode, and hence +/// can be removed. +/// +/// An alternative strategy is to use asserts, as in: +/// +/// ```dart +/// assert(() { +/// // ...debug-only code here... +/// return true; +/// }()); +/// ``` +/// +/// See also: +/// +/// * [kReleaseMode], which is true in release builds. +/// * [kProfileMode], which is true in profile builds. +const bool kDebugMode = !kReleaseMode && !kProfileMode; + +/// The epsilon of tolerable double precision error. +/// +/// This is used in various places in the framework to allow for floating point +/// precision loss in calculations. Differences below this threshold are safe to +/// disregard. +const double precisionErrorTolerance = 1e-10; + +/// A constant that is true if the application was compiled to run on the web. +/// +/// See also: +/// +/// * [defaultTargetPlatform], which is used by themes to find out which +/// platform the application is running on (or, in the case of a web app, +/// which platform the application's browser is running in). Can be overridden +/// in tests with [debugDefaultTargetPlatformOverride]. +/// * [dart:io.Platform], a way to find out the browser's platform that is not +/// overridable in tests. +const bool kIsWeb = bool.fromEnvironment('dart.library.js_util'); diff --git a/packages/riverpod/lib/src/framework.dart b/packages/riverpod/lib/src/framework.dart index acad37540..478be6b4f 100644 --- a/packages/riverpod/lib/src/framework.dart +++ b/packages/riverpod/lib/src/framework.dart @@ -3,8 +3,10 @@ library framework; import 'dart:async'; import 'dart:collection'; +import 'package:collection/collection.dart'; import 'package:meta/meta.dart'; import 'package:state_notifier/state_notifier.dart'; +import 'common/env.dart'; import 'internals.dart'; part 'framework/always_alive.dart'; diff --git a/packages/riverpod/lib/src/framework/async_selector.dart b/packages/riverpod/lib/src/framework/async_selector.dart index 57406e482..6c77f5148 100644 --- a/packages/riverpod/lib/src/framework/async_selector.dart +++ b/packages/riverpod/lib/src/framework/async_selector.dart @@ -234,8 +234,18 @@ class _AsyncSelector with ProviderListenable> { } return _SelectorSubscription( + node, sub, () => selectedFuture!, + onClose: () { + final completer = selectedCompleter; + if (completer != null && !completer.isCompleted) { + read(node).then( + completer.complete, + onError: completer.completeError, + ); + } + }, ); } diff --git a/packages/riverpod/lib/src/framework/container.dart b/packages/riverpod/lib/src/framework/container.dart index cd90b1a2b..99beff446 100644 --- a/packages/riverpod/lib/src/framework/container.dart +++ b/packages/riverpod/lib/src/framework/container.dart @@ -30,11 +30,11 @@ class _StateReader { /// at the creation of the [ProviderContainer] final bool isDynamicallyCreated; - ProviderElementBase? _element; + ProviderElementBase? _element; - ProviderElementBase getElement() => _element ??= _create(); + ProviderElementBase getElement() => _element ??= _create(); - ProviderElementBase _create() { + ProviderElementBase _create() { if (origin == _circularDependencyLock) { throw CircularDependencyError._(); } @@ -268,23 +268,6 @@ class ProviderContainer implements Node { ); } - @override - ProviderSubscription _listenElement( - ProviderElementBase element, { - required void Function(State? previous, State next) listener, - required void Function(Object error, StackTrace stackTrace) onError, - }) { - final sub = _ExternalProviderSubscription._( - element, - listener, - onError: onError, - ); - - element._externalDependents.add(sub); - - return sub; - } - /// {@macro riverpod.listen} @override ProviderSubscription listen( @@ -653,7 +636,7 @@ final b = Provider((ref) => ref.watch(a), dependencies: [a]); } /// Traverse the [ProviderElementBase]s associated with this [ProviderContainer]. - Iterable> getAllProviderElements() sync* { + Iterable getAllProviderElements() sync* { for (final reader in _stateReaders.values) { if (reader._element != null && reader.container == this) { yield reader._element!; @@ -666,9 +649,9 @@ final b = Provider((ref) => ref.watch(a), dependencies: [a]); /// This is fairly expensive and should be avoided as much as possible. /// If you do not need for providers to be sorted, consider using [getAllProviderElements] /// instead, which returns an unsorted list and is significantly faster. - Iterable> getAllProviderElementsInOrder() sync* { - final visitedNodes = HashSet>(); - final queue = DoubleLinkedQueue>(); + Iterable getAllProviderElementsInOrder() sync* { + final visitedNodes = HashSet(); + final queue = DoubleLinkedQueue(); // get providers that don't depend on other providers from this container for (final reader in _stateReaders.values) { diff --git a/packages/riverpod/lib/src/framework/element.dart b/packages/riverpod/lib/src/framework/element.dart index 2d64128fb..c907cebfb 100644 --- a/packages/riverpod/lib/src/framework/element.dart +++ b/packages/riverpod/lib/src/framework/element.dart @@ -43,11 +43,12 @@ void Function()? debugCanModifyProviders; /// of providers. /// Do not use. /// {@endtemplate} -abstract class ProviderElementBase implements Ref, Node { +@optionalTypeArgs +abstract class ProviderElementBase implements Ref, Node { /// {@macro riverpod.provider_element_base} ProviderElementBase(this._provider); - static ProviderElementBase? _debugCurrentlyBuildingElement; + static ProviderElementBase? _debugCurrentlyBuildingElement; /// The last result of [ProviderBase.debugGetCreateSourceHash]. /// @@ -61,8 +62,8 @@ abstract class ProviderElementBase implements Ref, Node { late ProviderBase _origin; /// The provider associated with this [ProviderElementBase], after applying overrides. - ProviderBase get provider => _provider; - ProviderBase _provider; + ProviderBase get provider => _provider; + ProviderBase _provider; /// The [ProviderContainer] that owns this [ProviderElementBase]. @override @@ -74,42 +75,22 @@ abstract class ProviderElementBase implements Ref, Node { /// This maps to listeners added with [listen]. /// See also [mayNeedDispose], called when [hasListeners] may have changed. bool get hasListeners => - _externalDependents.isNotEmpty || - _subscribers.isNotEmpty || - _providerDependents.isNotEmpty; + (_dependents?.isNotEmpty ?? false) || _providerDependents.isNotEmpty; - // TODO(rrousselGit) refactor to match ChangeNotifier - /// The list of [ProviderSubscription]s that are linked with this element, - /// which aren't coming from another provider. - /// - /// This is typically Flutter widgets or manual calls to [ProviderContainer.listen] - /// with this provider as target. - final _externalDependents = <_ExternalProviderSubscription>[]; - - /// The [ProviderSubscription]s associated to the providers that this - /// [ProviderElementBase] listens to. - /// - /// This list is typically updated when this provider calls [listen] on - /// another provider. - final _listenedProviderSubscriptions = <_ProviderListener>[]; + var _dependencies = HashMap, Object>(); + HashMap, Object>? _previousDependencies; + List? _subscriptions; + List? _dependents; /// The element of the providers that depends on this provider. final _providerDependents = >[]; - /// The subscriptions associated to other providers listening to this provider. - /// - /// Storing [_ProviderListener] instead of the raw [ProviderElementBase] as - /// a provider can listen multiple times to another provider with different listeners. - final _subscribers = <_ProviderListener>[]; - - var _dependencies = HashMap, Object>(); - HashMap, Object>? _previousDependencies; List? _onDisposeListeners; List? _onResumeListeners; List? _onCancelListeners; List? _onAddListeners; List? _onRemoveListeners; - List? _onChangeSelfListeners; + List? _onChangeSelfListeners; List? _onErrorSelfListeners; bool _mustRecomputeState = false; @@ -118,11 +99,10 @@ abstract class ProviderElementBase implements Ref, Node { var _didCancelOnce = false; - bool _mounted = false; - /// Whether the element was disposed or not @internal bool get mounted => _mounted; + bool _mounted = false; /// Whether the assert that prevents [requireState] from returning /// if the state was not set before is enabled. @@ -133,7 +113,7 @@ abstract class ProviderElementBase implements Ref, Node { bool _didBuild = false; /* STATE */ - Result? _state; + Result? _state; /// Update the exposed value of a provider and notify its listeners. /// @@ -143,7 +123,7 @@ abstract class ProviderElementBase implements Ref, Node { /// This API is not meant for public consumption. Instead if a [Ref] needs /// to expose a way to update the state, the practice is to expose a getter/setter. @internal - void setState(State newState) { + void setState(StateT newState) { assert( () { _debugDidSetState = true; @@ -168,7 +148,7 @@ abstract class ProviderElementBase implements Ref, Node { /// This is not meant for public consumption. Instead, public API should use /// [readSelf]. @internal - Result? getState() => _state; + Result? getState() => _state; /// Read the current value of a provider and: /// @@ -178,7 +158,7 @@ abstract class ProviderElementBase implements Ref, Node { /// This is not meant for public consumption. Instead, public API should use /// [readSelf]. @internal - State get requireState { + StateT get requireState { assert( () { if (debugAssertDidSetStateEnabled && !_debugDidSetState) { @@ -205,7 +185,7 @@ abstract class ProviderElementBase implements Ref, Node { /// Called when a provider is rebuilt. Used for providers to not notify their /// listeners if the exposed value did not change. @internal - bool updateShouldNotify(State previous, State next); + bool updateShouldNotify(StateT previous, StateT next); /* /STATE */ @@ -281,7 +261,7 @@ abstract class ProviderElementBase implements Ref, Node { /// the scenario where the value changed. @internal // ignore: use_setters_to_change_properties - void update(ProviderBase newProvider) { + void update(ProviderBase newProvider) { _provider = newProvider; } @@ -297,6 +277,7 @@ abstract class ProviderElementBase implements Ref, Node { _mustRecomputeState = true; runOnDispose(); + mayNeedDispose(); _container.scheduler.scheduleProviderRefresh(this); // We don't call this._markDependencyMayHaveChanged here because we voluntarily @@ -337,9 +318,7 @@ abstract class ProviderElementBase implements Ref, Node { _dependencyMayHaveChanged = false; visitAncestors( - (element) { - element.flush(); - }, + (element) => element.flush(), ); } @@ -348,7 +327,11 @@ abstract class ProviderElementBase implements Ref, Node { /// After a provider is initialized, this function takes care of unsubscribing /// to dependencies that are no-longer used. void _performBuild() { - _previousDependencies = _dependencies; + assert( + _previousDependencies == null, + 'Bad state: _performBuild was called twice', + ); + final previousDependencies = _previousDependencies = _dependencies; _dependencies = HashMap(); final previousStateResult = _state; @@ -383,12 +366,14 @@ abstract class ProviderElementBase implements Ref, Node { } // Unsubscribe to everything that a provider no longer depends on. - for (final sub in _previousDependencies!.entries) { + for (final sub in previousDependencies.entries) { sub.key .._providerDependents.remove(this) .._onRemoveListener(); } _previousDependencies = null; + + // TODO clear subscriptions only after the provider has been rebuilt } /// Initialize a provider. @@ -406,7 +391,7 @@ abstract class ProviderElementBase implements Ref, Node { /// Invokes [create] and handles errors. @internal void buildState() { - ProviderElementBase? debugPreviouslyBuildingElement; + ProviderElementBase? debugPreviouslyBuildingElement; final previousDidChangeDependency = _didChangeDependency; _didChangeDependency = false; assert( @@ -465,8 +450,8 @@ abstract class ProviderElementBase implements Ref, Node { } void _notifyListeners( - Result newState, - Result? previousStateResult, { + Result newState, + Result? previousStateResult, { bool checkUpdateShouldNotify = true, }) { assert( @@ -524,45 +509,40 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu previousStateResult.hasState && newState.hasState && !updateShouldNotify( - previousState as State, + previousState as StateT, newState.requireState, )) { return; } - final listeners = _externalDependents.toList(growable: false); - final subscribers = _subscribers.toList(growable: false); + final listeners = _dependents?.toList(growable: false); newState.map( data: (newState) { - for (var i = 0; i < listeners.length; i++) { - Zone.current.runBinaryGuarded( - listeners[i]._listener, - previousState, - newState.state, - ); - } - for (var i = 0; i < subscribers.length; i++) { - Zone.current.runBinaryGuarded( - subscribers[i].listener, - previousState, - newState.state, - ); + if (listeners != null) { + for (var i = 0; i < listeners.length; i++) { + final listener = listeners[i]; + if (listener is _ProviderStateSubscription) { + Zone.current.runBinaryGuarded( + listener.listener, + previousState, + newState.state, + ); + } + } } }, error: (newState) { - for (var i = 0; i < listeners.length; i++) { - Zone.current.runBinaryGuarded( - listeners[i].onError, - newState.error, - newState.stackTrace, - ); - } - for (var i = 0; i < subscribers.length; i++) { - Zone.current.runBinaryGuarded( - subscribers[i].onError, - newState.error, - newState.stackTrace, - ); + if (listeners != null) { + for (var i = 0; i < listeners.length; i++) { + final listener = listeners[i]; + if (listener is _ProviderStateSubscription) { + Zone.current.runBinaryGuarded( + listener.onError, + newState.error, + newState.stackTrace, + ); + } + } } }, ); @@ -621,9 +601,10 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu () { if (listenable is! ProviderBase) return true; + ProviderElementBase? listenableElement; try { // Initializing the provider, to make sure its dependencies are setup. - _container.readProviderElement(listenable); + listenableElement = _container.readProviderElement(listenable); } catch (err) { // We don't care whether the provider is in error or not. We're just // checking whether we're not in a circular dependency. @@ -650,14 +631,17 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu "To fix, add $listenable to $origin's 'dependencies' parameter", ); - final queue = - Queue>.from(_providerDependents); + final queue = Queue(); + visitAncestors(queue.add); + if (listenableElement != null) { + queue.add(listenableElement); + } while (queue.isNotEmpty) { final current = queue.removeFirst(); - queue.addAll(current._providerDependents); + current.visitAncestors(queue.add); - if (current.origin == listenable) { + if (current.origin == _origin) { throw CircularDependencyError._(); } } @@ -746,25 +730,6 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu return _container.readProviderElement(provider); } - @override - ProviderSubscription _listenElement( - ProviderElementBase element, { - required void Function(T? previous, T next) listener, - required void Function(Object error, StackTrace stackTrace) onError, - }) { - final sub = _ProviderListener._( - listenedElement: element, - dependentElement: this, - listener: (prev, value) => listener(prev as T?, value as T), - onError: onError, - ); - - element._subscribers.add(sub); - _listenedProviderSubscriptions.add(sub); - - return sub; - } - @override ProviderSubscription listen( ProviderListenable listenable, @@ -789,7 +754,7 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu @override void listenSelf( - void Function(State? previous, State next) listener, { + void Function(StateT? previous, StateT next) listener, { void Function(Object error, StackTrace stackTrace)? onError, }) { // TODO do we want to expose a way to close the subscription? @@ -807,7 +772,7 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu /// Returns the currently exposed by a provider /// /// May throw if the provider threw when creating the exposed value. - State readSelf() { + StateT readSelf() { flush(); return requireState; @@ -822,16 +787,19 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu /// If a provider both [watch] and [listen] an element, or if a provider /// [listen] multiple times to an element, it may be visited multiple times. void visitChildren({ - required void Function(ProviderElementBase element) elementVisitor, - required void Function(ProxyElementValueNotifier element) - notifierVisitor, + required void Function(ProviderElementBase element) elementVisitor, + required void Function(ProxyElementValueNotifier element) notifierVisitor, }) { for (var i = 0; i < _providerDependents.length; i++) { elementVisitor(_providerDependents[i]); } - for (var i = 0; i < _subscribers.length; i++) { - elementVisitor(_subscribers[i].dependentElement); + final dependents = _dependents; + if (dependents != null) { + for (var i = 0; i < dependents.length; i++) { + final dependent = dependents[i].source; + if (dependent is ProviderElementBase) elementVisitor(dependent); + } } } @@ -844,12 +812,18 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu /// If this provider both [watch] and [listen] an element, or if it /// [listen] multiple times to an element, that element may be visited multiple times. void visitAncestors( - void Function(ProviderElementBase element) visitor, + void Function(ProviderElementBase element) visitor, ) { _dependencies.keys.forEach(visitor); - for (var i = 0; i < _listenedProviderSubscriptions.length; i++) { - visitor(_listenedProviderSubscriptions[i].listenedElement); + final subscriptions = _subscriptions; + if (subscriptions != null) { + for (var i = 0; i < subscriptions.length; i++) { + final sub = subscriptions[i]; + if (sub is _ProviderStateSubscription) { + visitor(sub.listenedElement); + } + } } } @@ -869,16 +843,14 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu void dispose() { runOnDispose(); - // TODO test invalidateSelf() then dispose() properly unlinks dependencies - // TODO test [listen] calls are cleared - for (final sub in _dependencies.entries) { sub.key._providerDependents.remove(this); sub.key._onRemoveListener(); } _dependencies.clear(); - _externalDependents.clear(); + // TODO test invalidateSelf() then dispose() properly unlinks dependencies + // TODO test [listen] calls are cleared } void _onListen() { @@ -927,8 +899,24 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu if (!_mounted) return; _mounted = false; - while (_listenedProviderSubscriptions.isNotEmpty) { - _listenedProviderSubscriptions.first.close(); + final subscriptions = _subscriptions; + if (subscriptions != null) { + while (subscriptions.isNotEmpty) { + late int debugPreviousLength; + if (kDebugMode) { + debugPreviousLength = subscriptions.length; + } + + final sub = subscriptions.first; + sub.close(); + + if (kDebugMode) { + assert( + subscriptions.length < debugPreviousLength, + 'ProviderSubscription.close did not remove the subscription', + ); + } + } } _onDisposeListeners?.forEach(runGuarded); diff --git a/packages/riverpod/lib/src/framework/foundation.dart b/packages/riverpod/lib/src/framework/foundation.dart index 93508c9f2..9882cb229 100644 --- a/packages/riverpod/lib/src/framework/foundation.dart +++ b/packages/riverpod/lib/src/framework/foundation.dart @@ -229,11 +229,43 @@ mixin ProviderListenable implements ProviderListenableOrFamily { } /// Represents the subscription to a [ProviderListenable] +@optionalTypeArgs abstract class ProviderSubscription { - /// Stops listening to the provider - @mustCallSuper - void close(); + /// Represents the subscription to a [ProviderListenable] + ProviderSubscription(this.source) { + final Object listener = source; + if (listener is ProviderElementBase) { + final subs = listener._subscriptions ??= []; + subs.add(this); + } + } - /// Obtain the latest value emitted by the provider + /// The object that listens to the associated [ProviderListenable]. + /// + /// This is typically a [ProviderElementBase] or a [ProviderContainer], + /// but may be other values in the future. + final Node source; + + /// Whether the subscription is closed. + bool get closed => _closed; + var _closed = false; + + /// Obtain the latest value emitted by the provider. + /// + /// This method throws if [closed] is true. State read(); + + /// Stops listening to the provider. + /// + /// It is safe to call this method multiple times. + @mustCallSuper + void close() { + if (_closed) return; + _closed = true; + + final Object listener = source; + if (listener is ProviderElementBase) { + listener._subscriptions?.remove(this); + } + } } diff --git a/packages/riverpod/lib/src/framework/provider_base.dart b/packages/riverpod/lib/src/framework/provider_base.dart index d6fb9f863..67127597d 100644 --- a/packages/riverpod/lib/src/framework/provider_base.dart +++ b/packages/riverpod/lib/src/framework/provider_base.dart @@ -25,9 +25,9 @@ typedef DebugGetCreateSourceHash = String Function(); /// A base class for _all_ providers. @immutable -abstract class ProviderBase extends ProviderOrFamily - with ProviderListenable - implements ProviderOverride, Refreshable { +abstract class ProviderBase extends ProviderOrFamily + with ProviderListenable + implements ProviderOverride, Refreshable { /// A base class for _all_ providers. const ProviderBase({ required super.name, @@ -67,9 +67,9 @@ abstract class ProviderBase extends ProviderOrFamily final Object? argument; @override - ProviderSubscription addListener( + ProviderSubscription addListener( Node node, - void Function(State? previous, State next) listener, { + void Function(StateT? previous, StateT next) listener, { required void Function(Object error, StackTrace stackTrace)? onError, required void Function()? onDependencyMayHaveChanged, required bool fireImmediately, @@ -87,17 +87,21 @@ abstract class ProviderBase extends ProviderOrFamily ); } + // Calling before initializing the subscription, + // to ensure that "hasListeners" represents the state _before_ + // the listener is added element._onListen(); - return node._listenElement( - element, - listener: listener, + return _ProviderStateSubscription( + node, + listenedElement: element, + listener: (prev, next) => listener(prev as StateT?, next as StateT), onError: onError, ); } @override - State read(Node node) { + StateT read(Node node) { final element = node.readProviderElement(this); element.flush(); @@ -110,7 +114,7 @@ abstract class ProviderBase extends ProviderOrFamily /// An internal method that defines how a provider behaves. @visibleForOverriding - ProviderElementBase createElement(); + ProviderElementBase createElement(); @override // ignore: avoid_equals_and_hash_code_on_mutable_classes @@ -126,7 +130,7 @@ abstract class ProviderBase extends ProviderOrFamily if (from == null) return identical(other, this); return other.runtimeType == runtimeType && - other is ProviderBase && + other is ProviderBase && other.from == from && other.argument == argument; } @@ -149,62 +153,43 @@ abstract class ProviderBase extends ProviderOrFamily var _debugIsRunningSelector = false; -class _ExternalProviderSubscription - implements ProviderSubscription { - _ExternalProviderSubscription._( - this._listenedElement, - this._listener, { +/// When a provider listens to another provider using `listen` +@optionalTypeArgs +class _ProviderStateSubscription extends ProviderSubscription { + _ProviderStateSubscription( + super.source, { + required this.listenedElement, + required this.listener, required this.onError, - }); - - final void Function(State? previous, State next) _listener; - final ProviderElementBase _listenedElement; - final void Function(Object error, StackTrace stackTrace) onError; - var _closed = false; - - @override - void close() { - _closed = true; - _listenedElement._externalDependents.remove(this); - _listenedElement._onRemoveListener(); + }) { + final dependents = listenedElement._dependents ??= []; + dependents.add(this); } + // Why can't this be typed correctly? + final void Function(Object? prev, Object? state) listener; + final ProviderElementBase listenedElement; + final OnError onError; + @override - State read() { + StateT read() { if (_closed) { throw StateError( 'called ProviderSubscription.read on a subscription that was closed', ); } - return _listenedElement.readSelf(); + return listenedElement.readSelf(); } -} - -/// When a provider listens to another provider using `listen` -class _ProviderListener implements ProviderSubscription { - _ProviderListener._({ - required this.listenedElement, - required this.dependentElement, - required this.listener, - required this.onError, - }); - -// TODO can't we type it properly? - final void Function(Object? prev, Object? state) listener; - final ProviderElementBase dependentElement; - final ProviderElementBase listenedElement; - final OnError onError; @override void close() { - dependentElement._listenedProviderSubscriptions.remove(this); - listenedElement - .._subscribers.remove(this) - .._onRemoveListener(); - } + if (!closed) { + listenedElement._dependents?.remove(this); + listenedElement._onRemoveListener(); + } - @override - State read() => listenedElement.readSelf(); + super.close(); + } } /// A mixin to add [overrideWithValue] capability to a provider. diff --git a/packages/riverpod/lib/src/framework/proxy_provider_listenable.dart b/packages/riverpod/lib/src/framework/proxy_provider_listenable.dart index 14cb2400e..0ee47341f 100644 --- a/packages/riverpod/lib/src/framework/proxy_provider_listenable.dart +++ b/packages/riverpod/lib/src/framework/proxy_provider_listenable.dart @@ -2,6 +2,7 @@ part of '../framework.dart'; class _ProxySubscription extends ProviderSubscription { _ProxySubscription( + super.source, this._removeListeners, this._read, { required this.innerSubscription, @@ -12,13 +13,24 @@ class _ProxySubscription extends ProviderSubscription { final T Function() _read; @override - void close() { - innerSubscription.close(); - _removeListeners(); + T read() { + if (_closed) { + throw StateError( + 'called ProviderSubscription.read on a subscription that was closed', + ); + } + return _read(); } @override - T read() => _read(); + void close() { + if (!closed) { + innerSubscription.close(); + _removeListeners(); + } + + super.close(); + } } /// An internal utility for reading alternate values of a provider. @@ -73,8 +85,16 @@ class ProviderElementProxy }) { final element = node.readProviderElement(_origin); - // TODO does this need a "flush"? - // element.flush(); + // While we don't care about changes to the element, calling _listenElement + // is necessary to tell the listened element that it is being listened. + // We do it at the top of the file to trigger a "flush" before adding + // a listener to the notifier. + // This avoids the listener from being immediately notified of a new + // future when adding the listener refreshes the future. + final innerSub = node.listen( + _origin, + (prev, next) {}, + ); final notifier = _lense(element); if (fireImmediately) { @@ -97,15 +117,10 @@ class ProviderElementProxy ); return _ProxySubscription( + node, removeListener, () => read(node), - // While we don't care about changes to the element, calling _listenElement - // is necessary to tell the listened element that it is being listened. - innerSubscription: node._listenElement( - element, - listener: (prev, next) {}, - onError: (err, stack) {}, - ), + innerSubscription: innerSub, ); } diff --git a/packages/riverpod/lib/src/framework/ref.dart b/packages/riverpod/lib/src/framework/ref.dart index 39a0710d1..9403c341b 100644 --- a/packages/riverpod/lib/src/framework/ref.dart +++ b/packages/riverpod/lib/src/framework/ref.dart @@ -148,6 +148,38 @@ abstract class Ref { /// - when an `autoDispose` provider is no longer used /// - when the associated [ProviderContainer]/`ProviderScope` is disposed`. /// + /// **Prefer** having multiple [onDispose], for every disposable object created, + /// instead of a single large [onDispose]: + /// + /// Good: + /// ```dart + /// final disposable1 = Disposable(...); + /// ref.onDispose(disposable1.dispose); + /// + /// final disposable2 = Disposable(...); + /// ref.onDispose(disposable2.dispose); + /// ``` + /// + /// Bad: + /// ```dart + /// final disposable1 = Disposable(...); + /// final disposable2 = Disposable(...); + /// + /// ref.onDispose(() { + /// disposable1.dispose(); + /// disposable2.dispose(); + /// }); + /// ``` + /// + /// This is preferable for multiple reasons: + /// - It is easier for readers to know if a "dispose" is missing for a given + /// object. That is because the `dispose` call is directly next to the + /// object creation. + /// - It prevents memory leaks in cases of an exception. + /// If an exception happens inside a `dispose()` call, or + /// if an exception happens before [onDispose] is called, then + /// some of your objects may not be disposed. + /// /// See also: /// /// - [Provider.autoDispose], a modifier which tell a provider that it should diff --git a/packages/riverpod/lib/src/framework/scheduler.dart b/packages/riverpod/lib/src/framework/scheduler.dart index 85338eb49..9517b6fde 100644 --- a/packages/riverpod/lib/src/framework/scheduler.dart +++ b/packages/riverpod/lib/src/framework/scheduler.dart @@ -51,12 +51,12 @@ class ProviderScheduler { } final _stateToDispose = >[]; - final _stateToRefresh = >[]; + final _stateToRefresh = []; Completer? _pendingTaskCompleter; Future? get pendingFuture => _pendingTaskCompleter?.future; - void scheduleProviderRefresh(ProviderElementBase element) { + void scheduleProviderRefresh(ProviderElementBase element) { _stateToRefresh.add(element); _scheduleTask(); diff --git a/packages/riverpod/lib/src/framework/selector.dart b/packages/riverpod/lib/src/framework/selector.dart index 1aead0b6b..7853edbdf 100644 --- a/packages/riverpod/lib/src/framework/selector.dart +++ b/packages/riverpod/lib/src/framework/selector.dart @@ -2,9 +2,8 @@ part of '../framework.dart'; /// An abstraction of both [ProviderContainer] and [ProviderElement] used by /// [ProviderListenable]. -@internal abstract class Node { - /// Starts listening to this transformer + /// Starts listening to a listenable ProviderSubscription listen( ProviderListenable listenable, void Function(State? previous, State next) listener, { @@ -21,13 +20,6 @@ abstract class Node { ProviderElementBase readProviderElement( ProviderBase provider, ); - - /// Subscribes to a [ProviderElementBase]. - ProviderSubscription _listenElement( - ProviderElementBase element, { - required void Function(State? previous, State next) listener, - required void Function(Object error, StackTrace stackTrace) onError, - }); } /// An internal class for `ProviderBase.select`. @@ -139,6 +131,7 @@ class _ProviderSelector with ProviderListenable { } return _SelectorSubscription( + node, sub, () { return lastSelectedValue.map( @@ -160,22 +153,30 @@ class _ProviderSelector with ProviderListenable { } class _SelectorSubscription - implements ProviderSubscription { - _SelectorSubscription(this._internalSub, this._read); + extends ProviderSubscription { + _SelectorSubscription( + super.source, + this._internalSub, + this._read, { + this.onClose, + }); final ProviderSubscription _internalSub; final Output Function() _read; - var _closed = false; + final void Function()? onClose; @override void close() { - _closed = true; - _internalSub.close(); + if (!closed) { + onClose?.call(); + _internalSub.close(); + } + super.close(); } @override Output read() { - if (_closed) { + if (closed) { throw StateError( 'called ProviderSubscription.read on a subscription that was closed', ); diff --git a/packages/riverpod/lib/src/listenable.dart b/packages/riverpod/lib/src/listenable.dart index 06de51841..607e19da9 100644 --- a/packages/riverpod/lib/src/listenable.dart +++ b/packages/riverpod/lib/src/listenable.dart @@ -17,6 +17,7 @@ class _Listener { /// A listenable object used by [ProviderElementBase] as a mean to subscribe /// to subsets of the state exposed by a provider. @internal +@optionalTypeArgs class ProxyElementValueNotifier extends _ValueListenable { /// Directly obtain the value exposed, gratefully handling cases where /// [result] is null or in error state. diff --git a/packages/riverpod/lib/src/notifier/base.dart b/packages/riverpod/lib/src/notifier/base.dart index 2251a94aa..d0e2b691a 100644 --- a/packages/riverpod/lib/src/notifier/base.dart +++ b/packages/riverpod/lib/src/notifier/base.dart @@ -205,9 +205,8 @@ class NotifierProviderElement, T> @override void visitChildren({ - required void Function(ProviderElementBase element) elementVisitor, - required void Function(ProxyElementValueNotifier element) - notifierVisitor, + required void Function(ProviderElementBase element) elementVisitor, + required void Function(ProxyElementValueNotifier element) notifierVisitor, }) { super.visitChildren( elementVisitor: elementVisitor, diff --git a/packages/riverpod/lib/src/state_notifier_provider/base.dart b/packages/riverpod/lib/src/state_notifier_provider/base.dart index 8c560dc94..bf9c9d816 100644 --- a/packages/riverpod/lib/src/state_notifier_provider/base.dart +++ b/packages/riverpod/lib/src/state_notifier_provider/base.dart @@ -194,9 +194,8 @@ class StateNotifierProviderElement, T> @override void visitChildren({ - required void Function(ProviderElementBase element) elementVisitor, - required void Function(ProxyElementValueNotifier element) - notifierVisitor, + required void Function(ProviderElementBase element) elementVisitor, + required void Function(ProxyElementValueNotifier element) notifierVisitor, }) { super.visitChildren( elementVisitor: elementVisitor, diff --git a/packages/riverpod/lib/src/state_provider/base.dart b/packages/riverpod/lib/src/state_provider/base.dart index c33a5a604..b7d54657c 100644 --- a/packages/riverpod/lib/src/state_provider/base.dart +++ b/packages/riverpod/lib/src/state_provider/base.dart @@ -161,9 +161,8 @@ class StateProviderElement extends ProviderElementBase @override void visitChildren({ - required void Function(ProviderElementBase element) elementVisitor, - required void Function(ProxyElementValueNotifier element) - notifierVisitor, + required void Function(ProviderElementBase element) elementVisitor, + required void Function(ProxyElementValueNotifier element) notifierVisitor, }) { super.visitChildren( elementVisitor: elementVisitor, diff --git a/packages/riverpod/lib/src/stream_provider/base.dart b/packages/riverpod/lib/src/stream_provider/base.dart index f61f61a10..12c1fa098 100644 --- a/packages/riverpod/lib/src/stream_provider/base.dart +++ b/packages/riverpod/lib/src/stream_provider/base.dart @@ -176,9 +176,8 @@ class StreamProviderElement extends ProviderElementBase> @override void visitChildren({ - required void Function(ProviderElementBase element) elementVisitor, - required void Function(ProxyElementValueNotifier element) - notifierVisitor, + required void Function(ProviderElementBase element) elementVisitor, + required void Function(ProxyElementValueNotifier element) notifierVisitor, }) { super.visitChildren( elementVisitor: elementVisitor, diff --git a/packages/riverpod/pubspec.yaml b/packages/riverpod/pubspec.yaml index b31701db0..1e69f7b40 100644 --- a/packages/riverpod/pubspec.yaml +++ b/packages/riverpod/pubspec.yaml @@ -2,7 +2,7 @@ name: riverpod description: > A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze. -version: 2.5.0 +version: 2.5.1 homepage: https://riverpod.dev repository: https://github.com/rrousselGit/riverpod issue_tracker: https://github.com/rrousselGit/riverpod/issues @@ -10,9 +10,10 @@ funding: - https://github.com/sponsors/rrousselGit/ environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: + collection: ^1.18.0 meta: ^1.9.0 stack_trace: ^1.10.0 state_notifier: ">=0.7.2 <2.0.0" diff --git a/packages/riverpod/test/framework/listen_test.dart b/packages/riverpod/test/framework/listen_test.dart index 326827b4f..9c5cf04c6 100644 --- a/packages/riverpod/test/framework/listen_test.dart +++ b/packages/riverpod/test/framework/listen_test.dart @@ -1469,8 +1469,11 @@ void main() { final container = createContainer(); final listener = Listener(); - final sub = - container.listen(provider, listener.call, fireImmediately: true); + final sub = container.listen( + provider, + listener.call, + fireImmediately: true, + ); verify(listener(null, 0)).called(1); verifyNoMoreInteractions(listener); diff --git a/packages/riverpod/test/framework/modifiers_test.dart b/packages/riverpod/test/framework/modifiers_test.dart index 44dddfb92..c8df4cc1a 100644 --- a/packages/riverpod/test/framework/modifiers_test.dart +++ b/packages/riverpod/test/framework/modifiers_test.dart @@ -1,9 +1,82 @@ // ignore_for_file: prefer_const_constructors +import 'package:mockito/mockito.dart'; import 'package:riverpod/riverpod.dart'; import 'package:riverpod/src/builders.dart'; import 'package:test/test.dart'; +import '../utils.dart'; + void main() { + group('_ProxySubscription', () { + group('read', () { + test('throws if used after close', () { + final container = createContainer(); + final provider = FutureProvider((ref) async => 0); + + final sub = container.listen(provider.future, (prev, value) {}); + sub.close(); + + expect( + sub.read, + throwsStateError, + ); + }); + }); + }); + + test('Listening to a modifier correctly fires ref life-cycles', () async { + final container = createContainer(); + final onDispose = OnDisposeMock(); + final onAddListener = OnAddListener(); + final onRemoveListener = OnRemoveListener(); + final onResume = OnResume(); + final onCancel = OnCancelMock(); + + final provider = FutureProvider((ref) { + ref.onDispose(onDispose.call); + ref.onAddListener(onAddListener.call); + ref.onRemoveListener(onRemoveListener.call); + ref.onCancel(onCancel.call); + ref.onResume(onResume.call); + return 0; + }); + + final sub = container.listen(provider.future, (prev, value) {}); + + verifyOnly(onAddListener, onAddListener()); + + final sub2 = container.listen(provider.future, (prev, value) {}); + + verifyOnly(onAddListener, onAddListener()); + + sub.close(); + + verifyOnly(onRemoveListener, onRemoveListener()); + verifyZeroInteractions(onCancel); + + sub2.close(); + + verifyOnly(onRemoveListener, onRemoveListener()); + verifyZeroInteractions(onResume); + verifyOnly(onCancel, onCancel()); + + container.listen(provider.future, (prev, value) {}); + + verifyOnly(onAddListener, onAddListener()); + verifyOnly(onResume, onResume()); + + container.listen(provider.future, (prev, value) {}); + + verifyOnly(onAddListener, onAddListener()); + verifyNoMoreInteractions(onCancel); + verifyNoMoreInteractions(onResume); + verifyZeroInteractions(onDispose); + + container.invalidate(provider); + + verifyOnly(onDispose, onDispose()); + }); + test('builders', () { expect(Provider.autoDispose.family, Provider.family.autoDispose); expect( diff --git a/packages/riverpod/test/framework/provider_container_test.dart b/packages/riverpod/test/framework/provider_container_test.dart index b110fe0ef..b9a44e9a7 100644 --- a/packages/riverpod/test/framework/provider_container_test.dart +++ b/packages/riverpod/test/framework/provider_container_test.dart @@ -7,6 +7,23 @@ import '../utils.dart'; void main() { group('ProviderContainer', () { + group('invalidate', () { + test('can disposes of the element if not used anymore', () async { + final provider = Provider.autoDispose((r) { + r.keepAlive(); + return 0; + }); + final container = createContainer(); + + container.read(provider); + container.invalidate(provider); + + await container.pump(); + + expect(container.getAllProviderElements(), isEmpty); + }); + }); + test('Supports unmounting containers in reverse order', () { final container = createContainer(); diff --git a/packages/riverpod/test/framework/provider_element_test.dart b/packages/riverpod/test/framework/provider_element_test.dart index 2ef4471e5..b5ced8dd5 100644 --- a/packages/riverpod/test/framework/provider_element_test.dart +++ b/packages/riverpod/test/framework/provider_element_test.dart @@ -140,11 +140,11 @@ void main() { test('Throws if a circular dependency is detected', () { // Regression test for https://github.com/rrousselGit/riverpod/issues/2336 late Ref ref; - final a = Provider((r) { + final a = Provider(name: 'a', (r) { ref = r; return 0; }); - final b = Provider((r) => r.watch(a)); + final b = Provider(name: 'b', (r) => r.watch(a)); final container = createContainer(); container.read(b); @@ -572,13 +572,10 @@ void main() { final container = createContainer(); final listener = OnAddListener(); final listener2 = OnAddListener(); - final dep = Provider( - name: 'dep', - (ref) { - ref.onAddListener(listener.call); - ref.onAddListener(listener2.call); - }, - ); + final dep = Provider(name: 'dep', (ref) { + ref.onAddListener(listener.call); + ref.onAddListener(listener2.call); + }); late Ref ref; final provider = Provider( name: 'provider', diff --git a/packages/riverpod/test/framework/ref_test.dart b/packages/riverpod/test/framework/ref_test.dart index 793defd4a..1ec8938b6 100644 --- a/packages/riverpod/test/framework/ref_test.dart +++ b/packages/riverpod/test/framework/ref_test.dart @@ -6,6 +6,51 @@ import '../utils.dart'; void main() { group('Ref', () { + group('invalidateSelf', () { + test('can disposes of the element if not used anymore', () async { + late Ref ref; + final provider = Provider.autoDispose((r) { + ref = r; + r.keepAlive(); + return 0; + }); + final container = createContainer(); + + container.read(provider); + ref.invalidateSelf(); + + await container.pump(); + + expect(container.getAllProviderElements(), isEmpty); + }); + }); + + group('invalidate', () { + test('can disposes of the element if not used anymore', () async { + late Ref ref; + final dep = Provider((r) { + ref = r; + return 0; + }); + final provider = Provider.autoDispose((r) { + r.keepAlive(); + return 0; + }); + final container = createContainer(); + + container.read(dep); + container.read(provider); + ref.invalidate(provider); + + await container.pump(); + + expect( + container.getAllProviderElements().map((e) => e.origin), + [dep], + ); + }); + }); + test( 'cannot call ref.watch/ref.read/ref.listen/ref.onDispose after a dependency changed', () { diff --git a/packages/riverpod/test/framework/select_async_test.dart b/packages/riverpod/test/framework/select_async_test.dart index 3c42c142c..e984d2aca 100644 --- a/packages/riverpod/test/framework/select_async_test.dart +++ b/packages/riverpod/test/framework/select_async_test.dart @@ -7,6 +7,40 @@ import 'package:test/test.dart'; import '../utils.dart'; void main() { + group('If disposed before a value could be emitted', () { + test('resolves values with `sub.read()`', () async { + final container = createContainer(); + final controller = StreamController(); + final provider = Provider((ref) => ref); + addTearDown(controller.close); + final dep = StreamProvider((ref) => controller.stream); + + final ref = container.read(provider); + final future = ref.watch(dep.selectAsync((data) => data * 2)); + + container.invalidate(provider); + controller.add(21); + + expect(await future, 42); + }); + + test('resolves errors with `sub.read()`', () async { + final container = createContainer(); + final controller = StreamController(); + final provider = Provider((ref) => ref); + addTearDown(controller.close); + final dep = StreamProvider((ref) => controller.stream); + + final ref = container.read(provider); + final future = ref.watch(dep.selectAsync((data) => data * 2)); + + container.invalidate(provider); + controller.addError('err'); + + await expectLater(future, throwsA('err')); + }); + }); + test('implements ProviderSubscription.read on AsyncData', () async { final container = createContainer(); final dep = StateProvider((ref) => 0); diff --git a/packages/riverpod/test/providers/future_provider/future_provider_test.dart b/packages/riverpod/test/providers/future_provider/future_provider_test.dart index 263e5888e..0857d0b83 100644 --- a/packages/riverpod/test/providers/future_provider/future_provider_test.dart +++ b/packages/riverpod/test/providers/future_provider/future_provider_test.dart @@ -10,6 +10,72 @@ import '../../utils.dart'; void main() { group('FutureProviderRef.future', () { + test( + '.future does not immediately notify listeners when adding a new listener ' + 'to .future flushes the provider', () async { + // Regression test for https://github.com/rrousselGit/riverpod/issues/2041 + + final container = createContainer(); + final onFuture = Listener>(); + + final dep = FutureProvider((ref) => 0); + final provider = Provider( + (ref) { + ref.listen(dep.future, onFuture.call); + return 0; + }, + ); + + container.read(dep); + container.invalidate(dep); + + container.read(provider); + + verifyZeroInteractions(onFuture); + }); + + test('Regression 2041', () async { + final container = createContainer(); + final onFuture = Listener>(); + + final testNotifierProvider = FutureProvider.autoDispose((ref) => 0); + // ProxyProvider is never rebuild directly, but rather indirectly through + // testNotifierProvider. This means the scheduler does not naturally cover it. + // Then testProvider is the one to trigger the rebuild by listening to it. + final proxyProvider = FutureProvider.autoDispose( + (ref) => ref.watch(testNotifierProvider.future), + ); + + var buildCount = 0; + final testProvider = FutureProvider.autoDispose( + (ref) async { + buildCount++; + return (await ref.watch(proxyProvider.future)) + 2; + }, + ); + + container.listen>( + testProvider, + (previous, next) { + if (!next.isLoading && next is AsyncError) { + Zone.current.handleUncaughtError(next.error, next.stackTrace); + } + }, + fireImmediately: true, + ); + + container.invalidate(testNotifierProvider); + container.invalidate(testProvider); + + verifyZeroInteractions(onFuture); + expect(buildCount, 1); + + await container.pump(); + verifyZeroInteractions(onFuture); + + expect(buildCount, 2); + }); + test('returns the pending future', () async { final container = createContainer(); Future? future; diff --git a/packages/riverpod_analyzer_utils_tests/pubspec.yaml b/packages/riverpod_analyzer_utils_tests/pubspec.yaml index 05e2120e7..22ae01a60 100644 --- a/packages/riverpod_analyzer_utils_tests/pubspec.yaml +++ b/packages/riverpod_analyzer_utils_tests/pubspec.yaml @@ -3,7 +3,7 @@ description: A sample command-line application. publish_to: none environment: - sdk: ">=2.18.0 <3.0.0" + sdk: ">=2.18.0 <4.0.0" dependencies: analyzer: ">=5.12.0 <7.0.0" diff --git a/packages/riverpod_annotation/CHANGELOG.md b/packages/riverpod_annotation/CHANGELOG.md index 1d38faff4..822875625 100644 --- a/packages/riverpod_annotation/CHANGELOG.md +++ b/packages/riverpod_annotation/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.5 - 2024-03-10 + +- `riverpod` upgraded to `2.5.1` + ## 2.3.4 - 2024-02-03 - Improved `@Riverpod(dependencies: [...])` documentation. diff --git a/packages/riverpod_annotation/pubspec.yaml b/packages/riverpod_annotation/pubspec.yaml index b298a8248..3c5770b25 100644 --- a/packages/riverpod_annotation/pubspec.yaml +++ b/packages/riverpod_annotation/pubspec.yaml @@ -1,17 +1,17 @@ name: riverpod_annotation description: A package exposing annotations for riverpod_generator -version: 2.3.4 +version: 2.3.5 repository: https://github.com/rrousselGit/riverpod issue_tracker: https://github.com/rrousselGit/riverpod/issues funding: - https://github.com/sponsors/rrousselGit/ environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: meta: ^1.7.0 - riverpod: ^2.5.0 + riverpod: 2.5.1 dev_dependencies: test: ^1.21.0 diff --git a/packages/riverpod_generator/CHANGELOG.md b/packages/riverpod_generator/CHANGELOG.md index 77ab76649..69f3ad77a 100644 --- a/packages/riverpod_generator/CHANGELOG.md +++ b/packages/riverpod_generator/CHANGELOG.md @@ -1,4 +1,4 @@ -## Unreleased minor +## 2.4.0 - 2024-03-10 - Adds `provider_name_prefix` and `provider_family_name_prefix` to `build.yaml`. (thanks to @ValentinVignal) diff --git a/packages/riverpod_generator/integration/build_yaml/pubspec.yaml b/packages/riverpod_generator/integration/build_yaml/pubspec.yaml index 519d94960..595226515 100644 --- a/packages/riverpod_generator/integration/build_yaml/pubspec.yaml +++ b/packages/riverpod_generator/integration/build_yaml/pubspec.yaml @@ -3,7 +3,7 @@ description: A sample command-line application. publish_to: none environment: - sdk: ">=2.18.4 <3.0.0" + sdk: ">=2.18.4 <4.0.0" dependencies: riverpod: diff --git a/packages/riverpod_generator/pubspec.yaml b/packages/riverpod_generator/pubspec.yaml index 1bd4e6f23..f28301ba8 100644 --- a/packages/riverpod_generator/pubspec.yaml +++ b/packages/riverpod_generator/pubspec.yaml @@ -1,13 +1,13 @@ name: riverpod_generator description: A code generator for Riverpod. This both simplifies the syntax empowers it, such as allowing stateful hot-reload. -version: 2.3.11 +version: 2.4.0 repository: https://github.com/rrousselGit/riverpod issue_tracker: https://github.com/rrousselGit/riverpod/issues funding: - https://github.com/sponsors/rrousselGit/ environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: analyzer: ">=5.12.0 <7.0.0" @@ -18,11 +18,11 @@ dependencies: meta: ^1.7.0 path: ^1.8.0 riverpod_analyzer_utils: ^0.5.1 - riverpod_annotation: ^2.3.4 + riverpod_annotation: ^2.3.5 source_gen: ^1.2.0 dev_dependencies: build_runner: ^2.1.7 build_verify: ^3.0.0 - riverpod: ^2.5.0 + riverpod: 2.5.1 test: ^1.21.0 diff --git a/packages/riverpod_graph/pubspec.yaml b/packages/riverpod_graph/pubspec.yaml index 398580f10..0c7db8b4f 100644 --- a/packages/riverpod_graph/pubspec.yaml +++ b/packages/riverpod_graph/pubspec.yaml @@ -8,7 +8,7 @@ funding: - https://github.com/sponsors/rrousselGit/ environment: - sdk: ">=2.15.0 <3.0.0" + sdk: ">=2.15.0 <4.0.0" dependencies: analyzer: ">=5.12.0 <7.0.0" diff --git a/packages/riverpod_lint/CHANGELOG.md b/packages/riverpod_lint/CHANGELOG.md index 1f18b4f16..e432d02ac 100644 --- a/packages/riverpod_lint/CHANGELOG.md +++ b/packages/riverpod_lint/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.10 - 2024-03-10 + +- `riverpod` upgraded to `2.5.1` + ## 2.3.9 - 2024-02-04 - Bumped `custom_lint` version diff --git a/packages/riverpod_lint/pubspec.yaml b/packages/riverpod_lint/pubspec.yaml index bacedbcfd..533647aca 100644 --- a/packages/riverpod_lint/pubspec.yaml +++ b/packages/riverpod_lint/pubspec.yaml @@ -1,6 +1,6 @@ name: riverpod_lint description: Riverpod_lint is a developer tool for users of Riverpod, designed to help stop common issues and simplify repetitive tasks. -version: 2.3.9 +version: 2.3.10 homepage: https://riverpod.dev repository: https://github.com/rrousselGit/river_pod issue_tracker: https://github.com/rrousselGit/riverpod/issues @@ -8,7 +8,7 @@ funding: - https://github.com/sponsors/rrousselGit/ environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: analyzer: ">=6.0.0 <7.0.0" @@ -17,7 +17,7 @@ dependencies: custom_lint_builder: ^0.6.0 meta: ^1.7.0 path: ^1.8.1 - riverpod: ^2.5.0 + riverpod: ^2.5.1 riverpod_analyzer_utils: ^0.5.1 source_span: ^1.8.0 yaml: ^3.1.1 diff --git a/packages/riverpod_lint_flutter_test/pubspec_overrides.yaml b/packages/riverpod_lint_flutter_test/pubspec_overrides.yaml index 4f0b94b08..56aa97964 100644 --- a/packages/riverpod_lint_flutter_test/pubspec_overrides.yaml +++ b/packages/riverpod_lint_flutter_test/pubspec_overrides.yaml @@ -14,6 +14,3 @@ dependency_overrides: path: ../riverpod_annotation riverpod_lint: path: ../riverpod_lint - - # hotreloader is out of date - vm_service: ^14.0.0 diff --git a/packages/riverpod_lint_flutter_test/test/lints/scoped_providers_should_specify_dependencies.dart b/packages/riverpod_lint_flutter_test/test/lints/scoped_providers_should_specify_dependencies.dart index b73dea166..cdff93e36 100644 --- a/packages/riverpod_lint_flutter_test/test/lints/scoped_providers_should_specify_dependencies.dart +++ b/packages/riverpod_lint_flutter_test/test/lints/scoped_providers_should_specify_dependencies.dart @@ -65,6 +65,7 @@ void main() { flutter.runApp( ProviderScope( + // ignore: deprecated_member_use parent: rootContainer, overrides: [ scopedProvider.overrideWith((ref) => 0), @@ -110,6 +111,7 @@ void definitelyNotAMain() { flutter.runApp( ProviderScope( + // ignore: deprecated_member_use parent: rootContainer, overrides: [ scopedProvider.overrideWith((ref) => 0), @@ -145,6 +147,7 @@ void someTestFunction() { await tester.pumpWidget( ProviderScope( + // ignore: deprecated_member_use parent: rootContainer, overrides: [ scopedProvider.overrideWith((ref) => 0), diff --git a/pubspec.yaml b/pubspec.yaml index 671355da8..79f43313c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,6 +2,6 @@ name: melos_root publish_to: none environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dev_dependencies: melos: ^3.0.0 diff --git a/website/docs/concepts/dialog_scope.dart b/website/docs/concepts/dialog_scope.dart deleted file mode 100644 index 4ee7792f9..000000000 --- a/website/docs/concepts/dialog_scope.dart +++ /dev/null @@ -1,58 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// Have a counter that is being incremented by the FloatingActionButton -final counterProvider = StateProvider((ref) => 0); - -class Home extends ConsumerWidget { - const Home({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // We want to show a dialog with the count on a button press - return Scaffold( - body: Column( - children: [ - ElevatedButton( - onPressed: () { - showDialog( - context: context, - builder: (c) { - // We wrap the dialog with a ProviderScope widget, providing the - // parent container to ensure the dialog can access the same providers - // that are accessible by the Home widget. - return ProviderScope( - parent: ProviderScope.containerOf(context), - child: const AlertDialog( - content: CounterDisplay(), - ), - ); - }, - ); - }, - child: const Text('Show Dialog'), - ), - ], - ), - floatingActionButton: FloatingActionButton( - child: const Icon(Icons.add), - onPressed: () { - ref.read(counterProvider.notifier).state++; - }, - )); - } -} - -class CounterDisplay extends ConsumerWidget { - const CounterDisplay({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final count = ref.watch(counterProvider); - return Text('$count'); - } -} diff --git a/website/docs/concepts/scopes.mdx b/website/docs/concepts/scopes.mdx index f1c397c2e..ec97f6ec6 100644 --- a/website/docs/concepts/scopes.mdx +++ b/website/docs/concepts/scopes.mdx @@ -5,7 +5,6 @@ version: 1 import CodeBlock from "@theme/CodeBlock"; import asyncInitialization from "!!raw-loader!/docs/concepts/async_initialization.dart"; -import dialogScope from "!!raw-loader!/docs/concepts/dialog_scope.dart"; import themeScope from "!!raw-loader!/docs/concepts/theme_scope.dart"; import subtreeScope from "!!raw-loader!/docs/concepts/subtree_scope.dart"; import { trimSnippet } from "/src/components/CodeSnippet"; @@ -90,18 +89,6 @@ Here is an example that shows how scoping allows you override a dummy provider w {trimSnippet(asyncInitialization)} -## Showing Dialogs - -When you show a `Dialog` or `OverlayEntry`, flutter creates a new `Route` or adds to an `Overlay` that has a different build scope, -so that it can escape the layout of it's parent, and can be shown above other `Routes`. -This presents a problem for `InheritedWidget`s in general, and since [ProviderScope] is an `InheritedWidget`, it is also affected. - -To solve this problem, Riverpod allows you to create a `ProviderScope` that can access the state of all providers in a `parent` scope. - -The following example shows how to use this, to allow a `Dialog` to access the state of a counter from the context that caused the `Dialog` to be shown. - -{trimSnippet(dialogScope)} - ## Subtree Scoping Scoping allows you to override the state of a provider for a specific subtree of your widget tree. diff --git a/website/docs/from_provider/quickstart.mdx b/website/docs/from_provider/quickstart.mdx index 995934b62..820d2e247 100644 --- a/website/docs/from_provider/quickstart.mdx +++ b/website/docs/from_provider/quickstart.mdx @@ -46,7 +46,7 @@ and it is not the best way to use Riverpod, but it's a gentle and very easy way :::tip There is no rush to *immediately* try to change your `ChangeNotifier`s into the more modern [Riverpod's providers]. -Some requite a bit of a paradigm shift, so it may be difficult to do initially. +Some require a bit of a paradigm shift, so it may be difficult to do initially. Take your time, as it is important to get yourself familiar with Riverpod first; you'll quickly find out that *almost* all Providers from pkg:provider have a strict equivalent in pkg:riverpod. @@ -66,7 +66,7 @@ This should boost and simplify the migration process, while also minimizing / tr *Keep in mind that it is entirely possible to use both Provider and Riverpod at the same time.* Indeed, using import aliases, it is possible to use the two APIs altogether. -This is also great for readibilty and it removes any ambiguous API usage. +This is also great for readability and it removes any ambiguous API usage. If you plan on doing this, consider using import aliases for each Provider import in your codebase. @@ -131,7 +131,7 @@ you'll simply need to write `ref.watch` if you want to declare a direct dependen If anything, combining values with Riverpod should feel simpler and straightforward; thus, the migration should greatly simplify your code. -Furthermore, there are no shanenigans about combining more than two providers together: +Furthermore, there are no shenanigans about combining more than two providers together: just add another `ref.watch` and you'll be good to go. ## Eager initialization diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx b/website/i18n/bn/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx index 476559149..0187b6666 100644 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx +++ b/website/i18n/bn/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx @@ -3,7 +3,7 @@ title: প্রভাইডার অবসার্বার --- import CodeBlock from "@theme/CodeBlock"; -import logger from "!!raw-loader!./provider_observer_logger.dart"; +import logger from "!!raw-loader!/docs/concepts/provider_observer_logger.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; [ProviderObserver] একটি ProviderContainer এর পরিবর্তন লিসেন করে। diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/concepts/provider_observer_logger.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/concepts/provider_observer_logger.dart deleted file mode 100644 index 0d801dbce..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/concepts/provider_observer_logger.dart +++ /dev/null @@ -1,61 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// লগারের সাথে রিভারপডের সাথে বাস্তবায়িত একটি কাউন্টার উদাহরণ - -class Logger extends ProviderObserver { - @override - void didUpdateProvider( - ProviderBase provider, - Object? previousValue, - Object? newValue, - ProviderContainer container, - ) { - print(''' -{ - "provider": "${provider.name ?? provider.runtimeType}", - "newValue": "$newValue" -}'''); - } -} - -void main() { - runApp( - // ProviderScope যোগ করা পুরো প্রকল্পের জন্য রিভারপডকে সক্ষম করে - // observers এর তালিকায় আমাদের লগার যুক্ত করা হচ্ছে - ProviderScope(observers: [Logger()], child: const MyApp()), - ); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp(home: Home()); - } -} - -final counterProvider = StateProvider((ref) => 0, name: 'counter'); - -class Home extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final count = ref.watch(counterProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Counter example')), - body: Center( - child: Text('$count'), - ), - floatingActionButton: FloatingActionButton( - onPressed: () => ref.read(counterProvider.notifier).state++, - child: const Icon(Icons.add), - ), - ); - } -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx index 7ecb7fe03..52533b41b 100644 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx +++ b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx @@ -5,13 +5,13 @@ title: টেস্টিং import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import testingOriginalTestFlutter from "!!raw-loader!./testing_original_test_flutter.dart"; -import testingOriginalTestDart from "!!raw-loader!./testing_original_test_dart.dart"; -import repositorySnippet from "!!raw-loader!./testing_repository.dart"; -import testFlutter from "!!raw-loader!./testing_flutter.dart"; -import testDart from "!!raw-loader!./testing_dart.dart"; -import testFull from "!!raw-loader!./testing_full.dart"; -import testOverrideInfo from "!!raw-loader!./testing_override_info.dart"; +import testingOriginalTestFlutter from "!!raw-loader!/docs/cookbooks/testing_original_test_flutter.dart"; +import testingOriginalTestDart from "!!raw-loader!/docs/cookbooks/testing_original_test_dart.dart"; +import repositorySnippet from "!!raw-loader!/docs/cookbooks/testing_repository.dart"; +import testFlutter from "!!raw-loader!/docs/cookbooks/testing_flutter.dart"; +import testDart from "!!raw-loader!/docs/cookbooks/testing_dart.dart"; +import testFull from "!!raw-loader!/docs/cookbooks/testing_full.dart"; +import testOverrideInfo from "!!raw-loader!/docs/cookbooks/testing_override_info.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_dart.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_dart.dart deleted file mode 100644 index d9f880273..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_dart.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class FakeRepository {} - -final repositoryProvider = Provider((ref) => FakeRepository()); - -abstract class Todo { - String get id; - String get label; - bool get completed; -} - -final todoListProvider = FutureProvider>((ref) => []); - -void main() { -/* SNIPPET START */ - - test('override repositoryProvider', () async { - final container = ProviderContainer( - overrides: [ - // repositoryProvider এর আচরণ পরিবর্তন করে - // FakeRepository রিটার্ন করবে আসল Repository এর বদলে - /* highlight-start */ - repositoryProvider.overrideWithValue(FakeRepository()) - /* highlight-end */ - // আমাদের `todoListProvider` প্রভাইডার ওভাররাইড করার প্রয়োজন নেই, - // এটি অটোমেটিকলী ওভাররাইডেন repositoryProvider ব্যবহার করবে - ], - ); - - // প্রথম রিড, লোডিং স্ট্যাটাস কিনা চেক হচ্ছে - expect( - container.read(todoListProvider), - const AsyncValue>.loading(), - ); - - /// রিকুয়েস্ট শেষ হওয়ার জন্য অপেক্ষা চলতেছে - await container.read(todoListProvider.future); - - // ফেচ হওয়া ডাটা এক্সপোস করবে - expect(container.read(todoListProvider).value, [ - isA() - .having((s) => s.id, 'id', '42') - .having((s) => s.label, 'label', 'Hello world') - .having((s) => s.completed, 'completed', false), - ]); - }); - -/* SNIPPET END */ -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_flutter.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_flutter.dart deleted file mode 100644 index 36ff78123..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_flutter.dart +++ /dev/null @@ -1,40 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class MyApp extends StatelessWidget { - // ignore: prefer_const_constructors_in_immutables - MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return Container(); - } -} - -final repositoryProvider = Provider((ref) => FakeRepository()); - -class FakeRepository {} - -void main() { -/* SNIPPET START */ - - testWidgets('override repositoryProvider', (tester) async { - await tester.pumpWidget( - ProviderScope( - overrides: [ - // repositoryProvider এর আচরণ পরিবর্তন করে - // FakeRepository রিটার্ন করবে আসল Repository এর বদলে - /* highlight-start */ - repositoryProvider.overrideWithValue(FakeRepository()) - /* highlight-end */ - // আমাদের `todoListProvider` প্রভাইডার ওভাররাইড করার প্রয়োজন নেই, - // এটি অটোমেটিকলী ওভাররাইডেন repositoryProvider ব্যবহার করবে - ], - child: MyApp(), - ), - ); - }); - -/* SNIPPET END */ -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_full.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_full.dart deleted file mode 100644 index 128e211f7..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_full.dart +++ /dev/null @@ -1,96 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class Repository { - Future> fetchTodos() async => []; -} - -class Todo { - Todo({ - required this.id, - required this.label, - required this.completed, - }); - - final String id; - final String label; - final bool completed; -} - -// আমরা আমাদের ইন্সটেন্স একটি প্রভাইডার এ এক্সপোস করলাম -final repositoryProvider = Provider((ref) => Repository()); - -/// টুডুস গুলার তালিকা. আমরা এখানে এটি খুব সাধারণ ভাবে সার্ভার থেকে ফেচ করতেছি -/// [Repository] ব্যবহার করে এবং এখানে আমরা আর কিছু করতেছি না। -final todoListProvider = FutureProvider((ref) async { - // রিপোসেটোরি এর ইন্সট্যান্স নিলাম - final repository = ref.read(repositoryProvider); - - // টুডু গুলা ফেচ করলাম, এবং তা ইউয়াই (UI) তে এক্সপোস করে দিলাম - return repository.fetchTodos(); -}); - -/// একটি রিপোসোটোরী এর মকেড ইমপ্লেমেন্টেশন যেটি একটি পূর্ব নির্ধারিত টুডু লিস্ট রিটার্ন করে -class FakeRepository implements Repository { - @override - Future> fetchTodos() async { - return [ - Todo(id: '42', label: 'Hello world', completed: false), - ]; - } -} - -class TodoItem extends StatelessWidget { - const TodoItem({super.key, required this.todo}); - final Todo todo; - @override - Widget build(BuildContext context) { - return Text(todo.label); - } -} - -void main() { - testWidgets('override repositoryProvider', (tester) async { - await tester.pumpWidget( - ProviderScope( - overrides: [repositoryProvider.overrideWithValue(FakeRepository())], - // আমাদের এপ্লিকেশন, যেটি todoListProvider থেকে রিড করবে todo-list ডিসপ্লে করার জন্যে - // আপনি এটি এক্সট্রেক্ট অথবা রিফেক্টর করে MyApp উইজেট করতে পারেন - child: MaterialApp( - home: Scaffold( - body: Consumer(builder: (context, ref, _) { - final todos = ref.watch(todoListProvider); - // টুডুস গুলার তালিকা, এটা কি Error না কি Loading এ আছে - if (todos.asData == null) { - return const CircularProgressIndicator(); - } - return ListView( - children: [ - for (final todo in todos.asData!.value) TodoItem(todo: todo) - ], - ); - }), - ), - ), - ), - ); - - // প্রথম ফ্রেমটি হচ্ছে লোডিং স্ট্যাট (Loading) - expect(find.byType(CircularProgressIndicator), findsOneWidget); - - // রি-রেন্ডার. TodoListProvider এতক্ষণে টুডুস গুলা ফেচ করার কাজ শেষ করে ফেলেছে - await tester.pump(); - - // লোডিং আর থাকবে না - expect(find.byType(CircularProgressIndicator), findsNothing); - - // একটি TodoItem রেন্ডার হয়েছে, যে ডাটা গুলা FakeRepository দ্বারা রিটার্ন করা হয়েছে - expect(tester.widgetList(find.byType(TodoItem)), [ - isA() - .having((s) => s.todo.id, 'todo.id', '42') - .having((s) => s.todo.label, 'todo.label', 'Hello world') - .having((s) => s.todo.completed, 'todo.completed', false), - ]); - }); -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_dart.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_dart.dart deleted file mode 100644 index 86a9b7977..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_dart.dart +++ /dev/null @@ -1,64 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ - -// একটি কাউন্টার ইমপ্লিমেন্ট এবং টেস্টেড শুধুমাত্র ডার্ট ব্যবহার করে (ফ্লাটার এর উপর নির্ভর না হয়ে) - -// আমরা প্রভাইডার গ্লোবালি ডিক্লার করেছি, এবং আমরা এটি দুইটি টেস্ট এ ব্যবহার করব, এটি দেখার জন্য যে, -// স্টেটটা সঠিকভাবে '0' তে রিসেট হই কিনা, টেস্টগুলার মধ্যে - -final counterProvider = StateProvider((ref) => 0); - -// এখানে mockito ব্যবহার করা হচ্ছে, এটি ট্র্যাক করার জন্য যে কখন একটি প্রভাইডার -// লিসেনার গুলা কে নটিফাই করে -class Listener extends Mock { - void call(int? previous, int value); -} - -void main() { - test('defaults to 0 and notify listeners when value changes', () { - // একটি অবজেক্ট যা আমাদের প্রভাডার রিড করতে সাহায্য করবে - // টেস্ট এর মাঝে এটি কখনো শেয়ার করবেন না. - final container = ProviderContainer(); - addTearDown(container.dispose); - final listener = Listener(); - - // একটি প্রভাইডার অবসারব করে এবং পরির্বতন গুলা গোয়েন্দাগিরি করে - container.listen( - counterProvider, - listener.call, - fireImmediately: true, - ); - - // এই লিসেনারটা সাথে সাথে কল হবে 0 এর সাথে, যেটি ডিফল্ট ভ্যালু - verify(listener(null, 0)).called(1); - verifyNoMoreInteractions(listener); - - // আমরা ভ্যালু টা বাড়ালাম - container.read(counterProvider.notifier).state++; - - // লিসেনার আবার কল করা গেল তবে এবার '1' এর সাথে - verify(listener(0, 1)).called(1); - verifyNoMoreInteractions(listener); - }); - - test('the counter state is not shared between tests', () { - // আমরা এবার এখানে ভিন্ন ধরনের ProviderContainer ব্যবহার করব, প্রভাইডার রিড করার জন্য - // এটি আমাদের নিশ্চয়তা দেই যে, এখানে টেস্ট এর মধ্যে অন্য কোন স্টেট ব্যবহার হচ্ছে না - final container = ProviderContainer(); - addTearDown(container.dispose); - final listener = Listener(); - - container.listen( - counterProvider, - listener.call, - fireImmediately: true, - ); - - // নতুন টেস্ট সঠিকভাবে ডিফল্ট ভ্যালুটি ব্যবহার করে: 0 - verify(listener(null, 0)).called(1); - verifyNoMoreInteractions(listener); - }); -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_flutter.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_flutter.dart deleted file mode 100644 index 3e06a14d0..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_flutter.dart +++ /dev/null @@ -1,56 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -/* SNIPPET START */ - -// একটি কাউন্টার ইমপ্লিমেন্ট এবং টেস্টেড ফ্লাটার ব্যবহার করে - -// আমরা প্রভাইডার গ্লোবালি ডিক্লার করেছি, এবং আমরা এটি দুইটি টেস্ট এ ব্যবহার করব, এটি দেখার জন্য যে, -// স্টেটটা সঠিকভাবে '0' তে রিসেট হই কিনা, টেস্টগুলার মধ্যে - -final counterProvider = StateProvider((ref) => 0); - -// বর্তমান স্টেট রেন্ডার করে এবং একটি বাটন যেটি স্টেট বাড়ানোতে সহায়তা করে -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Consumer(builder: (context, ref, _) { - final counter = ref.watch(counterProvider); - return ElevatedButton( - onPressed: () => ref.read(counterProvider.notifier).state++, - child: Text('$counter'), - ); - }), - ); - } -} - -void main() { - testWidgets('update the UI when incrementing the state', (tester) async { - await tester.pumpWidget(ProviderScope(child: MyApp())); - - // ডিফল্ট মান হল `0`, যেটি প্রভাইডার দ্বারা ডিক্লার হয়েছে - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // স্টেট বাড়ান এবং আবার রেনডার করা - await tester.tap(find.byType(ElevatedButton)); - await tester.pump(); - - // স্টেট সঠিকভাবে বেড়েছে - expect(find.text('1'), findsOneWidget); - expect(find.text('0'), findsNothing); - }); - - testWidgets('the counter state is not shared between tests', (tester) async { - await tester.pumpWidget(ProviderScope(child: MyApp())); - - // স্টেটকে আবার `0` করা হল, কিন্তু কোন tearDown/setUp ছাড়াই - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - }); -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_override_info.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_override_info.dart deleted file mode 100644 index 38a80e15b..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_override_info.dart +++ /dev/null @@ -1,44 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -extension on ProviderBase { - // ignore: unused_element - Override overrideWithValue(Object? value) => throw UnimplementedError(); -} - -class Todo { - Todo({ - required String id, - required String label, - required bool completed, - }); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return Container(); - } -} - -/* SNIPPET START */ - -final todoListProvider = FutureProvider((ref) async => []); -// ... -/* SKIP */ -final foo = -/* SKIP END */ - ProviderScope( - overrides: [ - /// Allows overriding a FutureProvider to return a fixed value - /// একটি ফিক্সড ভ্যালু রিটার্ন করার অনুমতি আছে FutureProvider ওভাররাইড করে - todoListProvider.overrideWithValue( - AsyncValue.data([Todo(id: '42', label: 'Hello', completed: true)]), - ), - ], - child: const MyApp(), -); diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_repository.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_repository.dart deleted file mode 100644 index 7ffa5c646..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/cookbooks/testing_repository.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class Todo {} - -/* SNIPPET START */ - -class Repository { - Future> fetchTodos() async => []; -} - -// আমরা আমাদের রিপোসেটোরি এর ইন্সটেন্স-টি একটি প্রভাইডার এ এক্সপোস করলাম -final repositoryProvider = Provider((ref) => Repository()); - -/// টুডুস গুলার তালিকা. আমরা এখানে এটি খুব সাধারণ ভাবে সার্ভার থেকে ফেচ করতেছি -/// [Repository] ব্যবহার করে এবং এখানে আমরা আর কিছু করতেছি না। -final todoListProvider = FutureProvider((ref) async { - // রিপোসেটোরি এর ইন্সট্যান্স নিলাম - final repository = ref.watch(repositoryProvider); - - // টুডু গুলা ফেচ করলাম, এবং তা ইউয়াই (UI) তে এক্সপোস করে দিলাম - return repository.fetchTodos(); -}); diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/getting_started.mdx b/website/i18n/bn/docusaurus-plugin-content-docs/current/getting_started.mdx index c4b7a8893..74c74273e 100644 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/getting_started.mdx +++ b/website/i18n/bn/docusaurus-plugin-content-docs/current/getting_started.mdx @@ -44,7 +44,7 @@ import { trimSnippet } from "../../../../src/components/CodeSnippet"; ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -61,7 +61,7 @@ dependencies: ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -77,7 +77,7 @@ dependencies: ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" dependencies: riverpod: ^1.0.0-dev.10 diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/provider.mdx b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/provider.mdx index a4457edde..99e2564e6 100644 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/provider.mdx +++ b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/provider.mdx @@ -7,7 +7,7 @@ import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; import todo from "!!raw-loader!./provider/todo.dart"; import completedTodos from "!!raw-loader!./provider/completed_todos.dart"; -import todosConsumer from "!!raw-loader!./provider/todos_consumer.dart"; +import todosConsumer from "!!raw-loader!/docs/providers/provider/todos_consumer.dart"; import unoptimizedPreviousButton from "!!raw-loader!./provider/unoptimized_previous_button.dart"; import optimizedPreviousButton from "!!raw-loader!./provider/optimized_previous_button.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart deleted file mode 100644 index 5cb9b7ff4..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'completed_todos.dart'; - -Widget build() { -return -/* SNIPPET START */ -Consumer(builder: (context, ref, child) { - final completedTodos = ref.watch(completedTodosProvider); - // TODO show the todos using a ListView/GridView/.../* SKIP */ - return Container(); - /* SKIP END */ -}); -/* SNIPPET END */ -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx index 6eb09bace..01acb520f 100644 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx +++ b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx @@ -5,8 +5,8 @@ title: StateNotifierProvider import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import todos from "!!raw-loader!./state_notifier_provider/todos.dart"; -import todosConsumer from "!!raw-loader!./state_notifier_provider/todos_consumer.dart"; +import todos from "!!raw-loader!/docs/providers/state_notifier_provider/todos.dart"; +import todosConsumer from "!!raw-loader!/docs/providers/state_notifier_provider/todos_consumer.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; `StateNotifierProvider` হল একটি প্রভাইডার যা একটি [StateNotifier] (প্যাকেজ [state_notifier] থেকে, যা রিভারপড পুনরায় রি-এক্সপোর্ট করে) রিড এবং এক্সপোস করতে ব্যবহৃত হয়। diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos.dart deleted file mode 100644 index 30f9cf0fe..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// আমাদের স্টেট নোটিফায়ারের অবস্থা অপরিবর্তনীয় হওয়া উচিত। -// বাস্তবায়নে সাহায্য করার জন্য আমরা Freezed-এর মতো প্যাকেজগুলিও ব্যবহার করতে পারি। -@immutable -class Todo { - const Todo( - {required this.id, required this.description, required this.completed}); - - // সমস্ত বৈশিষ্ট্য আমাদের ক্লাসে 'final' হওয়া উচিত। - final String id; - final String description; - final bool completed; - - // যেহেতু টোডো অপরিবর্তনীয়, আমরা একটি পদ্ধতি প্রয়োগ করি যা সামান্য ভিন্ন বিষয়বস্তু সহ - // টোডো ক্লোন করার অনুমতি দেয়। - Todo copyWith({String? id, String? description, bool? completed}) { - return Todo( - id: id ?? this.id, - description: description ?? this.description, - completed: completed ?? this.completed, - ); - } -} - -// StateNotifier ক্লাস যা আমাদের StateNotifierProvider-এ পাস করা হবে। এই ক্লাসটি তার -//"ষ্টেট" প্রপার্টির বাইরে ষ্টেটকে প্রকাশ করা উচিত নয়, যার মানে কোনও পাবলিক গেটার/প্রপার্টি নেই! এই ক্লাস -// সর্বজনীন মেথদগুলিই হবে যা UI-কে ষ্টেট সংশোধন করতে দেয়৷ -class TodosNotifier extends StateNotifier> { - // আমরা একটি খালি তালিকায় todos তালিকা শুরু করি - TodosNotifier() : super([]); - - // আর UI কে todos যোগ করার অনুমতি দেওয়া যাক। - void addTodo(Todo todo) { - // যেহেতু আমাদের ষ্টেট অপরিবর্তনীয়, তাই আমাদের `state.add(todo)` করার অনুমতি নেই। - // পরিবর্তে, আমাদের টোডোর একটি নতুন তালিকা তৈরি করা উচিত যাতে পূর্ববর্তী আইটেম এবং - // নতুনটি রয়েছে। - // এখানে ডার্টের স্প্রেড অপারেটর ব্যবহার করা সহায়ক! - state = [...state, todo]; - // "notifyListeners" বা অনুরূপ কিছু কল করার প্রয়োজন নেই। - // "state = " কল করলে প্রয়োজনে স্বয়ংক্রিয়ভাবে UI পুনর্নির্মাণ করবে। - } - - // এর টোডো অপসারণের অনুমতি দেওয়া যাক - void removeTodo(String todoId) { - // আবার, আমাদের ষ্টেট অপরিবর্তনীয়। তাই আমরা বিদ্যমান তালিকা পরিবর্তনের পরিবর্তে - // একটি নতুন তালিকা তৈরি করছি। - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // আসুন একটি করণীয়কে সম্পূর্ণ হিসাবে চিহ্নিত করি - void toggle(String todoId) { - state = [ - for (final todo in state) - // আমরা শুধুমাত্র মিলে যাওয়া করণীয়কে সম্পূর্ণ হিসেবে চিহ্নিত করছি - if (todo.id == todoId) - // আরও একবার, যেহেতু আমাদের ষ্টেট অপরিবর্তনীয়, তাই আমাদের একটি কপি তৈরি করতে হবে - // এই টুডুটার. এটিতে সহায়তা করার জন্য আমরা আগে প্রয়োগ করা - // আমাদের `copyWith` মেথড ব্যবহার করছি - todo.copyWith(completed: !todo.completed) - else - // অন্যান্য todos সংশোধন করা হয় না - todo, - ]; - } -} - -// অবশেষে, আমরা UI কে আমাদের TodosNotifier ক্লাসের সাথে ইন্টারঅ্যাক্ট করার -// অনুমতি দিতে StateNotifierProvider ব্যবহার করছি। -final todosProvider = StateNotifierProvider>((ref) { - return TodosNotifier(); -}); diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos_consumer.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos_consumer.dart deleted file mode 100644 index e319dfbed..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos_consumer.dart +++ /dev/null @@ -1,32 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'todos.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // উইজেট রিবিল্ট হবে যখন টুডু লিস্ট চ্যাঞ্জ হবে - List todos = ref.watch(todosProvider); - - // আসুন একটি স্ক্রোলযোগ্য ListView-তে todos রেন্ডার করি - return ListView( - children: [ - for (final todo in todos) - CheckboxListTile( - value: todo.completed, - // টোডোতে ট্যাপ করার সময়, এর স্টেট পরিবর্তন করুন কমপ্লিট স্ট্যাটাস এ - onChanged: (value) => - ref.read(todosProvider.notifier).toggle(todo.id), - title: Text(todo.description), - ), - ], - ); - } -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider.mdx b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider.mdx index c4a9e9228..2a50dade5 100644 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider.mdx +++ b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider.mdx @@ -5,14 +5,14 @@ title: StateProvider import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import product from "!!raw-loader!./state_provider/product.dart"; -import productListView from "!!raw-loader!./state_provider/product_list_view.dart"; -import dropdown from "!!raw-loader!./state_provider/dropdown.dart"; -import sortProvider from "!!raw-loader!./state_provider/sort_provider.dart"; -import connectedDropdown from "!!raw-loader!./state_provider/connected_dropdown.dart"; -import sortedProductProvider from "!!raw-loader!./state_provider/sorted_product_provider.dart"; -import updateReadTwice from "!!raw-loader!./state_provider/update_read_twice.dart"; -import updateReadOnce from "!!raw-loader!./state_provider/update_read_once.dart"; +import product from "!!raw-loader!/docs/providers/state_provider/product.dart"; +import productListView from "!!raw-loader!/docs/providers/state_provider/product_list_view.dart"; +import dropdown from "!!raw-loader!/docs/providers/state_provider/dropdown.dart"; +import sortProvider from "!!raw-loader!/docs/providers/state_provider/sort_provider.dart"; +import connectedDropdown from "!!raw-loader!/docs/providers/state_provider/connected_dropdown.dart"; +import sortedProductProvider from "!!raw-loader!/docs/providers/state_provider/sorted_product_provider.dart"; +import updateReadTwice from "!!raw-loader!/docs/providers/state_provider/update_read_twice.dart"; +import updateReadOnce from "!!raw-loader!/docs/providers/state_provider/update_read_once.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/connected_dropdown.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/connected_dropdown.dart deleted file mode 100644 index dc1a2fb01..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/connected_dropdown.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: prefer_const_literals_to_create_immutables - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'dropdown.dart'; -import 'sort_provider.dart'; - -Widget build(BuildContext context, WidgetRef ref) { - return AppBar(actions: [ -/* SNIPPET START */ - DropdownButton( - // যখন সর্ট টাইপ পরিবর্তিত হয়, এটি প্রদর্শিত আইকন আপডেট করতে ড্রপডাউনটি পুনর্নির্মাণ করবে। - value: ref.watch(productSortTypeProvider), - // যখন ব্যবহারকারী ড্রপডাউনের সাথে ইন্টারঅ্যাক্ট করে, তখন আমরা প্রভাইডারের স্টেট আপডেট করি। - onChanged: (value) => - ref.read(productSortTypeProvider.notifier).state = value!, - items: [ - // ... - ], - ), -/* SNIPPET END */ - ]); -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/dropdown.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/dropdown.dart deleted file mode 100644 index afe354861..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/dropdown.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'full.dart'; - -/* SNIPPET START */ - -//এ কটি enum যা ফিল্টার টাইপ রিপ্রেসেন্ট করে -enum ProductSortType { - name, - price, -} - -Widget build(BuildContext context, WidgetRef ref) { - final products = ref.watch(productsProvider); - return Scaffold( - appBar: AppBar( - title: const Text('Products'), - actions: [ - DropdownButton( - value: ProductSortType.price, - onChanged: (value) {}, - items: const [ - DropdownMenuItem( - value: ProductSortType.name, - child: Icon(Icons.sort_by_alpha), - ), - DropdownMenuItem( - value: ProductSortType.price, - child: Icon(Icons.sort), - ), - ], - ), - ], - ), - body: ListView.builder( - // ... /* SKIP */ - itemBuilder: (c, i) => Container(), /* SKIP END */ - ), - ); -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/product.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/product.dart deleted file mode 100644 index 078def200..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/product.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ - -class Product { - Product({required this.name, required this.price}); - - final String name; - final double price; -} - -final _products = [ - Product(name: 'iPhone', price: 999), - Product(name: 'cookie', price: 2), - Product(name: 'ps5', price: 500), -]; - -final productsProvider = Provider>((ref) { - return _products; -}); diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/product_list_view.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/product_list_view.dart deleted file mode 100644 index 17765aea8..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/product_list_view.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'product.dart'; - -/* SNIPPET START */ - -Widget build(BuildContext context, WidgetRef ref) { - final products = ref.watch(productsProvider); - return Scaffold( - body: ListView.builder( - itemCount: products.length, - itemBuilder: (context, index) { - final product = products[index]; - return ListTile( - title: Text(product.name), - subtitle: Text('${product.price} \$'), - ); - }, - ), - ); -} diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/sort_provider.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/sort_provider.dart deleted file mode 100644 index 225b7f4ad..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/sort_provider.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'dropdown.dart'; - -/* SNIPPET START */ - -final productSortTypeProvider = StateProvider( - // আমরা ডিফল্ট সর্ট টাইপ রিটার্ন দিই, এখানে নাম। - (ref) => ProductSortType.name, -); diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/sorted_product_provider.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/sorted_product_provider.dart deleted file mode 100644 index 6725d0282..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/sorted_product_provider.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'dropdown.dart'; -import 'product.dart'; -import 'sort_provider.dart'; - -final _products = [ - Product(name: 'iPhone', price: 999), - Product(name: 'cookie', price: 2), - Product(name: 'ps5', price: 500), -]; - -/* SNIPPET START */ - -final productsProvider = Provider>((ref) { - final sortType = ref.watch(productSortTypeProvider); - switch (sortType) { - case ProductSortType.name: - return _products.sorted((a, b) => a.name.compareTo(b.name)); - case ProductSortType.price: - return _products.sorted((a, b) => a.price.compareTo(b.price)); - } -}); \ No newline at end of file diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_once.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_once.dart deleted file mode 100644 index 825df6d0f..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_once.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - /* highlight-start */ - ref.read(counterProvider.notifier).update((state) => state + 1); - /* highlight-end */ - }, - ), - ); - } -} \ No newline at end of file diff --git a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_twice.dart b/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_twice.dart deleted file mode 100644 index 59590fa5b..000000000 --- a/website/i18n/bn/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_twice.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - // আমরা পূর্ববর্তী মান থেকে স্ট্যাট আপডেট করছি, আমরা দুইবার প্রভাইডার রিড করে ফেলছি! - ref.read(counterProvider.notifier).state = - ref.read(counterProvider.notifier).state + 1; - }, - ), - ); - } -} diff --git a/website/i18n/de/docusaurus-plugin-content-docs/current/getting_started.mdx b/website/i18n/de/docusaurus-plugin-content-docs/current/getting_started.mdx index 9024fd465..f5d85ad93 100644 --- a/website/i18n/de/docusaurus-plugin-content-docs/current/getting_started.mdx +++ b/website/i18n/de/docusaurus-plugin-content-docs/current/getting_started.mdx @@ -43,7 +43,7 @@ Wenn die Entscheidung getroffen wurde, welches Paket verwendet werden soll, füg ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -60,7 +60,7 @@ Dann führe `flutter pub get` aus. ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -76,7 +76,7 @@ Dann führe `flutter pub get` aus. ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" dependencies: riverpod: ^2.1.3 diff --git a/website/i18n/de/docusaurus-plugin-content-docs/current/providers/provider.mdx b/website/i18n/de/docusaurus-plugin-content-docs/current/providers/provider.mdx index 06abb9f6e..0e6648322 100644 --- a/website/i18n/de/docusaurus-plugin-content-docs/current/providers/provider.mdx +++ b/website/i18n/de/docusaurus-plugin-content-docs/current/providers/provider.mdx @@ -7,7 +7,7 @@ import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; import todo from "!!raw-loader!./provider/todo.dart"; import completedTodos from "!!raw-loader!./provider/completed_todos.dart"; -import todosConsumer from "!!raw-loader!./provider/todos_consumer.dart"; +import todosConsumer from "!!raw-loader!/docs/providers/provider/todos_consumer.dart"; import unoptimizedPreviousButton from "!!raw-loader!./provider/unoptimized_previous_button.dart"; import optimizedPreviousButton from "!!raw-loader!./provider/optimized_previous_button.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/de/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart b/website/i18n/de/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart deleted file mode 100644 index 5cb9b7ff4..000000000 --- a/website/i18n/de/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'completed_todos.dart'; - -Widget build() { -return -/* SNIPPET START */ -Consumer(builder: (context, ref, child) { - final completedTodos = ref.watch(completedTodosProvider); - // TODO show the todos using a ListView/GridView/.../* SKIP */ - return Container(); - /* SKIP END */ -}); -/* SNIPPET END */ -} diff --git a/website/i18n/es/docusaurus-plugin-content-docs/current/getting_started.mdx b/website/i18n/es/docusaurus-plugin-content-docs/current/getting_started.mdx index 8618ec2c9..16ec49c1c 100644 --- a/website/i18n/es/docusaurus-plugin-content-docs/current/getting_started.mdx +++ b/website/i18n/es/docusaurus-plugin-content-docs/current/getting_started.mdx @@ -38,7 +38,7 @@ Una vez que sepas qué paquete deseas instalar, procede a añadir lo siguiente a ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -55,7 +55,7 @@ Luego ejecuta `flutter pub get`. ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -71,7 +71,7 @@ Luego ejecuta `flutter pub get`. ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" dependencies: riverpod: ^2.1.3 diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart b/website/i18n/fr/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart deleted file mode 100644 index e70c72515..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart +++ /dev/null @@ -1,58 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// Avoir un compteur qui est incrémenté par le FloatingActionButton. -final counterProvider = StateProvider((ref) => 0); - -class Home extends ConsumerWidget { - const Home({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // Nous voulons afficher une boîte de dialoque avec la valeur du compteur à l'appui du bouton - return Scaffold( - body: Column( - children: [ - ElevatedButton( - onPressed: () { - showDialog( - context: context, - builder: (c) { - // Nous enveloppons la boîte de dialogue avec un widget ProviderScope, en fournissant le - // conteneur parent pour garantir que la boîte de dialogue puisse accéder aux mêmes providers - // accessibles par le widget Home. - return ProviderScope( - parent: ProviderScope.containerOf(context), - child: const AlertDialog( - content: CounterDisplay(), - ), - ); - }, - ); - }, - child: const Text('Afficher boîte de dialogue'), - ), - ], - ), - floatingActionButton: FloatingActionButton( - child: const Icon(Icons.add), - onPressed: () { - ref.read(counterProvider.notifier).state++; - }, - )); - } -} - -class CounterDisplay extends ConsumerWidget { - const CounterDisplay({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final count = ref.watch(counterProvider); - return Text('$count'); - } -} diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/concepts/scopes.mdx b/website/i18n/fr/docusaurus-plugin-content-docs/current/concepts/scopes.mdx index 1ee93e4a8..7a5e51459 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/concepts/scopes.mdx +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/concepts/scopes.mdx @@ -6,7 +6,6 @@ import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; import asyncInitialization from "!!raw-loader!/i18n/fr/docusaurus-plugin-content-docs/current/concepts/async_initialization.dart"; -import dialogScope from "!!raw-loader!/i18n/fr/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart"; import themeScope from "!!raw-loader!/i18n/fr/docusaurus-plugin-content-docs/current/concepts/theme_scope.dart"; import subtreeScope from "!!raw-loader!/i18n/fr/docusaurus-plugin-content-docs/current/concepts/subtree_scope.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; @@ -83,17 +82,6 @@ Voici un exemple qui montre comment le scoping vous permet de remplacer un provi {trimSnippet(asyncInitialization)} -## Affichage des dialogues - -Lorsque vous affichez un `Dialog` ou un `OverlayEntry`, flutter crée une nouvelle `Route` ou ajoute à un `Overlay` qui a une portée de construction différente, -afin qu'il puisse échapper à la disposition de son parent, et qu'il puisse être affiché au-dessus des autres `Routes`. -Cela pose un problème pour les `InheritedWidget`s en général, et comme [ProviderScope] est un `InheritedWidget`, il est également affecté. - -Pour résoudre ce problème, Riverpod vous permet de créer un `ProviderScope` qui peut accéder à l'état de tous les providers dans une portée `parent`. - -L'exemple suivant montre comment l'utiliser, pour permettre à un `Dialog` d'accéder à l'état d'un compteur depuis le contexte qui a provoqué l'affichage du `Dialog`. -{trimSnippet(dialogScope)} - ## Scoping de sous-arbres Le scoping vous permet de surcharger l'état d'un provider pour un sous-arbre spécifique de votre arbre de widgets. diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started.mdx b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started.mdx index 3a0d949e4..15e4ba23c 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started.mdx +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started.mdx @@ -38,7 +38,7 @@ Une fois la librarie choisie, vous pouvez modifier votre `pubspec.yaml` pour y i ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -55,7 +55,7 @@ Exécutez ensuite la commande `flutter pub get`. ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -71,7 +71,7 @@ Exécutez ensuite la commande `flutter pub get`. ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" dependencies: riverpod: ^1.0.0-dev.10 diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml index 7904cfdf2..538c95316 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: riverpod: ^2.1.1 diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml index 5165f3375..da0363ab3 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: riverpod: ^2.1.1 \ No newline at end of file diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml index d11a860d9..6c6f2bc15 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml index 026fdbe64..7e0d1aa24 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml index 2bdd3591f..90356238a 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml index c0b78f8a0..4beb7f86b 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx index b9763e1d7..357d7256c 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx @@ -5,10 +5,10 @@ title: (Async)NotifierProvider import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import todos from "./notifier_provider/todos"; -import todosConsumer from "!!raw-loader!/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart"; -import remoteTodos from "./notifier_provider/remote_todos"; -import remoteTodosConsumer from "!!raw-loader!/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart"; +import todos from "/docs/providers/notifier_provider/todos"; +import todosConsumer from "!!raw-loader!/docs/providers/notifier_provider/todos/todos_consumer.dart"; +import remoteTodos from "/docs/providers/notifier_provider/remote_todos"; +import remoteTodosConsumer from "!!raw-loader!/docs/providers/notifier_provider/remote_todos/todos_consumer.dart"; import { trimSnippet, AutoSnippet } from "../../../../../src/components/CodeSnippet"; [NotifierProvider] est un provider qui est utilisé pour écouter et exposer un [Notifier]. diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart deleted file mode 100644 index 0cb566d5a..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart +++ /dev/null @@ -1,82 +0,0 @@ -import 'dart:convert'; - -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -class Http { - Future get(String str) async => str; - Future delete(String str) async => str; - Future post(String str, Map body) async => str; - Future patch(String str, Map body) async => str; -} - -final http = Http(); - -/* SNIPPET START */ - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; - - factory Todo.fromJson(Map json) => _$TodoFromJson(json); -} - -// Ceci va générer un AsyncNotifier et un AsyncNotifierProvider. -// La classe AsyncNotifier qui sera transmise à notre AsyncNotifierProvider. -// Cette classe ne doit pas exposer d'état en dehors de sa propriété "state", ce qui signifie que -// pas de getters/properties publics ! -// Les méthodes publiques de cette classe seront celles qui permettront à l'interface utilisateur de modifier l'état. -// Enfin, nous utilisons asyncTodosProvider(AsyncNotifierProvider) pour permettre à l'interface utilisateur -// d'interagir avec notre classe Todos. -@riverpod -class AsyncTodos extends _$AsyncTodos { - Future> _fetchTodo() async { - final json = await http.get('api/todos'); - final todos = jsonDecode(json) as List>; - return todos.map(Todo.fromJson).toList(); - } - - @override - FutureOr> build() async { - // Chargement de la liste de tâches initiale à partir du référentiel distant - return _fetchTodo(); - } - - Future addTodo(Todo todo) async { - // Définit l'état à "loading" - state = const AsyncValue.loading(); - // Ajout du nouveau todo et rechargement de la liste des todo depuis le référentiel distant - state = await AsyncValue.guard(() async { - await http.post('api/todos', todo.toJson()); - return _fetchTodo(); - }); - } - - // Autorisons la suppression des todos. - Future removeTodo(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.delete('api/todos/$todoId'); - return _fetchTodo(); - }); - } - - // Marquons une tâche comme étant terminée. - Future toggle(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.patch( - 'api/todos/$todoId', - {'completed': true}, - ); - return _fetchTodo(); - }); - } -} diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart deleted file mode 100644 index f4455a338..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Http { - Future get(String str) async => str; - Future delete(String str) async => str; - Future post(String str, Map body) async => str; - Future patch(String str, Map body) async => str; -} - -final http = Http(); - -/* SNIPPET START */ - -// An immutable state is preferred. -// We could also use packages like Freezed to help with the implementation. -@immutable -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - factory Todo.fromJson(Map map) { - return Todo( - id: map['id'] as String, - description: map['description'] as String, - completed: map['completed'] as bool, - ); - } - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - Map toJson() => { - 'id': id, - 'description': description, - 'completed': completed, - }; -} - -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -class AsyncTodosNotifier extends AsyncNotifier> { - Future> _fetchTodo() async { - final json = await http.get('api/todos'); - final todos = jsonDecode(json) as List>; - return todos.map(Todo.fromJson).toList(); - } - - @override - Future> build() async { - // Load initial todo list from the remote repository - return _fetchTodo(); - } - - Future addTodo(Todo todo) async { - // Set the state to loading - state = const AsyncValue.loading(); - // Add the new todo and reload the todo list from the remote repository - state = await AsyncValue.guard(() async { - await http.post('api/todos', todo.toJson()); - return _fetchTodo(); - }); - } - - // Let's allow removing todos - Future removeTodo(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.delete('api/todos/$todoId'); - return _fetchTodo(); - }); - } - - // Let's mark a todo as completed - Future toggle(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.patch( - 'api/todos/$todoId', - {'completed': true}, - ); - return _fetchTodo(); - }); - } -} - -// Finally, we are using NotifierProvider to allow the UI to interact with -// our TodosNotifier class. -final asyncTodosProvider = - AsyncNotifierProvider>(() { - return AsyncTodosNotifier(); -}); diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart deleted file mode 100644 index b489ed45c..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart +++ /dev/null @@ -1,38 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'codegen.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // rreconstruit le widget lorsque la liste des tâches change. - final asyncTodos = ref.watch(asyncTodosProvider); - - // Affichons les todos dans une liste déroulante. - return asyncTodos.when( - data: (todos) => ListView( - children: [ - for (final todo in todos) - CheckboxListTile( - value: todo.completed, - // En appuyant sur la tâche, vous pouvez modifier son état d'achèvement. - onChanged: (value) => - ref.read(asyncTodosProvider.notifier).toggle(todo.id), - title: Text(todo.description), - ), - ], - ), - loading: () => const Center( - child: CircularProgressIndicator(), - ), - error: (err, stack) => Text('Error: $err'), - ); - } -} diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart deleted file mode 100644 index e00b857c8..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart +++ /dev/null @@ -1,68 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; -} - -// Ceci va générer un Notifier et un NotifierProvider. -// La classe de Notifier qui sera transmise à notre NotifierProvider. -// Cette classe ne doit pas exposer d'état en dehors de sa propriété "state", ce qui signifie que -// pas de getters/properties publics ! -// Les méthodes publiques de cette classe seront celles qui permettront à l'interface utilisateur de modifier l'état. -// Enfin, nous utilisons todosProvider(NotifierProvider) pour permettre à l'interface utilisateur -// d'interagir avec notre classe Todos. -@riverpod -class Todos extends _$Todos { - @override - List build() { - return []; - } - - // Permettons à l'interface utilisateur d'ajouter des todos. - void addTodo(Todo todo) { - // Comme notre état est immuable, nous ne pouvons pas faire `state.add(todo)`. - // A la place, nous devons créer une nouvelle liste de todos qui contient - // les éléments précédents et le nouveau. - // L'utilisation de l'opérateur spread de Dart est utile ici ! - state = [...state, todo]; - // Il n'est pas nécessaire d'appeler "notifyListeners" ou quelque chose de similaire. L'appel de "state =" - // reconstruira automatiquement l'interface utilisateur si nécessaire. - } - - // Autorisons la suppression des todos. - void removeTodo(String todoId) { - // Encore une fois, notre état est immuable. Donc nous créons une nouvelle liste au lieu de - // changer la liste existante. - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // Marquons une tâche comme étant terminée. - void toggle(String todoId) { - state = [ - for (final todo in state) - // nous marquons seulement le todo correspondant comme terminé - if (todo.id == todoId) - // Une fois de plus, puisque notre état est immuable, nous devons faire une copie - // du todo. Nous utilisons la méthode `copyWith` implémentée précédemment - // pour nous aider à le faire. - todo.copyWith(completed: !todo.completed) - else - // les autres todos ne sont pas modifiés - todo, - ]; - } -} diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart deleted file mode 100644 index ec3e50308..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart +++ /dev/null @@ -1,85 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// An immutable state is preferred. -// We could also use packages like Freezed to help with the implementation. -@immutable -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - // Since Todo is immutable, we implement a method that allows cloning the - // Todo with slightly different content. - Todo copyWith({String? id, String? description, bool? completed}) { - return Todo( - id: id ?? this.id, - description: description ?? this.description, - completed: completed ?? this.completed, - ); - } -} - -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -class TodosNotifier extends Notifier> { - // We initialize the list of todos to an empty list - @override - List build() { - return []; - } - - // Let's allow the UI to add todos. - void addTodo(Todo todo) { - // Since our state is immutable, we are not allowed to do `state.add(todo)`. - // Instead, we should create a new list of todos which contains the previous - // items and the new one. - // Using Dart's spread operator here is helpful! - state = [...state, todo]; - // No need to call "notifyListeners" or anything similar. Calling "state =" - // will automatically rebuild the UI when necessary. - } - - // Let's allow removing todos - void removeTodo(String todoId) { - // Again, our state is immutable. So we're making a new list instead of - // changing the existing list. - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // Let's mark a todo as completed - void toggle(String todoId) { - state = [ - for (final todo in state) - // we're marking only the matching todo as completed - if (todo.id == todoId) - // Once more, since our state is immutable, we need to make a copy - // of the todo. We're using our `copyWith` method implemented before - // to help with that. - todo.copyWith(completed: !todo.completed) - else - // other todos are not modified - todo, - ]; - } -} - -// Finally, we are using NotifierProvider to allow the UI to interact with -// our TodosNotifier class. -final todosProvider = NotifierProvider>(() { - return TodosNotifier(); -}); diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart b/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart deleted file mode 100644 index e7dde22af..000000000 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart +++ /dev/null @@ -1,32 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'codegen.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // reconstruit le widget lorsque la liste des tâches change. - List todos = ref.watch(todosProvider); - - // Affichons les todos dans une liste déroulante. - return ListView( - children: [ - for (final todo in todos) - CheckboxListTile( - value: todo.completed, - // En appuyant sur la tâche, vous pouvez modifier son état d'achèvement. - onChanged: (value) => - ref.read(todosProvider.notifier).toggle(todo.id), - title: Text(todo.description), - ), - ], - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select.mdx index 094b08847..6500735c2 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select.mdx @@ -3,9 +3,9 @@ title: Ottimizzare le performance --- import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import select from "./select/select"; +import select from "/docs/advanced/select/select"; -import selectAsync from "./select/select_async"; +import selectAsync from "/docs/advanced/select/select_async"; Con tutto ciò che abbiamo visto fino ad ora, possiamo già costruire un'applicazione completamente funzionante. Tuttavia, potresti avere delle domande riguardo alle performance. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/codegen.dart deleted file mode 100644 index 23106b471..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/codegen.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_multiple_declarations_per_line, omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -class User { - late String firstName, lastName; -} - -@riverpod -User example(ExampleRef ref) => User() - ..firstName = 'John' - ..lastName = 'Doe'; - -class ConsumerExample extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Invece di scrivere: - // String name = ref.watch(provider).firstName!; - // Possiamo scrivere: - String name = ref.watch(exampleProvider.select((it) => it.firstName)); - // In questo modo il widget ascolterà solo i cambiamenti della proprietà "firstName". - - return Text('Hello $name'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/raw.dart deleted file mode 100644 index a8f00cb01..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select/raw.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_multiple_declarations_per_line, omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -class User { - late String firstName, lastName; -} - -final provider = Provider( - (ref) => User() - ..firstName = 'John' - ..lastName = 'Doe', -); - -class ConsumerExample extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Invece di scrivere: - // String name = ref.watch(provider).firstName!; - // Possiamo scrivere: - String name = ref.watch(provider.select((it) => it.firstName)); - // In questo modo il widget ascolterà solo i cambiamenti della proprietà "firstName". - - return Text('Hello $name'); - } -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/codegen.dart deleted file mode 100644 index a3527a9e8..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/codegen.dart +++ /dev/null @@ -1,26 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_multiple_declarations_per_line, omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors, body_might_complete_normally_nullable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -class User { - late String firstName, lastName; -} - -final userProvider = FutureProvider( - (ref) => User() - ..firstName = 'John' - ..lastName = 'Doe', -); -/* SNIPPET START */ -@riverpod -Object? example(ExampleRef ref) async { - // Aspetta che un utente sia disponibile, ed ascolta solo la proprietà "firstName" - final firstName = await ref.watch( - userProvider.selectAsync((it) => it.firstName), - ); - - // TODO usa "firstName" per ottenere qualcos'altro -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/raw.dart deleted file mode 100644 index 574a8a29b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/advanced/select/select_async/raw.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_multiple_declarations_per_line, omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class User { - late String firstName, lastName; -} - -final userProvider = FutureProvider( - (ref) => User() - ..firstName = 'John' - ..lastName = 'Doe', -); -/* SNIPPET START */ -final provider = FutureProvider((ref) async { - // Aspetta che un utente sia disponibile, ed ascolta solo la proprietà "firstName" - final firstName = await ref.watch( - userProvider.selectAsync((it) => it.firstName), - ); - - // TODO usa "firstName" per ottenere qualcos'altro -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx index 38ef39768..378e579a2 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx @@ -6,10 +6,10 @@ import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; import homeScreen from "!raw-loader!./cancel/home_screen.dart"; import extension from "!raw-loader!./cancel/extension.dart"; -import detailScreen from "./cancel/detail_screen"; -import detailScreenCancel from "./cancel/detail_screen_cancel"; -import detailScreenDebounce from "./cancel/detail_screen_debounce"; -import providerWithExtension from "./cancel/provider_with_extension"; +import detailScreen from "/docs/case_studies/cancel/detail_screen"; +import detailScreenCancel from "/docs/case_studies/cancel/detail_screen_cancel"; +import detailScreenDebounce from "/docs/case_studies/cancel/detail_screen_debounce"; +import providerWithExtension from "/docs/case_studies/cancel/provider_with_extension"; Man mano che le applicazioni diventano più complesse, è comune avere più richieste di rete attive contemporaneamente. Per esempio, un utente potrebbe digitare in una casella di testo diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/codegen.dart deleted file mode 100644 index e3bf193a2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/codegen.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -/* SNIPPET START */ -@freezed -class Activity with _$Activity { - factory Activity({ - required String activity, - required String type, - required int participants, - required double price, - }) = _Activity; - - factory Activity.fromJson(Map json) => - _$ActivityFromJson(json); -} - -@riverpod -Future activity(ActivityRef ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} - -class DetailPageView extends ConsumerWidget { - const DetailPageView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar( - title: const Text('Detail page'), - ), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const Center(child: CircularProgressIndicator()), - }, - ], - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/raw.dart deleted file mode 100644 index b3ad1faaf..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/raw.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -/* SNIPPET START */ -class Activity { - Activity({ - required this.activity, - required this.type, - required this.participants, - required this.price, - }); - - factory Activity.fromJson(Map json) { - return Activity( - activity: json['activity']! as String, - type: json['type']! as String, - participants: json['participants']! as int, - price: json['price']! as double, - ); - } - - final String activity; - final String type; - final int participants; - final double price; -} - -final activityProvider = FutureProvider.autoDispose((ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); - -class DetailPageView extends ConsumerWidget { - const DetailPageView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar( - title: const Text('Detail page'), - ), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const Center(child: CircularProgressIndicator()), - }, - ], - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/codegen.dart deleted file mode 100644 index 97194c7b5..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/codegen.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../detail_screen/codegen.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - // Creiamo un client HTTP usando package:http - final client = http.Client(); - // Durante la distruzione, chiudiamo il client. - // Questo cancellerà qualsiasi richiesta pendente che il client potrebbe avere. - ref.onDispose(client.close); - - // Ora utilizziamo il client per eseguire la richiesta "get" - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - // Il resto del codice è uguale a prima - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/raw.dart deleted file mode 100644 index eaf0509d7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import '../detail_screen/codegen.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - // Creiamo un client HTTP usando package:http - final client = http.Client(); - // Durante la distruzione, chiudiamo il client. - // Questo cancellerà qualsiasi richiesta pendente che il client potrebbe avere. - ref.onDispose(client.close); - - // Ora utilizziamo il client per eseguire la richiesta "get" - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - // Il resto del codice è uguale a prima - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/codegen.dart deleted file mode 100644 index a3e8cbdae..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/codegen.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../detail_screen/codegen.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - // Capiamo se il provider è al momento distrutto oppure no. - var didDispose = false; - ref.onDispose(() => didDispose = true); - - // Ritardiamo la chiamata di 500ms per aspettare che l'utente finisca di riaggiornare. - await Future.delayed(const Duration(milliseconds: 500)); - - // Se il provider è stato distrutto durante il ritardo, significa che l'utente - // ha aggiornato di nuovo. Generiamo un'eccezione per cancellare la richiesta. - // È sicuro generare un'eccezione qui dato che sarà catturata da Riverpod. - if (didDispose) { - throw Exception('Cancelled'); - } - - // Il codice seguente non è cambiato dallo snippet precedente - final client = http.Client(); - ref.onDispose(client.close); - - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/raw.dart deleted file mode 100644 index 0028dba94..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/raw.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import '../detail_screen/codegen.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - // Capiamo se il provider è al momento distrutto oppure no. - var didDispose = false; - ref.onDispose(() => didDispose = true); - - // Ritardiamo la richiesta di 500ms per aspettare che l'utente finisca di aggiornare. - await Future.delayed(const Duration(milliseconds: 500)); - - // Se il provider è stato distrutto durante il ritardo, significa che l'utente - // ha aggiornato di nuovo. Generiamo un'eccezione per cancellare la richiesta. - // È sicuro generare un'eccezione qui dato che sarà catturata da Riverpod. - if (didDispose) { - throw Exception('Cancelled'); - } - - // Il codice seguente non è cambiato dallo snippet precedente - final client = http.Client(); - ref.onDispose(client.close); - - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/codegen.dart deleted file mode 100644 index 3c64da871..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/codegen.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'dart:convert'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../detail_screen/codegen.dart'; -import '../extension.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - // Otteniamo un client HTTP usando l'estensione creata prima. - final client = await ref.getDebouncedHttpClient(); - - // Usiamo ora il client per effettuare la richiesta "get". - // La nostra richiesta sarà automaticamente respinta e cancellata se l'utente - // lascia la pagina - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/raw.dart deleted file mode 100644 index 36ef098f7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/raw.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../detail_screen/codegen.dart'; -import '../extension.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - // We obtain an HTTP client using the extension we created earlier. - final client = await ref.getDebouncedHttpClient(); - - // We now use the client to make the request instead of the "get" function. - // Our request will naturally be debounced and be cancelled if the user - // leaves the page. - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx index a16869505..dcbe237d7 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx @@ -3,13 +3,13 @@ title: Pull to refresh (trascina per aggiornare) --- import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import activity from "./pull_to_refresh/activity"; -import fetchActivity from "./pull_to_refresh/fetch_activity"; -import displayActivity from "!!raw-loader!./pull_to_refresh/display_activity.dart"; -import displayActivity2 from "!!raw-loader!./pull_to_refresh/display_activity2.dart"; -import displayActivity3 from "!!raw-loader!./pull_to_refresh/display_activity3.dart"; -import displayActivity4 from "!!raw-loader!./pull_to_refresh/display_activity4.dart"; -import fullApp from "./pull_to_refresh/full_app"; +import activity from "/docs/case_studies/pull_to_refresh/activity"; +import fetchActivity from "/docs/case_studies/pull_to_refresh/fetch_activity"; +import displayActivity from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity.dart"; +import displayActivity2 from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity2.dart"; +import displayActivity3 from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity3.dart"; +import displayActivity4 from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity4.dart"; +import fullApp from "/docs/case_studies/pull_to_refresh/full_app"; Riverpod supporta nativamente il meccanismo di pull-to-refresh grazie alla sua natura dichiarativa. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/codegen.dart deleted file mode 100644 index ac3e1b17d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/codegen.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'codegen.g.dart'; -part 'codegen.freezed.dart'; - -/* SNIPPET START */ -@freezed -class Activity with _$Activity { - factory Activity({ - required String activity, - required String type, - required int participants, - required double price, - }) = _Activity; - - factory Activity.fromJson(Map json) => - _$ActivityFromJson(json); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/raw.dart deleted file mode 100644 index 42365b7bb..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/raw.dart +++ /dev/null @@ -1,24 +0,0 @@ -/* SNIPPET START */ -class Activity { - Activity({ - required this.activity, - required this.type, - required this.participants, - required this.price, - }); - - factory Activity.fromJson(Map json) { - return Activity( - activity: json['activity']! as String, - type: json['type']! as String, - participants: json['participants']! as int, - price: json['price']! as double, - ); - } - - final String activity; - final String type; - final int participants; - final double price; -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity.dart deleted file mode 100644 index 8bddac53f..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: Center( - // Se abbiamo un'attività, la mostriamo, altrimenti aspettiamo - child: Text(activity.valueOrNull?.activity ?? ''), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity2.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity2.dart deleted file mode 100644 index 7394ea664..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity2.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: avoid_print, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - /* highlight-start */ - body: RefreshIndicator( - onRefresh: () async => print('refresh'), - child: ListView( - children: [ - /* highlight-end */ - Text(activity.valueOrNull?.activity ?? ''), - ], - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity3.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity3.dart deleted file mode 100644 index c819bf061..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity3.dart +++ /dev/null @@ -1,31 +0,0 @@ -// ignore_for_file: avoid_print, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - // Aggiornando "activityProvider.future" e restituendo il risultato, - // l'indicatore di aggiornamento continuerà ad apparire finchè la nuova attività - // non viene ottenuta. - /* highlight-start */ - onRefresh: () => ref.refresh(activityProvider.future), - /* highlight-end */ - child: ListView( - children: [ - Text(activity.valueOrNull?.activity ?? ''), - ], - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity4.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity4.dart deleted file mode 100644 index 8aa63bed7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity4.dart +++ /dev/null @@ -1,35 +0,0 @@ -// ignore_for_file: avoid_print, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'activity/codegen.dart'; -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - // Se un dato è disponibile, lo mostriamo. - // Nota che il dato rimarrà ancora disponibile durante un aggiornamento. - AsyncValue(:final valueOrNull?) => Text(valueOrNull.activity), - // Un errore è disponibile, quindi lo mostriamo. - AsyncValue(:final error?) => Text('Error: $error'), - // Nessun dato ne errore, quindi siamo nello stato di caricamento. - _ => const CircularProgressIndicator(), - }, - ], - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/codegen.dart deleted file mode 100644 index 0cec67cba..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/codegen.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../activity/codegen.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/raw.dart deleted file mode 100644 index 1cec3b128..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../activity/raw.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/codegen.dart deleted file mode 100644 index b7d53c744..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/codegen.dart +++ /dev/null @@ -1,69 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unreachable_from_main - -/* SNIPPET START */ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; -part 'codegen.freezed.dart'; - -void main() => runApp(ProviderScope(child: MyApp())); - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp(home: ActivityView()); - } -} - -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => - Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const CircularProgressIndicator(), - }, - ], - ), - ), - ); - } -} - -@riverpod -Future activity(ActivityRef ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} - -@freezed -class Activity with _$Activity { - factory Activity({ - required String activity, - required String type, - required int participants, - required double price, - }) = _Activity; - - factory Activity.fromJson(Map json) => - _$ActivityFromJson(json); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/raw.dart deleted file mode 100644 index c4186fb31..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/raw.dart +++ /dev/null @@ -1,73 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unreachable_from_main - -/* SNIPPET START */ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -void main() => runApp(ProviderScope(child: MyApp())); - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp(home: ActivityView()); - } -} - -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => - Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const CircularProgressIndicator(), - }, - ], - ), - ), - ); - } -} - -final activityProvider = FutureProvider.autoDispose((ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); - -class Activity { - Activity({ - required this.activity, - required this.type, - required this.participants, - required this.price, - }); - - factory Activity.fromJson(Map json) { - return Activity( - activity: json['activity']! as String, - type: json['type']! as String, - participants: json['participants']! as int, - price: json['price']! as double, - ); - } - - final String activity; - final String type; - final int participants; - final double price; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx index 122b677c4..de0ebef81 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx @@ -6,28 +6,28 @@ version: 1 import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import fetchUser from "!!raw-loader!./about_codegen/main.dart"; -import rawFetchUser from "!!raw-loader!./about_codegen/raw.dart"; +import fetchUser from "!!raw-loader!/docs/concepts/about_codegen/main.dart"; +import rawFetchUser from "!!raw-loader!/docs/concepts/about_codegen/raw.dart"; import { Link } from "../../../../../src/components/Link"; import { trimSnippet, CodeSnippet } from "../../../../../src/components/CodeSnippet"; -import syncFn from "!!raw-loader!./about_codegen/provider_type/sync_fn.dart"; -import syncClass from "!!raw-loader!./about_codegen/provider_type/sync_class.dart"; -import asyncFnFuture from "!!raw-loader!./about_codegen/provider_type/async_fn_future.dart"; -import asyncClassFuture from "!!raw-loader!./about_codegen/provider_type/async_class_future.dart"; -import asyncFnStream from "!!raw-loader!./about_codegen/provider_type/async_fn_stream.dart"; -import asyncClassStream from "!!raw-loader!./about_codegen/provider_type/async_class_stream.dart"; -import familyFn from "!!raw-loader!./about_codegen/provider_type/family_fn.dart"; -import familyClass from "!!raw-loader!./about_codegen/provider_type/family_class.dart"; -import provider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/provider.dart"; -import notifierProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/notifier_provider.dart"; -import futureProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/future_provider.dart"; -import asyncNotifierProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/async_notifier_provider.dart"; -import streamProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/stream_provider.dart"; -import streamNotifierProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart"; -import autoDisposeCodeGen from "!!raw-loader!./about_codegen/provider_type/auto_dispose.dart"; -import autoDisposeNonCodeGen from "!!raw-loader!./about_codegen/provider_type/non_code_gen/auto_dispose.dart"; -import familyCodeGen from "!!raw-loader!./about_codegen/provider_type/family.dart"; -import familyNonCodeGen from "!!raw-loader!./about_codegen/provider_type/non_code_gen/family.dart"; +import syncFn from "!!raw-loader!/docs/concepts/about_codegen/provider_type/sync_fn.dart"; +import syncClass from "!!raw-loader!/docs/concepts/about_codegen/provider_type/sync_class.dart"; +import asyncFnFuture from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_fn_future.dart"; +import asyncClassFuture from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_class_future.dart"; +import asyncFnStream from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_fn_stream.dart"; +import asyncClassStream from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_class_stream.dart"; +import familyFn from "!!raw-loader!/docs/concepts/about_codegen/provider_type/family_fn.dart"; +import familyClass from "!!raw-loader!/docs/concepts/about_codegen/provider_type/family_class.dart"; +import provider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/provider.dart"; +import notifierProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart"; +import futureProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart"; +import asyncNotifierProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart"; +import streamProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart"; +import streamNotifierProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart"; +import autoDisposeCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/auto_dispose.dart"; +import autoDisposeNonCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart"; +import familyCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/family.dart"; +import familyNonCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/family.dart"; const TRANSPARENT_STYLE = { backgroundColor: "transparent" }; const RED_STYLE = { color: "indianred", fontWeight: "700" }; const BLUE_STYLE = { color: "rgb(103, 134, 196)", fontWeight: "700" }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/main.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/main.dart deleted file mode 100644 index 1ccb42807..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/main.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -class User { - User.fromJson(Object obj); -} - -class Http { - Future get(String str) async => str; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -Future fetchUser(FetchUserRef ref, {required int userId}) async { - final json = await http.get('api/user/$userId'); - return User.fromJson(json); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_future.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_future.dart deleted file mode 100644 index d3b8eba59..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_future.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_class_future.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - Future build() async { - return Future.value('foo'); - } - - // Aggiungere i metodi per mutare lo stato -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_stream.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_stream.dart deleted file mode 100644 index d9dc82607..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_stream.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_class_stream.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - Stream build() async* { - yield 'foo'; - } - - // Aggiungere i metodi per mutare lo stato -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_future.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_future.dart deleted file mode 100644 index 95fdd909c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_future.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_fn_future.g.dart'; - -/* SNIPPET START */ -@riverpod -Future example(ExampleRef ref) async { - return Future.value('foo'); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_stream.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_stream.dart deleted file mode 100644 index 74da790ad..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_stream.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_fn_stream.g.dart'; - -/* SNIPPET START */ -@riverpod -Stream example(ExampleRef ref) async* { - yield 'foo'; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/auto_dispose.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/auto_dispose.dart deleted file mode 100644 index a08715640..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/auto_dispose.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'auto_dispose.g.dart'; - -/* SNIPPET START */ -// Provider autoDispose (keepAlive è false di default) -@riverpod -String example1(Example1Ref ref) => 'foo'; - -// Provider non autoDispose -@Riverpod(keepAlive: true) -String example2(Example2Ref ref) => 'foo'; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family.dart deleted file mode 100644 index e1ee685fb..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family.g.dart'; - -/* SNIPPET START */ -@riverpod -String example(ExampleRef ref, int param) => 'Hello $param'; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_class.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_class.dart deleted file mode 100644 index 61944fc29..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_class.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family_class.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - String build( - int param1, { - String param2 = 'foo', - }) { - return 'Hello $param1 & param2'; - } - - // Aggiungere i metodi per mutare lo stato -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_fn.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_fn.dart deleted file mode 100644 index 863df6f40..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_fn.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family_fn.g.dart'; - -/* SNIPPET START */ -@riverpod -String example( - ExampleRef ref, - int param1, { - String param2 = 'foo', -}) { - return 'Hello $param1 & param2'; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart deleted file mode 100644 index 8e9d30345..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = AsyncNotifierProvider.autoDispose( - ExampleNotifier.new, -); - -class ExampleNotifier extends AutoDisposeAsyncNotifier { - @override - Future build() async { - return Future.value('foo'); - } - - // Aggiungere i metodi per mutare lo stato -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart deleted file mode 100644 index dfa839778..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -// Provider autoDispose -final example1Provider = Provider.autoDispose((ref) { - return 'foo'; -}); - -// Provider non autoDispose -final example2Provider = Provider((ref) { - return 'foo'; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/family.dart deleted file mode 100644 index a9e59d48d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/family.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = Provider.family((ref, param) { - return 'Hello $param'; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart deleted file mode 100644 index 6306a76fb..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = - FutureProvider.autoDispose((ref) async { - return Future.value('foo'); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart deleted file mode 100644 index a647ce356..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = NotifierProvider.autoDispose( - ExampleNotifier.new, -); - -class ExampleNotifier extends AutoDisposeNotifier { - @override - String build() { - return 'foo'; - } - - // Aggiungere i metodi per mutare lo stato -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/provider.dart deleted file mode 100644 index 1f541352a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/provider.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = Provider.autoDispose( - (ref) { - return 'foo'; - }, -); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart deleted file mode 100644 index 14cb84ab9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = StreamNotifierProvider.autoDispose(() { - return ExampleNotifier(); -}); - -class ExampleNotifier extends AutoDisposeStreamNotifier { - @override - Stream build() async* { - yield 'foo'; - } - - // Aggiungere i metodi per mutare lo stato -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart deleted file mode 100644 index 5e7f8463a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = - StreamProvider.autoDispose((ref) async* { - yield 'foo'; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_class.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_class.dart deleted file mode 100644 index 2da399352..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_class.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'sync_class.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - String build() { - return 'foo'; - } - - // Aggiungere i metodi per mutare lo stato -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_fn.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_fn.dart deleted file mode 100644 index 0d4922734..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_fn.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'sync_fn.g.dart'; - -/* SNIPPET START */ -@riverpod -String example(ExampleRef ref) { - return 'foo'; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/raw.dart deleted file mode 100644 index 4630c27ff..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_codegen/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types, avoid_unused_constructor_parameters - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class User { - User.fromJson(Object obj); -} - -class Http { - Future get(String str) async => str; -} - -final http = Http(); - -/* SNIPPET START */ -final fetchUserProvider = FutureProvider.autoDispose.family((ref, userId) async { - final json = await http.get('api/user/$userId'); - return User.fromJson(json); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx index 5b9bcfb84..d7caff990 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx @@ -2,9 +2,9 @@ title: Informazioni sugli hook --- -import hookAndConsumer from "!!raw-loader!./about_hooks/hook_and_consumer.dart"; -import hookConsumer from "!!raw-loader!./about_hooks/hook_consumer.dart"; -import hookConsumerWidget from "!!raw-loader!./about_hooks/hook_consumer_widget.dart"; +import hookAndConsumer from "!!raw-loader!/docs/concepts/about_hooks/hook_and_consumer.dart"; +import hookConsumer from "!!raw-loader!/docs/concepts/about_hooks/hook_consumer.dart"; +import hookConsumerWidget from "!!raw-loader!/docs/concepts/about_hooks/hook_consumer_widget.dart"; import { CodeSnippet } from "../../../../../src/components/CodeSnippet"; import { Link } from "../../../../../src/components/Link"; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_and_consumer.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_and_consumer.dart deleted file mode 100644 index 601825dea..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_and_consumer.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../providers/creating_a_provider/codegen.dart'; - -class MyValue {} - -/* SNIPPET START */ - -class Example extends StatelessWidget { - @override - Widget build(BuildContext context) { - // Possiamo utilizzare i builder forniti da entrambi i pacchetti - return Consumer( - builder: (context, ref, child) { - return HookBuilder(builder: (context) { - final counter = useState(0); - final value = ref.watch(myProvider); - - return Text('Hello $counter $value'); - }); - }, - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer.dart deleted file mode 100644 index e74e6bcb1..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer.dart +++ /dev/null @@ -1,26 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../providers/creating_a_provider/codegen.dart'; - -class MyValue {} - -/* SNIPPET START */ - -class Example extends StatelessWidget { - @override - Widget build(BuildContext context) { - // L'equivalente di usare Consumer e HookBuilder insieme. - return HookConsumer( - builder: (context, ref, child) { - final counter = useState(0); - final value = ref.watch(myProvider); - - return Text('Hello $counter $value'); - }, - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer_widget.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer_widget.dart deleted file mode 100644 index e4c9499b1..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer_widget.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../providers/creating_a_provider/codegen.dart'; - -class MyValue {} - -/* SNIPPET START */ - -// Estendiamo HookConsumerWidget invece di HookWidget -class Example extends HookConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Possiamo utilizzare sia gli hook che i provider qui - final counter = useState(0); - final value = ref.watch(myProvider); - - return Text('Hello $counter $value'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/codegen.dart deleted file mode 100644 index b544b3778..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/codegen.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import 'models.dart'; - -part 'codegen.g.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -// The current search filter -final searchProvider = StateProvider((ref) => ''); - -@riverpod -Stream configs(ConfigsRef ref) { - return Stream.value(Configuration()); -} - -@riverpod -Future> characters(CharactersRef ref) async { - final search = ref.watch(searchProvider); - final configs = await ref.watch(configsProvider.future); - final response = await dio.get>>( - '${configs.host}/characters?search=$search'); - - return response.data!.map(Character.fromJson).toList(); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/models.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/models.dart deleted file mode 100644 index e21e1d7c6..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/models.dart +++ /dev/null @@ -1,17 +0,0 @@ - -class Character { - Character(); - - // ignore: avoid_unused_constructor_parameters - factory Character.fromJson(Map json) { - return Character(); - } -} - -class Configuration { - Configuration({ - this.host = '', - }); - - final String host; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/raw.dart deleted file mode 100644 index 948148bd0..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'models.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -// The current search filter -final searchProvider = StateProvider((ref) => ''); - -/// Configurations which can change over time -final configsProvider = StreamProvider( - (ref) => Stream.value(Configuration()), -); - -final charactersProvider = FutureProvider>((ref) async { - final search = ref.watch(searchProvider); - final configs = await ref.watch(configsProvider.future); - final response = await dio.get>>( - '${configs.host}/characters?search=$search'); - - return response.data!.map(Character.fromJson).toList(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/codegen.dart deleted file mode 100644 index 8b8f234b9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/codegen.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -String city(CityRef ref) => 'London'; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/raw.dart deleted file mode 100644 index d8093431c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/raw.dart +++ /dev/null @@ -1,4 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final cityProvider = Provider((ref) => 'London'); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/codegen.dart deleted file mode 100644 index 0d2e49b28..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/codegen.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../todo_list_provider/raw.dart'; - -part 'codegen.g.dart'; - -enum Filter { - none, - completed, - uncompleted, -} - -final filterProvider = StateProvider((ref) => Filter.none); - -/* SNIPPET START */ - -@riverpod -List filteredTodoList(FilteredTodoListRef ref) { - final filter = ref.watch(filterProvider); - final todos = ref.watch(todoListProvider); - - switch (filter) { - case Filter.none: - return todos; - case Filter.completed: - return todos.where((todo) => todo.completed).toList(); - case Filter.uncompleted: - return todos.where((todo) => !todo.completed).toList(); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/raw.dart deleted file mode 100644 index 85885e800..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/raw.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../todo_list_provider/raw.dart'; - -enum Filter { - none, - completed, - uncompleted, -} - -final filterProvider = StateProvider((ref) => Filter.none); - -/* SNIPPET START */ - -final filteredTodoListProvider = Provider>((ref) { - final filter = ref.watch(filterProvider); - final todos = ref.watch(todoListProvider); - - switch (filter) { - case Filter.none: - return todos; - case Filter.completed: - return todos.where((todo) => todo.completed).toList(); - case Filter.uncompleted: - return todos.where((todo) => !todo.completed).toList(); - } -}); \ No newline at end of file diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/codegen.dart deleted file mode 100644 index b1cb3dbe3..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -MyValue another(AnotherRef ref) => MyValue(); - -class MyValue {} - -/* SNIPPET START */ - -@riverpod -MyValue my(MyRef ref) { - // Bad practice to call `read` here - final value = ref.read(anotherProvider); - return value; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/raw.dart deleted file mode 100644 index 76bae4653..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -final anotherProvider = Provider((ref) => MyValue()); - -class MyValue {} - -/* SNIPPET START */ - -final myProvider = Provider((ref) { - // Bad practice to call `read` here - final value = ref.read(anotherProvider); - return value; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/codegen.dart deleted file mode 100644 index e44e202bc..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/codegen.dart +++ /dev/null @@ -1,25 +0,0 @@ - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import 'models.dart'; - -part 'codegen.g.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -@riverpod -Stream config(ConfigRef ref) => Stream.value(Configuration()); - -@riverpod -Future> products(ProductsRef ref) async { - // Listens only to the host. If something else in the configurations - // changes, this will not pointlessly re-evaluate our provider. - final host = await ref.watch(configProvider.selectAsync((config) => config.host)); - - final result = await dio.get>>('$host/products'); - - return result.data!.map(Product.fromJson).toList(); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/models.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/models.dart deleted file mode 100644 index 3a711b4b6..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/models.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: sort_constructors_first - -class Product { - const Product({this.title = ''}); - - final String title; - - factory Product.fromJson(Map map) { - return Product( - title: map['title'] as String, - ); - } -} - -class Configuration { - Configuration({ - this.host = '', - }); - - final String host; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/raw.dart deleted file mode 100644 index ae35300b0..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'models.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -final configProvider = - StreamProvider((ref) => Stream.value(Configuration())); - -final productsProvider = FutureProvider>((ref) async { - // Listens only to the host. If something else in the configurations - // changes, this will not pointlessly re-evaluate our provider. - final host = await ref.watch(configProvider.selectAsync((config) => config.host)); - final result = await dio.get>>('$host/products'); - - return result.data!.map(Product.fromJson).toList(); -}); \ No newline at end of file diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/codegen.dart deleted file mode 100644 index a1942dbd4..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; -} - -/* SNIPPET START */ - -@riverpod -class TodoList extends _$TodoList { - @override - List build() { - return []; - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/raw.dart deleted file mode 100644 index a341b7f5b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/raw.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: public_member_api_docs, sort_constructors_first -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - // Since Todo is immutable, we implement a method that allows cloning the - // Todo with slightly different content. - Todo copyWith({String? id, String? description, bool? completed}) { - return Todo( - id: id ?? this.id, - description: description ?? this.description, - completed: completed ?? this.completed, - ); - } -} - -/* SNIPPET START */ - -class TodoList extends Notifier> { - @override - List build() { - return []; - } -} - -final todoListProvider = NotifierProvider>(TodoList.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/codegen.dart deleted file mode 100644 index 8f7af2644..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/codegen.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -String city(CityRef ref) => 'London'; - -class Weather {} - -Future fetchWeather({required String city}) async => Weather(); -/* SNIPPET START */ -@riverpod -Future weather(WeatherRef ref) { - // We use `ref.watch` to listen to another provider, and we pass it the provider - // that we want to consume. Here: cityProvider - final city = ref.watch(cityProvider); - - // We can then use the result to do something based on the value of `cityProvider`. - return fetchWeather(city: city); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/raw.dart deleted file mode 100644 index d25ec4ffc..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/raw.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -final cityProvider = Provider((ref) => 'London'); - -class Weather {} - -Future fetchWeather({required String city}) async => Weather(); - -/* SNIPPET START */ - -final weatherProvider = FutureProvider((ref) async { - // We use `ref.watch` to listen to another provider, and we pass it the provider - // that we want to consume. Here: cityProvider - final city = ref.watch(cityProvider); - - // We can then use the result to do something based on the value of `cityProvider`. - return fetchWeather(city: city); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/codegen.dart deleted file mode 100644 index 1a90008ed..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import 'models.dart'; - -part 'codegen.g.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -@riverpod -Stream config(ConfigRef ref) => Stream.value(Configuration()); - -@riverpod -Future> products(ProductsRef ref) async { - // Will cause productsProvider to re-fetch the products if anything in the - // configurations changes - final configs = await ref.watch(configProvider.future); - - final result = - await dio.get>>('${configs.host}/products'); - return result.data!.map(Product.fromJson).toList(); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/models.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/models.dart deleted file mode 100644 index 8009c2fd8..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/models.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -class Product { - Product(); - factory Product.fromJson(Map json) { - return Product(); - } -} - -class Configuration { - Configuration({ - this.host = '', - }); - - final String host; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/raw.dart deleted file mode 100644 index be2be903c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'models.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -final configProvider = - StreamProvider((ref) => Stream.value(Configuration())); - -final productsProvider = FutureProvider>((ref) async { - // Will cause productsProvider to re-fetch the products if anything in the - // configurations changes - final configs = await ref.watch(configProvider.future); - - final result = await dio.get>>('${configs.host}/products'); - return result.data!.map(Product.fromJson).toList(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx index 851b4dbca..2298e4d02 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx @@ -2,14 +2,14 @@ title: Combining Provider States --- -import charactersProvider from "./combining_provider_states/characters_provider"; -import cityProvider from "./combining_provider_states/city_provider"; -import filteredTodoListProvider from "./combining_provider_states/filtered_todo_list_provider"; -import readInProvider from "./combining_provider_states/read_in_provider"; -import selectAsyncProvider from "./combining_provider_states/select_async_provider"; -import todoListProvider from "./combining_provider_states/todo_list_provider"; -import weatherProvider from "./combining_provider_states/weather_provider"; -import wholeObjectProvider from "./combining_provider_states/whole_object_provider"; +import charactersProvider from "/docs/concepts/combining_provider_states/characters_provider"; +import cityProvider from "/docs/concepts/combining_provider_states/city_provider"; +import filteredTodoListProvider from "/docs/concepts/combining_provider_states/filtered_todo_list_provider"; +import readInProvider from "/docs/concepts/combining_provider_states/read_in_provider"; +import selectAsyncProvider from "/docs/concepts/combining_provider_states/select_async_provider"; +import todoListProvider from "/docs/concepts/combining_provider_states/todo_list_provider"; +import weatherProvider from "/docs/concepts/combining_provider_states/weather_provider"; +import wholeObjectProvider from "/docs/concepts/combining_provider_states/whole_object_provider"; import { Link } from "../../../../../src/components/Link"; import { AutoSnippet, diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart deleted file mode 100644 index 4ee7792f9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart +++ /dev/null @@ -1,58 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// Have a counter that is being incremented by the FloatingActionButton -final counterProvider = StateProvider((ref) => 0); - -class Home extends ConsumerWidget { - const Home({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // We want to show a dialog with the count on a button press - return Scaffold( - body: Column( - children: [ - ElevatedButton( - onPressed: () { - showDialog( - context: context, - builder: (c) { - // We wrap the dialog with a ProviderScope widget, providing the - // parent container to ensure the dialog can access the same providers - // that are accessible by the Home widget. - return ProviderScope( - parent: ProviderScope.containerOf(context), - child: const AlertDialog( - content: CounterDisplay(), - ), - ); - }, - ); - }, - child: const Text('Show Dialog'), - ), - ], - ), - floatingActionButton: FloatingActionButton( - child: const Icon(Icons.add), - onPressed: () { - ref.read(counterProvider.notifier).state++; - }, - )); - } -} - -class CounterDisplay extends ConsumerWidget { - const CounterDisplay({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final count = ref.watch(counterProvider); - return Text('$count'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/codegen.dart deleted file mode 100644 index 0977a8087..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/codegen.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: unnecessary_lambdas - -import 'dart:async'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Stream example(ExampleRef ref) { - final streamController = StreamController(); - - ref.onDispose(() { - // Closes the StreamController when the state of this provider is destroyed. - streamController.close(); - }); - - return streamController.stream; -} - diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/raw.dart deleted file mode 100644 index a9b5741d8..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unnecessary_lambdas - -import 'dart:async'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -final example = StreamProvider.autoDispose((ref) { - final streamController = StreamController(); - - ref.onDispose(() { - // Closes the StreamController when the state of this provider is destroyed. - streamController.close(); - }); - - return streamController.stream; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx index d3e776f89..918f5776b 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx @@ -2,7 +2,7 @@ title: Provider Lifecycles --- -import onDispose from "./lifecycle_on_dispose"; +import onDispose from "/docs/concepts/lifecycle_on_dispose"; import { trimSnippet, When, AutoSnippet } from "../../../../../src/components/CodeSnippet"; :::caution diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers.mdx index 2bdf5467d..e9b7c75f7 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers.mdx @@ -2,8 +2,8 @@ title: Providers --- -import creatingProvider from "./providers/creating_a_provider"; -import declaringManyProviders from "./providers/declaring_many_providers"; +import creatingProvider from "/docs/concepts/providers/creating_a_provider"; +import declaringManyProviders from "/docs/concepts/providers/declaring_many_providers"; import { AutoSnippet, } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/codegen.dart deleted file mode 100644 index 8dc6c5e12..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/codegen.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -class MyValue {} - -/* SNIPPET START */ - -@riverpod -MyValue my(MyRef ref) { - return MyValue(); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/raw.dart deleted file mode 100644 index d63faf94b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/raw.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class MyValue {} - -/* SNIPPET START */ - -final myProvider = Provider((ref) { - return MyValue(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/codegen.dart deleted file mode 100644 index a9472e02a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/codegen.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -String city(CityRef ref) => 'London'; -@riverpod -String country(CountryRef ref) => 'England'; - diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/raw.dart deleted file mode 100644 index 60a3d4786..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/raw.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final cityProvider = Provider((ref) => 'London'); -final countryProvider = Provider((ref) => 'England'); \ No newline at end of file diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading.mdx index 78345456a..b090c1dd7 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading.mdx @@ -3,19 +3,19 @@ title: Reading a Provider --- import CodeBlock from "@theme/CodeBlock"; -import counter from "./reading/counter"; -import consumerWidget from "./reading/consumer_widget"; -import consumerStatefulWidget from "./reading/consumer_stateful_widget"; +import counter from "/docs/concepts/reading/counter"; +import consumerWidget from "/docs/concepts/reading/consumer_widget"; +import consumerStatefulWidget from "/docs/concepts/reading/consumer_stateful_widget"; import consumerHook from "!!raw-loader!/docs/concepts/reading/consumer_hook.dart"; -import watch from "./reading/watch"; -import watchBuild from "./reading/watch_build"; -import listen from "./reading/listen"; -import listenBuild from "./reading/listen_build"; -import read from "./reading/read"; -import readBuild from "./reading/read_build"; -import readNotifierBuild from "./reading/read_notifier_build"; -import watchNotifierBuild from "./reading/watch_notifier_build"; -import provider from "./reading/provider"; +import watch from "/docs/concepts/reading/watch"; +import watchBuild from "/docs/concepts/reading/watch_build"; +import listen from "/docs/concepts/reading/listen"; +import listenBuild from "/docs/concepts/reading/listen_build"; +import read from "/docs/concepts/reading/read"; +import readBuild from "/docs/concepts/reading/read_build"; +import readNotifierBuild from "/docs/concepts/reading/read_notifier_build"; +import watchNotifierBuild from "/docs/concepts/reading/watch_notifier_build"; +import provider from "/docs/concepts/reading/provider"; import { trimSnippet, AutoSnippet, diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/hooks.dart deleted file mode 100644 index 7b9118cbc..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/hooks.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends StatefulHookConsumerWidget { - const HomeView({super.key}); - - @override - HomeViewState createState() => HomeViewState(); -} - -class HomeViewState extends ConsumerState { - @override - void initState() { - super.initState(); - // "ref" can be used in all life-cycles of a StatefulWidget. - ref.read(counterProvider); - } - - @override - Widget build(BuildContext context) { - // Like HookConsumerWidget, we can use hooks inside the builder - final state = useState(0); - - // We can also use "ref" to listen to a provider inside the build method - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/index.tsx deleted file mode 100644 index 9c0ae43de..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import hooks from "!!raw-loader!./hooks.dart"; - -export default { - raw, - hooks: hooks, - codegen: raw, - hooksCodegen: hooks, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/raw.dart deleted file mode 100644 index 98d7f3403..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/raw.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends ConsumerStatefulWidget { - const HomeView({super.key}); - - @override - HomeViewState createState() => HomeViewState(); -} - -class HomeViewState extends ConsumerState { - @override - void initState() { - super.initState(); - // "ref" can be used in all life-cycles of a StatefulWidget. - ref.read(counterProvider); - } - - @override - Widget build(BuildContext context) { - // We can also use "ref" to listen to a provider inside the build method - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/hooks.dart deleted file mode 100644 index 1c5547428..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/hooks.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // HookConsumerWidget allows using hooks inside the build method - final state = useState(0); - - // We can also use the ref parameter to listen to providers. - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/index.tsx deleted file mode 100644 index 9c0ae43de..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import hooks from "!!raw-loader!./hooks.dart"; - -export default { - raw, - hooks: hooks, - codegen: raw, - hooksCodegen: hooks, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/raw.dart deleted file mode 100644 index d2df7c5a7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/codegen.dart deleted file mode 100644 index ca1edf42e..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final repositoryProvider = Provider((ref) => Repository()); - -class Repository { - Future post(String url) async {} -} - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - - void increment() { - // Counter can use the "ref" to read other providers - final repository = ref.read(repositoryProvider); - repository.post('...'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/raw.dart deleted file mode 100644 index b97c93b00..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/counter/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -final repositoryProvider = Provider((ref) => Repository()); - -class Repository { - Future post(String url) async {} -} - -/* SNIPPET START */ - -final counterProvider = StateNotifierProvider((ref) { - return Counter(ref); -}); - -class Counter extends StateNotifier { - Counter(this.ref) : super(0); - - final Ref ref; - - void increment() { - // Counter can use the "ref" to read other providers - final repository = ref.read(repositoryProvider); - repository.post('...'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/codegen.dart deleted file mode 100644 index 154e25e27..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/codegen.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; -import '../counter/raw.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -void another(AnotherRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - // ... -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/raw.dart deleted file mode 100644 index ab229db6e..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:riverpod/riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final anotherProvider = Provider((ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - // ... -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen.dart deleted file mode 100644 index e22f4b169..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; -} - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - return Container(); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen_hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen_hooks.dart deleted file mode 100644 index 5b1147d28..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen_hooks.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_hooks.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; -} - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - final greeting = useState('Hello'); - - return Container( - alignment: Alignment.center, - child: Text(greeting.value), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/index.tsx deleted file mode 100644 index a856c4980..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen_hooks from "!!raw-loader!./codegen_hooks.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: codegen_hooks, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw.dart deleted file mode 100644 index e59ddaf57..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = - StateNotifierProvider(Counter.new); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - return Container(); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw_hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw_hooks.dart deleted file mode 100644 index 9f86fc19f..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw_hooks.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = - StateNotifierProvider(Counter.new); - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - final greeting = useState('Hello'); - - return Container( - alignment: Alignment.center, - child: Text(greeting.value), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/codegen.dart deleted file mode 100644 index 201c92f91..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/codegen.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -class Repository { - String get() => ''; -} - -@riverpod -Repository repository(RepositoryRef ref) => Repository(); - -/* SNIPPET START */ - -@riverpod -String value(ValueRef ref) { - // use ref to obtain other providers - final repository = ref.watch(repositoryProvider); - return repository.get(); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/raw.dart deleted file mode 100644 index 28fdfed97..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/provider/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Repository { - void get() {} -} - -final repositoryProvider = Provider((ref) { - return Repository(); -}); - -/* SNIPPET START */ - -final valueProvider = Provider((ref) { - // use ref to obtain other providers - final repository = ref.watch(repositoryProvider); - return repository.get(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen.dart deleted file mode 100644 index 0742ed5e5..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen.dart +++ /dev/null @@ -1,32 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen_hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen_hooks.dart deleted file mode 100644 index 341087cde..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen_hooks.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_hooks.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final greeting = useState('Hello'); - - return Scaffold( - body: Center(child: Text(greeting.value)), - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/index.tsx deleted file mode 100644 index d0caf89aa..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import codegen_hooks from "!!raw-loader!./codegen_hooks.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: codegen_hooks, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/raw.dart deleted file mode 100644 index 7d8685155..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/raw.dart +++ /dev/null @@ -1,26 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = StateNotifierProvider(Counter.new); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/raw_hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/raw_hooks.dart deleted file mode 100644 index acc6ba980..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read/raw_hooks.dart +++ /dev/null @@ -1,31 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = - StateNotifierProvider(Counter.new); - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final greeting = useState('Hello'); - - return Scaffold( - body: Center(child: Text(greeting.value)), - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/codegen.dart deleted file mode 100644 index 9a4347159..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/codegen.dart +++ /dev/null @@ -1,25 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -Widget build(BuildContext context, WidgetRef ref) { - // use "read" to ignore updates on a provider - final counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: counter.increment, - child: const Text('button'), - ); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/raw.dart deleted file mode 100644 index 266e00224..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_build/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -Widget build(BuildContext context, WidgetRef ref) { - // use "read" to ignore updates on a provider - final counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.state++, - child: const Text('button'), - ); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/codegen.dart deleted file mode 100644 index 6bf061abf..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -Widget build(BuildContext context, WidgetRef ref) { - Counter counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.increment(), - child: const Text('button'), - ); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/raw.dart deleted file mode 100644 index 0ec5b5958..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -Widget build(BuildContext context, WidgetRef ref) { - StateController counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.state++, - child: const Text('button'), - ); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/codegen.dart deleted file mode 100644 index 31de6da74..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/codegen.dart +++ /dev/null @@ -1,45 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -/* SNIPPET START */ - -@riverpod -FilterType filterType(FilterTypeRef ref) { - return FilterType.none; -} - -@riverpod -class Todos extends _$Todos { - @override - List build() { - return []; - } -} - -@riverpod -List filteredTodoList(FilteredTodoListRef ref) { - // obtains both the filter and the list of todos - final FilterType filter = ref.watch(filterTypeProvider); - final List todos = ref.watch(todosProvider); - - switch (filter) { - case FilterType.completed: - // return the completed list of todos - return todos.where((todo) => todo.isCompleted).toList(); - case FilterType.none: - // returns the unfiltered list of todos - return todos; - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/raw.dart deleted file mode 100644 index 625c0fe9a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch/raw.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -class TodoList extends StateNotifier> { - TodoList() : super([]); -} - -/* SNIPPET START */ - -final filterTypeProvider = StateProvider((ref) => FilterType.none); -final todosProvider = - StateNotifierProvider>((ref) => TodoList()); - -final filteredTodoListProvider = Provider((ref) { - // obtains both the filter and the list of todos - final FilterType filter = ref.watch(filterTypeProvider); - final List todos = ref.watch(todosProvider); - - switch (filter) { - case FilterType.completed: - // return the completed list of todos - return todos.where((todo) => todo.isCompleted).toList(); - case FilterType.none: - // returns the unfiltered list of todos - return todos; - } -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen.dart deleted file mode 100644 index 80b63d216..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen.dart +++ /dev/null @@ -1,39 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -@riverpod -class TodoList extends _$TodoList { - @override - List build() => []; -} - -/* SNIPPET START */ - -@riverpod -int counter(CounterRef ref) => 0; - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('$counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen_hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen_hooks.dart deleted file mode 100644 index c82698304..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen_hooks.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_hooks.g.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -@riverpod -class TodoList extends _$TodoList { - @override - List build() => []; -} - -/* SNIPPET START */ - -@riverpod -int counter(CounterRef ref) => 0; - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // You can use hooks inside a HookConsumerWidget - final greeting = useState('Hello'); - - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('${greeting.value} $counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/index.tsx deleted file mode 100644 index a856c4980..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen_hooks from "!!raw-loader!./codegen_hooks.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: codegen_hooks, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw.dart deleted file mode 100644 index 8d5d430eb..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -class TodoList extends StateNotifier> { - TodoList() : super([]); -} - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('$counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw_hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw_hooks.dart deleted file mode 100644 index 5f297850a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw_hooks.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -class TodoList extends StateNotifier> { - TodoList() : super([]); -} - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // You can use hooks inside a HookConsumerWidget - final greeting = useState('Hello'); - - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('${greeting.value} $counter'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/codegen.dart deleted file mode 100644 index 6b76d0219..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -Widget build(BuildContext context, WidgetRef ref) { - Counter counter = ref.watch(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.increment(), - child: const Text('button'), - ); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/raw.dart deleted file mode 100644 index 66c630717..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -Widget build(BuildContext context, WidgetRef ref) { - StateController counter = ref.watch(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.state++, - child: const Text('button'), - ); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/scopes.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/scopes.mdx index f53d8315d..7b42d6461 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/scopes.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/scopes.mdx @@ -4,7 +4,6 @@ title: Scopes import CodeBlock from "@theme/CodeBlock"; import asyncInitialization from "!!raw-loader!/docs/concepts/async_initialization.dart"; -import dialogScope from "!!raw-loader!/docs/concepts/dialog_scope.dart"; import themeScope from "!!raw-loader!/docs/concepts/theme_scope.dart"; import subtreeScope from "!!raw-loader!/docs/concepts/subtree_scope.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; @@ -89,18 +88,6 @@ Here is an example that shows how scoping allows you override a dummy provider w {trimSnippet(asyncInitialization)} -## Showing Dialogs - -When you show a `Dialog` or `OverlayEntry`, flutter creates a new `Route` or adds to an `Overlay` that has a different build scope, -so that it can escape the layout of it's parent, and can be shown above other `Routes`. -This presents a problem for `InheritedWidget`s in general, and since [ProviderScope] is an `InheritedWidget`, it is also affected. - -To solve this problem, Riverpod allows you to create a `ProviderScope` that can access the state of all providers in a `parent` scope. - -The following example shows how to use this, to allow a `Dialog` to access the state of a counter from the context that caused the `Dialog` to be shown. - -{trimSnippet(dialogScope)} - ## Subtree Scoping Scoping allows you to override the state of a provider for a specific subtree of your widget tree. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx index 94c1ea43c..d2b252c9a 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx @@ -2,7 +2,7 @@ title: Why Immutability --- -import whyImmutability from "./why_immutability" +import whyImmutability from "/docs/concepts/why_immutability" import { trimSnippet, AutoSnippet, diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/codegen.dart deleted file mode 100644 index fd286a36c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/codegen.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class ThemeNotifier extends _$ThemeNotifier { - @override - ThemeSettings build() => const ThemeSettings( - mode: ThemeMode.light, - primaryColor: Colors.blue, - ); - - void toggle() { - state = state.copyWith(mode: state.mode.toggle); - } - - void setDarkTheme() { - state = state.copyWith(mode: ThemeMode.dark); - } - - void setLightTheme() { - state = state.copyWith(mode: ThemeMode.light); - } - - void setSystemTheme() { - state = state.copyWith(mode: ThemeMode.system); - } - - void setPrimaryColor(Color color) { - state = state.copyWith(primaryColor: color); - } -} - -@freezed -class ThemeSettings with _$ThemeSettings { - const factory ThemeSettings({ - required ThemeMode mode, - required Color primaryColor, - }) = _ThemeSettings; -} - -extension ToggleTheme on ThemeMode { - ThemeMode get toggle { - switch (this) { - case ThemeMode.dark: - return ThemeMode.light; - case ThemeMode.light: - return ThemeMode.dark; - case ThemeMode.system: - return ThemeMode.system; - } - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/raw.dart deleted file mode 100644 index 1e34c694c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/concepts/why_immutability/raw.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final themeProvider = - NotifierProvider(ThemeNotifier.new); - -class ThemeNotifier extends Notifier { - @override - ThemeSettings build() { - return ThemeSettings(mode: ThemeMode.system, primaryColor: Colors.blue); - } - - void toggle() { - state = state.copyWith(mode: state.mode.toggle); - } - - void setDarkTheme() { - state = state.copyWith(mode: ThemeMode.dark); - } - - void setLightTheme() { - state = state.copyWith(mode: ThemeMode.light); - } - - void setSystemTheme() { - state = state.copyWith(mode: ThemeMode.system); - } - - void setPrimaryColor(Color color) { - state = state.copyWith(primaryColor: color); - } -} - -class ThemeSettings { - ThemeSettings({ - required this.mode, - required this.primaryColor, - }); - - final ThemeMode mode; - final Color primaryColor; - - ThemeSettings copyWith({ - ThemeMode? mode, - Color? primaryColor, - }) { - return ThemeSettings( - mode: mode ?? this.mode, - primaryColor: primaryColor ?? this.primaryColor, - ); - } -} - -extension ToggleTheme on ThemeMode { - ThemeMode get toggle { - switch (this) { - case ThemeMode.dark: - return ThemeMode.light; - case ThemeMode.light: - return ThemeMode.dark; - case ThemeMode.system: - return ThemeMode.system; - } - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx index deb6b044b..001fe154f 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx @@ -3,14 +3,14 @@ title: Svuotare la cache e reagire alla cancellazione dello stato --- import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import onDisposeExample from "./auto_dispose/on_dispose_example"; -import codegenKeepAlive from "!!raw-loader!./auto_dispose/codegen_keep_alive.dart"; -import rawAutoDispose from "!!raw-loader!./auto_dispose/raw_auto_dispose.dart"; -import invalidateExample from "!!raw-loader!./auto_dispose/invalidate_example.dart"; -import keepAlive from "./auto_dispose/keep_alive"; -import cacheForExtension from "!!raw-loader!./auto_dispose/cache_for_extension.dart"; -import cacheForUsage from "./auto_dispose/cache_for_usage"; -import invalidateFamilyExample from './auto_dispose/invalidate_family_example' +import onDisposeExample from "/docs/essentials/auto_dispose/on_dispose_example"; +import codegenKeepAlive from "!!raw-loader!/docs/essentials/auto_dispose/codegen_keep_alive.dart"; +import rawAutoDispose from "!!raw-loader!/docs/essentials/auto_dispose/raw_auto_dispose.dart"; +import invalidateExample from "!!raw-loader!/docs/essentials/auto_dispose/invalidate_example.dart"; +import keepAlive from "/docs/essentials/auto_dispose/keep_alive"; +import cacheForExtension from "!!raw-loader!/docs/essentials/auto_dispose/cache_for_extension.dart"; +import cacheForUsage from "/docs/essentials/auto_dispose/cache_for_usage"; +import invalidateFamilyExample from '/docs/essentials/auto_dispose/invalidate_family_example' Fino ad ora, abbiamo visto come creare/aggiornare lo stato dell'applicazione. Ma non abbiamo ancora parlato di quando avviene la distruzione dello stato. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_extension.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_extension.dart deleted file mode 100644 index c815e4979..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_extension.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:async'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -extension CacheForExtension on AutoDisposeRef { - /// Mantiene il provider in vita per [duration]. - void cacheFor(Duration duration) { - // Previene subito lo stato dal essere distrutto. - final link = keepAlive(); - // Dopo che la durata è terminata, riabilitiamo la rimozione automatica - final timer = Timer(duration, link.close); - - // Opzionale: quando il provider viene ricomputato (come con ref.watch), - // cancelliamo il timer rimasto attivo. - onDispose(timer.cancel); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/codegen.dart deleted file mode 100644 index bb8c5b5c3..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../cache_for_extension.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future example(ExampleRef ref) async { - // Mantiene lo stato attivo per 5 minuti - ref.cacheFor(const Duration(minutes: 5)); - - return http.get(Uri.https('example.com')); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/raw.dart deleted file mode 100644 index 03b9280ca..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../cache_for_extension.dart'; - -/* SNIPPET START */ -final provider = FutureProvider.autoDispose((ref) async { - // Mantiene lo stato attivo per 5 minuti - ref.cacheFor(const Duration(minutes: 5)); - - return http.get(Uri.https('example.com')); -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/codegen_keep_alive.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/codegen_keep_alive.dart deleted file mode 100644 index 0cead709f..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/codegen_keep_alive.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_keep_alive.g.dart'; - -/* SNIPPET START */ -// Possiamo specificare "keepAlive" nell'annotazione per disabilitare -// la distruzione automatica dello stato -@Riverpod(keepAlive: true) -int example(ExampleRef ref) { - return 0; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_example.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_example.dart deleted file mode 100644 index b5b8c54d6..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_example.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -// Possiamo specificare autoDispose per abilitare la distruzione automatica dello stato. -final someProvider = Provider.autoDispose((ref) { - return 0; -}); - -/* SNIPPET START */ -class MyWidget extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - return ElevatedButton( - onPressed: () { - // Sul click, distruggiamo il provider. - ref.invalidate(someProvider); - }, - child: const Text('dispose a provider'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/codegen.dart deleted file mode 100644 index 726aca39f..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -late WidgetRef ref; - -/* SNIPPET START */ -@riverpod -String label(LabelRef ref, String userName) { - return 'Hello $userName'; -} - -// ... - -void onTap() { - // Invalida tutte le possibili combinazioni di paramatri di questo provider. - ref.invalidate(labelProvider); - // Invalida una sola specifica combinazione - ref.invalidate(labelProvider('John')); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/raw.dart deleted file mode 100644 index 8cea257a2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -late WidgetRef ref; - -/* SNIPPET START */ -final provider = Provider.autoDispose.family((ref, name) { - return 'Hello $name'; -}); - -// ... - -void onTap() { - // Invalida tutte le possibili combinazioni di paramatri di questo provider. - ref.invalidate(provider); - // Invalida una sola specifica combinazione - ref.invalidate(provider('John')); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/codegen.dart deleted file mode 100644 index 9c1300407..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/codegen.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future example(ExampleRef ref) async { - final response = await http.get(Uri.parse('https://example.com')); - // Manteniamo il provider in vita solo se la richiesta è stata completata correttamente. - // Se la richiesta ha fallito, quando il provider verrà smesso di essere ascoltato, - // lo stato verrà distrutto. - ref.keepAlive(); - - // Possiamo usare il `link` per ristabilire il comportamento di auto-rimozione con: - // link.close(); - - return response.body; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/raw.dart deleted file mode 100644 index cf5d91a85..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -final provider = FutureProvider.autoDispose((ref) async { - final response = await http.get(Uri.parse('https://example.com')); - // Manteniamo il provider in vita solo se la richiesta è stata completata correttamente. - // Se la richiesta ha fallito, quando il provider verrà smesso di essere ascoltato, - // lo stato verrà distrutto. - final link = ref.keepAlive(); - - // Possiamo usare il `link` per ristabilire il comportamento di auto-rimozione con: - // link.close(); - - return response.body; -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/codegen.dart deleted file mode 100644 index 20d142ba4..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:async'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -int other(OtherRef ref) => 0; - -/* SNIPPET START */ -@riverpod -Stream example(ExampleRef ref) { - final controller = StreamController(); - - // Quando lo stato viene distrutto chiudiamo lo StreamController. - ref.onDispose(controller.close); - - // TO-DO: Aggiungere dei valori nello StreamController - return controller.stream; -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/raw.dart deleted file mode 100644 index 43a57802f..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:async'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -final provider = StreamProvider((ref) { - final controller = StreamController(); - - // Quando lo stato viene distrutto chiudiamo lo StreamController. - ref.onDispose(controller.close); - - // TO-DO: Aggiungere dei valori nello StreamController - return controller.stream; -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/raw_auto_dispose.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/raw_auto_dispose.dart deleted file mode 100644 index 25cfc27a6..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/auto_dispose/raw_auto_dispose.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -// Possiamo specificare autoDispose per abilitare la distruzione dello stato automatica. -final provider = Provider.autoDispose((ref) { - return 0; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx index cd2e6b0eb..c9b6e3f58 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx @@ -5,12 +5,12 @@ version: 1 import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import functionalRef from "./combining_requests/functional_ref"; -import notifierRef from "./combining_requests/notifier_ref"; -import watchExample from "./combining_requests/watch_example"; -import watchPlacement from "./combining_requests/watch_placement"; -import listenExample from "./combining_requests/listen_example"; -import readExample from './combining_requests/read_example'; +import functionalRef from "/docs/essentials/combining_requests/functional_ref"; +import notifierRef from "/docs/essentials/combining_requests/notifier_ref"; +import watchExample from "/docs/essentials/combining_requests/watch_example"; +import watchPlacement from "/docs/essentials/combining_requests/watch_placement"; +import listenExample from "/docs/essentials/combining_requests/listen_example"; +import readExample from '/docs/essentials/combining_requests/read_example'; Finora abbiamo visto solo casi in cui le richieste sono indipendenti l'una dall'altra. Tuttavia, un caso d'uso comune è dover eseguire una richiesta in base al risultato di un'altra. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/codegen.dart deleted file mode 100644 index c70c3c363..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/codegen.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -int other(OtherRef ref) => 0; - -/* SNIPPET START */ -@riverpod -int example(ExampleRef ref) { - // "Ref" può essere usato qui per leggere altri provider - final otherValue = ref.watch(otherProvider); - - return 0; -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/raw.dart deleted file mode 100644 index 7088d88c0..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/raw.dart +++ /dev/null @@ -1,14 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = Provider((ref) { - // "Ref" può essere usato qui per leggere altri provider - final otherValue = ref.watch(otherProvider); - - return 0; -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/codegen.dart deleted file mode 100644 index 25c6a2f37..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -@riverpod -int example(ExampleRef ref) { - ref.listen(otherProvider, (previous, next) { - print('Changed from: $previous, next: $next'); - }); - - return 0; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/raw.dart deleted file mode 100644 index 12b578dd0..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = Provider((ref) { - ref.listen(otherProvider, (previous, next) { - print('Changed from: $previous, next: $next'); - }); - - return 0; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/codegen.dart deleted file mode 100644 index 982ffbd8a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/codegen.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -int other(OtherRef ref) => 0; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - int build() { - // "Ref" può essere usato qui per leggere altri provider - final otherValue = ref.watch(otherProvider); - - return 0; - } -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/raw.dart deleted file mode 100644 index 46a6aebe6..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = NotifierProvider(MyNotifier.new); - -class MyNotifier extends Notifier { - @override - int build() { - // "Ref" può essere usato qui per leggere altri provider - final otherValue = ref.watch(otherProvider); - - return 0; - } -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/codegen.dart deleted file mode 100644 index bc66ee22d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - // Non buono! Non usare "read" qui dato che non è reattivo - ref.read(otherProvider); - - return 0; - } - - void increment() { - ref.read(otherProvider); // Usare "read" qui va bene - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/raw.dart deleted file mode 100644 index 2d0c25873..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/raw.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final notifierProvider = NotifierProvider(MyNotifier.new); - -class MyNotifier extends Notifier { - @override - int build() { - // Non buono! Non usare "read" qui dato che non è reattivo - ref.read(otherProvider); - - return 0; - } - - void increment() { - ref.read(otherProvider); // Usare "read" qui va bene - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/codegen.dart deleted file mode 100644 index 7ea3496c2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/codegen.dart +++ /dev/null @@ -1,44 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -const someStream = Stream<({double longitude, double latitude})>.empty(); - -/* SNIPPET START */ -@riverpod -Stream<({double longitude, double latitude})> location(LocationRef ref) { - // TO-DO: Restituire uno stream che ottiene la posizione corrente - return someStream; -} - -@riverpod -Future> restaurantsNearMe(RestaurantsNearMeRef ref) async { - // Usiamo "ref.watch" per ottenere l'ultima posizione. - // Specificando ".future" dopo il provider il nostro codice aspetterà - // che almeno una posizione sia disponibile - final location = await ref.watch(locationProvider.future); - - // Possiamo quindi fare una richiesta di rete basata su questa posizione. - // Per esempio potremmo usare le API di Google Map: - // https://developers.google.com/maps/documentation/places/web-service/search-nearby - final response = await http.get( - Uri.https('maps.googleapis.com', 'maps/api/place/nearbysearch/json', { - 'location': '${location.latitude},${location.longitude}', - 'radius': '1500', - 'type': 'restaurant', - 'key': '', - }), - ); - // Ottiene i nomi dei ristoranti dal JSON - final json = jsonDecode(response.body) as Map; - final results = (json['results'] as List).cast>(); - return results.map((e) => e['name']! as String).toList(); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/raw.dart deleted file mode 100644 index 96f441e0a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/raw.dart +++ /dev/null @@ -1,40 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -const someStream = Stream<({double longitude, double latitude})>.empty(); - -/* SNIPPET START */ -final locationProvider = StreamProvider<({double longitude, double latitude})>((ref) { - // TO-DO: Restituire uno stream che ottiene la posizione corrente - return someStream; -}); - -final restaurantsNearMeProvider = FutureProvider>((ref) async { - // Usiamo "ref.watch" per ottenere l'ultima posizione. - // Specificando ".future" dopo il provider il nostro codice aspetterà - // che almeno una posizione sia disponibile - final location = await ref.watch(locationProvider.future); - - // Possiamo quindi fare una richiesta di rete basata su questa posizione. - // Per esempio potremmo usare le API di Google Map: - // https://developers.google.com/maps/documentation/places/web-service/search-nearby - final response = await http.get( - Uri.https('maps.googleapis.com', 'maps/api/place/nearbysearch/json', { - 'location': '${location.latitude},${location.longitude}', - 'radius': '1500', - 'type': 'restaurant', - 'key': '', - }), - ); - // Ottiene i nomi dei ristoranti dal JSON - final json = jsonDecode(response.body) as Map; - final results = (json['results'] as List).cast>(); - return results.map((e) => e['name']! as String).toList(); -}); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/codegen.dart deleted file mode 100644 index 736d1ecc7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/codegen.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/foundation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -@riverpod -int example(ExampleRef ref) { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - final someListenable = ValueNotifier(0); - someListenable.addListener(() { - ref.watch(otherProvider); // Bad! - }); - - return 0; -} - -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - return 0; - } - - void increment() { - ref.watch(otherProvider); // Bad! - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/raw.dart deleted file mode 100644 index 34fa8f6c9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/raw.dart +++ /dev/null @@ -1,35 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/foundation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = Provider((ref) { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - final someListenable = ValueNotifier(0); - someListenable.addListener(() { - ref.watch(otherProvider); // Bad! - }); - - return 0; -}); - -final notifierProvider = NotifierProvider(MyNotifier.new); - -class MyNotifier extends Notifier { - @override - int build() { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - return 0; - } - - void increment() { - ref.watch(otherProvider); // Bad! - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx index 8c4c8632f..5d46d847e 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx @@ -4,9 +4,9 @@ version: 1 --- import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import consumerExample from "!!raw-loader!./eager_initialization/consumer_example.dart"; -import asyncConsumerExample from "!!raw-loader!./eager_initialization/async_consumer_example.dart"; -import requireValue from "./eager_initialization/require_value"; +import consumerExample from "!!raw-loader!/docs/essentials/eager_initialization/consumer_example.dart"; +import asyncConsumerExample from "!!raw-loader!/docs/essentials/eager_initialization/async_consumer_example.dart"; +import requireValue from "/docs/essentials/eager_initialization/require_value"; Tutti i provider sono inizializzati in modo lazy di default. Questo significa che il provider è inizializzato solo quando viene usato per la prima volta. Tale comportamento è utile per provider che sono diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/async_consumer_example.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/async_consumer_example.dart deleted file mode 100644 index fdbea3fc1..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/async_consumer_example.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors, unused_element - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -final myProvider = FutureProvider((ref) => 0); - -/* SNIPPET START */ -class _EagerInitialization extends ConsumerWidget { - const _EagerInitialization({required this.child}); - final Widget child; - - @override - Widget build(BuildContext context, WidgetRef ref) { - final result = ref.watch(myProvider); - - // Gestisce gli stati di errore e di caricamento - if (result.isLoading) { - return const CircularProgressIndicator(); - } else if (result.hasError) { - return const Text('Oopsy!'); - } - - return child; - } -} -/* SNIPPET END */ - diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/consumer_example.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/consumer_example.dart deleted file mode 100644 index bcdd13982..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/consumer_example.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -final myProvider = Provider((ref) => 0); - -/* SNIPPET START */ -void main() { - runApp(ProviderScope(child: MyApp())); -} - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return const _EagerInitialization( - // TODO: Renderizza la tua app qui - child: MaterialApp(), - ); - } -} - -class _EagerInitialization extends ConsumerWidget { - const _EagerInitialization({required this.child}); - final Widget child; - - @override - Widget build(BuildContext context, WidgetRef ref) { - // Inizializza anticipatamente i provider osservandoli. - // Usando "watch", il provider resterà in vita e non sarà distrutto. - ref.watch(myProvider); - return child; - } -} -/* SNIPPET END */ - diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/codegen.dart deleted file mode 100644 index 5e663533a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -// Un provider inizializzato anticipatamente. -@riverpod -Future example(ExampleRef ref) async => 'Hello world'; - -class MyConsumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final result = ref.watch(exampleProvider); - - // Se il provider è stato correttamente inizializzato anticipatamente, allora puoi - // direttamente leggere il dato con "requireValue". - return Text(result.requireValue); - } -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/raw.dart deleted file mode 100644 index 2c7646f9d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -// Un provider inizializzato anticipatamente. -final exampleProvider = FutureProvider((ref) async => 'Hello world'); - -class MyConsumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final result = ref.watch(exampleProvider); - - // Se il provider è stato correttamente inizializzato anticipatamente, allora puoi - // direttamente leggere il dato con "requireValue". - return Text(result.requireValue); - } -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx index 325aa85cf..4b6a4958e 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx @@ -5,15 +5,15 @@ version: 1 import { Link } from "../../../../../src/components/Link"; import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import noArgProvider from "./passing_args/no_arg_provider"; +import noArgProvider from "/docs/essentials/passing_args/no_arg_provider"; import family from "!!raw-loader!./passing_args/raw/family.dart"; import codegenFamily from "!!raw-loader!./passing_args/codegen/family.dart"; -import consumerProvider from "!!raw-loader!./passing_args/raw/consumer_provider.dart"; -import consumerFamily from "!!raw-loader!./passing_args/raw/consumer_family.dart"; -import consumerListFamily from "!!raw-loader!./passing_args/raw/consumer_list_family.dart"; -import multipleConsumerFamily from "!!raw-loader!./passing_args/raw/multiple_consumer_family.dart"; -import tupleFamily from "!!raw-loader!./passing_args/raw/tuple_family.dart"; -import consumerTupleFamily from "!!raw-loader!./passing_args/raw/consumer_tuple_family.dart"; +import consumerProvider from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_provider.dart"; +import consumerFamily from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_family.dart"; +import consumerListFamily from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_list_family.dart"; +import multipleConsumerFamily from "!!raw-loader!/docs/essentials/passing_args/raw/multiple_consumer_family.dart"; +import tupleFamily from "!!raw-loader!/docs/essentials/passing_args/raw/tuple_family.dart"; +import consumerTupleFamily from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_tuple_family.dart"; In un articolo precedente abbiamo visto come possiamo definire un "provider" per effettuare una semplice richiesta _GET_. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_family.dart deleted file mode 100644 index e7244535b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_family.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../../first_request/raw/activity.dart'; -import 'family.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - AsyncValue activity = ref.watch( - // Il provider è ora una funzione che si aspetta il tipo dell'attività - // Passiamo una costante stringa per ora, per semplicità. - activityProvider('recreational'), - ); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_list_family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_list_family.dart deleted file mode 100644 index 9b1b2e546..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_list_family.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -final activityProvider = Provider.family((ref, id) { - throw UnimplementedError(); -}); - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - // Potremmo aggiornare activityProvider per accettare direttamente una lista di stringhe. - // Poi essere tentati di creare quella lista direttamente nella chiamata di watch. - ref.watch(activityProvider(['recreational', 'cooking'])); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_provider.dart deleted file mode 100644 index 337eab2d1..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_provider.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../../first_request/raw/activity.dart'; -import 'provider.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - AsyncValue activity = ref.watch(activityProvider); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_tuple_family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_tuple_family.dart deleted file mode 100644 index fe1fd80ae..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_tuple_family.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'tuple_family.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - ref.watch( - // Usando un Record possiamo passare i nostri parametri. - // È possibile creare direttamente il record nella chiamata watch - // poiché i record sovrascrivono ==. - activityProvider((type: 'recreational', maxPrice: 40)), - ); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/multiple_consumer_family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/multiple_consumer_family.dart deleted file mode 100644 index b8884f436..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/multiple_consumer_family.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../../first_request/raw/activity.dart'; -import 'family.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - AsyncValue activity = ref.watch( - // Il provider è ora una funzione che si aspetta il tipo dell'attività - // Passiamo una costante stringa per ora, per semplicità. - activityProvider('recreational'), - ); - /* SNIPPET START */ - return Consumer( - builder: (context, ref, child) { - final recreational = ref.watch(activityProvider('recreational')); - final cooking = ref.watch(activityProvider('cooking')); - - // Possiamo quindi visualizzare entrambe le attività. - // Entrambe le richieste avverranno in parallelo e verranno correttamente cachate. - return Column( - children: [ - Text(recreational.valueOrNull?.activity ?? ''), - Text(cooking.valueOrNull?.activity ?? ''), - ], - ); - }, - ); - /* SNIPPET END */ - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/tuple_family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/tuple_family.dart deleted file mode 100644 index eaacf9250..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/tuple_family.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import '../../first_request/raw/activity.dart'; - -/* SNIPPET START */ - -// Definiamo un record che rappresenta gli argomenti che vogliamo passare al provider. -// Renderlo un typedef è opzionale ma può rendere il codice più leggibile. -typedef ActivityParameters = ({String type, int maxPrice}); - -final activityProvider = FutureProvider.autoDispose - // Possiamo usare il record definito prima come tipo degli argomenti. - .family((ref, arguments) async { - final response = await http.get( - Uri( - scheme: 'https', - host: 'boredapi.com', - path: '/api/activity', - queryParameters: { - // Infine, possiamo usare gli argomenti per aggiornare i nostri parametri di query. - 'type': arguments.type, - 'price': arguments.maxPrice, - }, - ), - ); - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx index ea4628be2..142542f30 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx @@ -3,7 +3,7 @@ title: Logging e segnalazione degli errori --- import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import providerObserver from "!!raw-loader!./provider_observer/provider_observer.dart"; +import providerObserver from "!!raw-loader!/docs/essentials/provider_observer/provider_observer.dart"; Riverpod offre nativamente un modo per ascoltare tutti gli eventi che succedono nell'albero dei provider. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/provider_observer/provider_observer.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/provider_observer/provider_observer.dart deleted file mode 100644 index dd75afb01..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/provider_observer/provider_observer.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -class MyObserver extends ProviderObserver { - @override - void didAddProvider( - ProviderBase provider, - Object? value, - ProviderContainer container, - ) { - print('Provider $provider was initialized with $value'); - } - - @override - void didDisposeProvider( - ProviderBase provider, - ProviderContainer container, - ) { - print('Provider $provider was disposed'); - } - - @override - void didUpdateProvider( - ProviderBase provider, - Object? previousValue, - Object? newValue, - ProviderContainer container, - ) { - print('Provider $provider updated from $previousValue to $newValue'); - } - - @override - void providerDidFail( - ProviderBase provider, - Object error, - StackTrace stackTrace, - ProviderContainer container, - ) { - print('Provider $provider threw $error at $stackTrace'); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx index 5902e99a2..be0207fb2 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx @@ -9,11 +9,11 @@ import Legend, { colors } from "./first_request/legend/legend"; import todoListProvider from "./side_effects/todo_list_provider"; import todoListNotifier from "./side_effects/todo_list_notifier"; import todoListNotifierAddTodo from "./side_effects/todo_list_notifier_add_todo"; -import consumerAddTodoCall from "!!raw-loader!./side_effects/raw/consumer_add_todo_call.dart"; -import restAddTodo from "!!raw-loader!./side_effects/raw/rest_add_todo.dart"; -import invalidateSelfAddTodo from "!!raw-loader!./side_effects/raw/invalidate_self_add_todo.dart"; -import manualAddTodo from "!!raw-loader!./side_effects/raw/manual_add_todo.dart"; -import mutableManualAddTodo from "!!raw-loader!./side_effects/raw/mutable_manual_add_todo.dart"; +import consumerAddTodoCall from "!!raw-loader!/docs/essentials/side_effects/raw/consumer_add_todo_call.dart"; +import restAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/rest_add_todo.dart"; +import invalidateSelfAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/invalidate_self_add_todo.dart"; +import manualAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/manual_add_todo.dart"; +import mutableManualAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/mutable_manual_add_todo.dart"; import renderAddTodo from "./side_effects/render_add_todo"; Fino ad ora, abbiamo visto solo come ottenere dati (cioè eseguire una richiesta HTTP _GET_). diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/consumer_add_todo_call.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/consumer_add_todo_call.dart deleted file mode 100644 index b65d27945..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/consumer_add_todo_call.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../raw/todo_list_notifier.dart' show Todo; -import '../raw/todo_list_notifier_add_todo.dart'; - -/* SNIPPET START */ -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return ElevatedButton( - onPressed: () { - // Usando "ref.read" combinato con "myProvider.notifier" possiamo - // ottenere l'istanza della classe del nostro notifier. Ciò ci permette di - // chiamare il metodo "addTodo". - ref.read(todoListProvider.notifier).addTodo(Todo(description: 'Questo è un nuovo todo')); - }, - child: const Text('Aggiungi todo'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/invalidate_self_add_todo.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/invalidate_self_add_todo.dart deleted file mode 100644 index 9487699de..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/invalidate_self_add_todo.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - /* SNIPPET START */ - Future addTodo(Todo todo) async { - // Non ci importa della risposta dell'API - await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - // Una volta che la richiesta è terminata, possiamo marcare la cache locale come sporca. - // Facendo ciò, il metodo "build" sul nostro notifier verrà chiamato asincronamente di nuovo, - // notificando i suoi listener. - ref.invalidateSelf(); - - // (Opzionale) Possiamo quindi aspettare che il nuovo stato venga computato. - // Questo assicura che "addTodo" non venga completato finchè il nuovo stato non è disponibile. - await future; - } -/* SNIPPET END */ -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/manual_add_todo.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/manual_add_todo.dart deleted file mode 100644 index e99cff69d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/manual_add_todo.dart +++ /dev/null @@ -1,40 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - /* SNIPPET START */ - Future addTodo(Todo todo) async { - // Non ci importa della risposta dell'API - await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - // Possiamo quindi aggiornare manualmente la cache locale. Per fare ciò, avremo bisogno - // di ottenere lo stato precedente. - // Attenzione: lo stato precedente potrebbe essere anche in stato di loading o di errore. - // Un modo elegante di gestirlo sarebbe leggere `this.future` invece - // di `this.state`, il che consentirebbe di attendere lo stato di loading e - // generare un errore se lo stato è in uno stato di errore. - final previousState = await future; - - // Possiamo quindi aggiornare lo stato, creando un nuovo oggetto di stato. - // Ciò notificherà i suoi listener. - state = AsyncData([...previousState, todo]); - } -/* SNIPPET END */ -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/mutable_manual_add_todo.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/mutable_manual_add_todo.dart deleted file mode 100644 index 58e615287..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/mutable_manual_add_todo.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - Future addTodo(Todo todo) async { - // Non ci importa della risposta dell'API - await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - /* SNIPPET START */ - final previousState = await future; - // Modifica la lista dei todo in modo mutabile. - previousState.add(todo); - // Notifica manualmente i listener. - ref.notifyListeners(); - /* SNIPPET END */ - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/rest_add_todo.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/rest_add_todo.dart deleted file mode 100644 index 2a70ea672..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/rest_add_todo.dart +++ /dev/null @@ -1,38 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - /* SNIPPET START */ - Future addTodo(Todo todo) async { - // La richiesta POST restituirà una List corrispondente al nuovo stato dell'applicazione - final response = await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - // Decodifichiamo la risposta API e la convertiamo in una List - List newTodos = (jsonDecode(response.body) as List) - .cast>() - .map(Todo.fromJson) - .toList(); - - // Aggiorniamo la cache locale per riflettere il nuovo stato. - // Questo notificherà tutti i suoi ascoltatori. - state = AsyncData(newTodos); - } -/* SNIPPET END */ -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing.mdx index 569e751a7..d9ff23e0b 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing.mdx @@ -3,17 +3,17 @@ title: Testare i tuoi provider --- import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import createContainer from "!!raw-loader!./testing/create_container.dart"; -import unitTest from "!!raw-loader!./testing/unit_test.dart"; -import widgetTest from "!!raw-loader!./testing/widget_test.dart"; -import fullWidgetTest from "!!raw-loader!./testing/full_widget_test.dart"; -import widgetContainerOf from "!!raw-loader!./testing/widget_container_of.dart"; -import providerToMock from "./testing/provider_to_mock"; -import mockProvider from "!!raw-loader!./testing/mock_provider.dart"; -import autoDisposeListen from "!!raw-loader!./testing/auto_dispose_listen.dart"; -import listenProvider from "!!raw-loader!./testing/listen_provider.dart"; -import awaitFuture from "!!raw-loader!./testing/await_future.dart"; -import notifierMock from "./testing/notifier_mock"; +import createContainer from "!!raw-loader!/docs/essentials/testing/create_container.dart"; +import unitTest from "!!raw-loader!/docs/essentials/testing/unit_test.dart"; +import widgetTest from "!!raw-loader!/docs/essentials/testing/widget_test.dart"; +import fullWidgetTest from "!!raw-loader!/docs/essentials/testing/full_widget_test.dart"; +import widgetContainerOf from "!!raw-loader!/docs/essentials/testing/widget_container_of.dart"; +import providerToMock from "/docs/essentials/testing/provider_to_mock"; +import mockProvider from "!!raw-loader!/docs/essentials/testing/mock_provider.dart"; +import autoDisposeListen from "!!raw-loader!/docs/essentials/testing/auto_dispose_listen.dart"; +import listenProvider from "!!raw-loader!/docs/essentials/testing/listen_provider.dart"; +import awaitFuture from "!!raw-loader!/docs/essentials/testing/await_future.dart"; +import notifierMock from "/docs/essentials/testing/notifier_mock"; Una parte fondamentale delle API di Riverpod è l'abilità di testare i tuoi provider in modo isolato. diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/auto_dispose_listen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/auto_dispose_listen.dart deleted file mode 100644 index 6d901503b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/auto_dispose_listen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = Provider((_) => 'Hello world'); - -void main() { - test('Some description', () { - final container = createContainer(); - /* SNIPPET START */ - final subscription = container.listen(provider, (_, __) {}); - - expect( - // Equivalente di `container.read(provider)` - // Ma il provider non verrà distrutto a meno che "subscription" non venga distrutta. - subscription.read(), - 'Some value', - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/await_future.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/await_future.dart deleted file mode 100644 index 060f4c592..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/await_future.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = FutureProvider((_) async => 42); - -void main() { - test('Some description', () async { - // Crea un ProviderContainer per questo test. - // NON condivedere i ProviderContainer tra i vari test. - final container = createContainer(); - - /* SNIPPET START */ - // TODO: usa il container per testare la tua applicazione. - // Il valore atteso è asincrono, quindi dovremmo usare "expectLater" - await expectLater( - // Leggiamo "provider.future" invece di "provider". - // Questo è possibile su provider asincroni e restituisce un future - // che si risolverà con il valore del provider. - container.read(provider.future), - // Possiamo verificare che quel future si risolva con il valore atteso. - // In alternativa possiamo usare "throwsA" per gli errori. - completion('some value'), - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/create_container.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/create_container.dart deleted file mode 100644 index e9441d3b8..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/create_container.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:riverpod/riverpod.dart'; -import 'package:test/test.dart'; - -/// Un'utilità di test che crea un [ProviderContainer] e lo distrugge automaticamente -/// alla fine del test -ProviderContainer createContainer({ - ProviderContainer? parent, - List overrides = const [], - List? observers, -}) { - // Crea un ProviderContainer, permettendo di specificare dei parametri. - final container = ProviderContainer( - parent: parent, - overrides: overrides, - observers: observers, - ); - - // Alla fine del test, distrugge il container - addTearDown(container.dispose); - - return container; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/full_widget_test.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/full_widget_test.dart deleted file mode 100644 index 5b2ee2d94..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/full_widget_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -final provider = Provider((_) => 'some value'); - -class YourWidgetYouWantToTest extends StatelessWidget { - const YourWidgetYouWantToTest({super.key}); - - @override - Widget build(BuildContext context) => const Placeholder(); -} - -/* SNIPPET START */ -void main() { - testWidgets('Some description', (tester) async { - await tester.pumpWidget( - const ProviderScope(child: YourWidgetYouWantToTest()), - ); - - final element = tester.element(find.byType(YourWidgetYouWantToTest)); - final container = ProviderScope.containerOf(element); - - // TODO interagire con i tuoi provider - expect( - container.read(provider), - 'some value', - ); - }); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/listen_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/listen_provider.dart deleted file mode 100644 index d2e840d9b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/listen_provider.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = Provider((_) => 'Hello world'); - -void main() { - test('Some description', () { - final container = createContainer(); - /* SNIPPET START */ - container.listen( - provider, - (previous, next) { - print('The provider changed from $previous to $next'); - }, - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/mock_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/mock_provider.dart deleted file mode 100644 index 0e5b266d2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/mock_provider.dart +++ /dev/null @@ -1,45 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'create_container.dart'; -import 'full_widget_test.dart'; -import 'provider_to_mock/raw.dart'; - -void main() { - testWidgets('Some description', (tester) async { - await tester.pumpWidget( - const ProviderScope(child: YourWidgetYouWantToTest()), - ); - /* SNIPPET START */ - // Nei test unitari, riutilizzando la nostra precedente utilità "createContainer". - final container = createContainer( - // Possiamo specificare una lista di provider da emulare: - overrides: [ - // In questo caso, stiamo imitando "exampleProvider". - exampleProvider.overrideWith((ref) { - // Questa funzione è la tipica funzione di inizializzazione di un provider. - // Qui è dove normalmente chiamaresti "ref.watch" e restituiresti lo stato iniziale. - - // Sostituiamo il valore di default "Hello world" con un valore custom. - // Infine, quando interagiremo con `exampleProvider`, ci ritornerà questo valore. - return 'Hello from tests'; - }), - ], - ); - - // Possiamo anche fare lo stesso nei test di widget usando ProviderScope: - await tester.pumpWidget( - ProviderScope( - // I ProviderScope hanno lo stesso esatto parametro "overrides" - overrides: [ - // Uguale a prima - exampleProvider.overrideWith((ref) => 'Hello from tests'), - ], - child: const YourWidgetYouWantToTest(), - ), - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/codegen.dart deleted file mode 100644 index 84f0fff0b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: prefer_mixin - -import 'package:mockito/mockito.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() => throw UnimplementedError(); -} - -// Il tuo mock necessita di subclassare la classe base del Notifier -class MyNotifierMock extends _$MyNotifier with Mock implements MyNotifier {} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/raw.dart deleted file mode 100644 index d21cc3d0e..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/raw.dart +++ /dev/null @@ -1,14 +0,0 @@ -// ignore_for_file: prefer_mixin - -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:mockito/mockito.dart'; - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() => throw UnimplementedError(); -} - -// Il tuo mock necessita di subclassare la classe base del Notifier -class MyNotifierMock extends Notifier with Mock implements MyNotifier {} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/codegen.dart deleted file mode 100644 index c03802466..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/codegen.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -// Un provider inizializzato anticipatamente -@riverpod -Future example(ExampleRef ref) async => 'Hello world'; -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/raw.dart deleted file mode 100644 index b4eb3aaf0..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/raw.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -// Un provider inizializzato anticipatamente -final exampleProvider = FutureProvider((ref) async => 'Hello world'); -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/unit_test.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/unit_test.dart deleted file mode 100644 index 162c30a72..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/unit_test.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = Provider((_) => 42); - -/* SNIPPET START */ -void main() { - test('Some description', () { - // Crea un ProviderContainer per questo test. - // NON condividere dei ProviderContainer tra i test. - final container = createContainer(); - - // TODO: usare il container per testare la tua applicazione. - expect( - container.read(provider), - equals('some value'), - ); - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/widget_container_of.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/widget_container_of.dart deleted file mode 100644 index 61b2ca36b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/widget_container_of.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'widget_test.dart'; - -void main() { - testWidgets('Some description', (tester) async { - /* SNIPPET START */ - final element = tester.element(find.byType(YourWidgetYouWantToTest)); - final container = ProviderScope.containerOf(element); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/widget_test.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/widget_test.dart deleted file mode 100644 index b4afc835c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/testing/widget_test.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class YourWidgetYouWantToTest extends StatelessWidget { - const YourWidgetYouWantToTest({super.key}); - - @override - Widget build(BuildContext context) => const Placeholder(); -} - -/* SNIPPET START */ -void main() { - testWidgets('Some description', (tester) async { - await tester.pumpWidget( - const ProviderScope(child: YourWidgetYouWantToTest()), - ); - }); -} -/* SNIPPET END */ diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx index 9083ed859..ad158ff42 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx @@ -6,13 +6,13 @@ import { AutoSnippet, When, } from "../../../../../src/components/CodeSnippet"; -import syncDefinition from "./websockets_sync/sync_definition"; -import streamProvider from "./websockets_sync/stream_provider"; -import syncConsumer from "!!raw-loader!./websockets_sync/sync_consumer.dart"; -import rawUsage from "!!raw-loader!./websockets_sync/raw_usage.dart"; -import pipeChangeNotifier from "!!raw-loader!./websockets_sync/pipe_change_notifier.dart"; -import sharedPipeChangeNotifier from "!!raw-loader!./websockets_sync/shared_pipe_change_notifier.dart"; -import changeNotifierProvider from "!!raw-loader!./websockets_sync/change_notifier_provider.dart"; +import syncDefinition from "/docs/essentials/websockets_sync/sync_definition"; +import streamProvider from "/docs/essentials/websockets_sync/stream_provider"; +import syncConsumer from "!!raw-loader!/docs/essentials/websockets_sync/sync_consumer.dart"; +import rawUsage from "!!raw-loader!/docs/essentials/websockets_sync/raw_usage.dart"; +import pipeChangeNotifier from "!!raw-loader!/docs/essentials/websockets_sync/pipe_change_notifier.dart"; +import sharedPipeChangeNotifier from "!!raw-loader!/docs/essentials/websockets_sync/shared_pipe_change_notifier.dart"; +import changeNotifierProvider from "!!raw-loader!/docs/essentials/websockets_sync/change_notifier_provider.dart"; Fino ad ora abbiamo solo coperto come creare un `Future`. Abbiamo fatto ciò apposta, dato che i `Future`s sono una parte fondamentale di come diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/change_notifier_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/change_notifier_provider.dart deleted file mode 100644 index ea3859a27..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/change_notifier_provider.dart +++ /dev/null @@ -1,11 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final myProvider = ChangeNotifierProvider>((ref) { - // Ascolterà ed eliminerà ValueNotifier - // I widget possono quindi "ref.watch" questo provider per ascoltarne gli aggiornamenti. - return ValueNotifier(0); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/pipe_change_notifier.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/pipe_change_notifier.dart deleted file mode 100644 index b030b5dd9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/pipe_change_notifier.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/widgets.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'pipe_change_notifier.g.dart'; - -/* SNIPPET START */ -/// A provider which creates a ValueNotifier and update its listeners -/// whenever the value changes. -@riverpod -ValueNotifier myListenable(MyListenableRef ref) { - final notifier = ValueNotifier(0); - - // Smaltiamo il notifier quando il provider viene distrutto - ref.onDispose(notifier.dispose); - - // Notifica i listener di questo provider ogni volta che il ValueNotifier si aggiorna. - notifier.addListener(ref.notifyListeners); - - return notifier; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/raw_usage.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/raw_usage.dart deleted file mode 100644 index 6a25e47a5..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/raw_usage.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'raw_usage.g.dart'; - -/* SNIPPET START */ -@riverpod -Raw> rawStream(RawStreamRef ref) { - // "Raw" è un typedef. Non c'è bisogno di wrappare - // il valore di ritorno in un costruttore "Raw". - return const Stream.empty(); -} - -class Consumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Il valore non è più convertito in AsyncValue - // e lo stream creato è ritornato come tale. - Stream stream = ref.watch(rawStreamProvider); - return StreamBuilder( - stream: stream, - builder: (context, snapshot) { - return Text('${snapshot.data}'); - }, - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/shared_pipe_change_notifier.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/shared_pipe_change_notifier.dart deleted file mode 100644 index fa41ad22e..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/shared_pipe_change_notifier.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'shared_pipe_change_notifier.g.dart'; - -/* SNIPPET START */ -extension on Ref { - // Possiamo spostare la logica precedente in una estensione Ref. - // Questo abilita il riutilizzo della logica - T disposeAndListenChangeNotifier(T notifier) { - onDispose(notifier.dispose); - notifier.addListener(notifyListeners); - // Restituiamo il notifier per facilitarne di un poco l'utilizzo - return notifier; - } -} - -@riverpod -ValueNotifier myListenable(MyListenableRef ref) { - return ref.disposeAndListenChangeNotifier(ValueNotifier(0)); -} - -@riverpod -ValueNotifier anotherListenable(AnotherListenableRef ref) { - return ref.disposeAndListenChangeNotifier(ValueNotifier(42)); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/codegen.dart deleted file mode 100644 index 0a1030247..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/codegen.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Stream streamExample(StreamExampleRef ref) async* { - // Ogni secondo ritorna un numero da 0 a 41. - // Questo può essere sostituito con uno Stream da Firestore o GraphQL o altro. - for (var i = 0; i < 42; i++) { - yield i; - await Future.delayed(const Duration(seconds: 1)); - } -} - -class Consumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Lo stream è ascoltato e convertito in un AsyncValue - AsyncValue value = ref.watch(streamExampleProvider); - - // Possiamo usare l'AsyncValue per gestire i stati di caricamento/errore e mostrare il dato. - return switch (value) { - AsyncValue(:final error?) => Text('Error: $error'), - AsyncValue(:final valueOrNull?) => Text('$valueOrNull'), - _ => const CircularProgressIndicator(), - }; - } -} -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/index.ts deleted file mode 100644 index 4ee159de8..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/raw.dart deleted file mode 100644 index 07ee676d2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/raw.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final streamExampleProvider = StreamProvider.autoDispose((ref) async* { - // Ogni secondo ritorna un numero da 0 a 41. - // Questo può essere sostituito con uno Stream da Firestore o GraphQL o altro. - for (var i = 0; i < 42; i++) { - yield i; - await Future.delayed(const Duration(seconds: 1)); - } -}); - -class Consumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Lo stream è ascoltato e convertito in un AsyncValue - AsyncValue value = ref.watch(streamExampleProvider); - - // Possiamo usare l'AsyncValue per gestire i stati di caricamento/errore e mostrare il dato. - return switch (value) { - AsyncValue(:final error?) => Text('Error: $error'), - AsyncValue(:final valueOrNull?) => Text('$valueOrNull'), - _ => const CircularProgressIndicator(), - }; - } -} -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_consumer.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_consumer.dart deleted file mode 100644 index bf4aa03f7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_consumer.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'sync_definition/raw.dart'; - -void main() { -/* SNIPPET START */ - Consumer( - builder: (context, ref, child) { - // Il valore non è contenuto in un "AsyncValue" - int value = ref.watch(synchronousExampleProvider); - - return Text('$value'); - }, - ); -/* SNIPPET END */ -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/codegen.dart deleted file mode 100644 index b18b8f76e..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/codegen.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -int synchronousExample(SynchronousExampleRef ref) { - return 0; -} -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/index.ts b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/index.ts deleted file mode 100644 index 4ee159de8..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { raw, codegen }; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/raw.dart deleted file mode 100644 index 9c64294a0..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/raw.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ -final synchronousExampleProvider = Provider.autoDispose((ref) { - return 0; -}); -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/family.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/family.dart deleted file mode 100644 index 4d49c552a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/family.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family.g.dart'; -/* SNIPPET START */ - -@riverpod -int random(RandomRef ref, {required int seed, required int max}) { - return Random(seed).nextInt(max); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/index.tsx deleted file mode 100644 index fa391f61a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./family.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/raw.dart deleted file mode 100644 index 68b84d40d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/family/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'dart:math'; - -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -@immutable -abstract class Equatable { - const Equatable(); - - List get props; -} - -/* SNIPPET START */ -class ParamsType extends Equatable { - const ParamsType({required this.seed, required this.max}); - - final int seed; - final int max; - - @override - List get props => [seed, max]; -} - -final randomProvider = - Provider.family.autoDispose((ref, params) { - return Random(params.seed).nextInt(params.max); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/async_values.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/async_values.dart deleted file mode 100644 index 802a23150..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/async_values.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; -import '../../helpers/json.dart'; - -part 'async_values.g.dart'; - -/* SNIPPET START */ - -@riverpod -Future> itemsApi(ItemsApiRef ref) async { - final client = Dio(); - final result = await client.get>('your-favorite-api'); - final parsed = [...result.data!.map((e) => Item.fromJson(e as Json))]; - return parsed; -} - -@riverpod -List evenItems(EvenItemsRef ref) { - final asyncValue = ref.watch(itemsApiProvider); - if (asyncValue.isReloading) return []; - if (asyncValue.hasError) return const [Item(id: -1)]; - - final items = asyncValue.requireValue; - - return [...items.whereIndexed((index, element) => index.isEven)]; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/index.tsx deleted file mode 100644 index 526f2dffe..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./async_values.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/raw.dart deleted file mode 100644 index 1ca8987ef..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; -import '../../helpers/json.dart'; - -/* SNIPPET START */ - -final itemsApiProvider = FutureProvider.autoDispose((ref) async { - final client = Dio(); - final result = await client.get>('your-favorite-api'); - final parsed = [...result.data!.map((e) => Item.fromJson(e as Json))]; - return parsed; -}); - -final evenItemsProvider = Provider.autoDispose((ref) { - final asyncValue = ref.watch(itemsApiProvider); - if (asyncValue.isLoading) return []; - if (asyncValue.hasError) return const [Item(id: -1)]; - - final items = asyncValue.requireValue; - - return [...items.whereIndexed((index, element) => index.isEven)]; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/auto_dispose.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/auto_dispose.dart deleted file mode 100644 index 079e29de2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/auto_dispose.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'auto_dispose.g.dart'; - -/* SNIPPET START */ - -// Con la generazione di codice, un provider è .autoDispose di default -@riverpod -int diceRoll(DiceRollRef ref) { - // Poiché questo provider è .autoDispose, smettere di ascoltarlo ne disporrà lo stato esposto attuale. - // Quindi, ogni volta che questo provider viene ascoltato di nuovo, - // verrà tirato un nuovo dado e lo stato verrà esposto di nuovo. - final dice = Random().nextInt(10); - return dice; -} - -@riverpod -int cachedDiceRoll(CachedDiceRollRef ref) { - final coin = Random().nextInt(10); - if (coin > 5) throw Exception('Way too large.'); - // La condizione sopra potrebbe fallire; - // Se non lo fa, l'istruzione seguente dice al Provider - // di mantenere il suo stato in cache, *anche quando nessuno lo ascolta più*. - ref.keepAlive(); - return coin; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/index.tsx deleted file mode 100644 index 6c57cfffd..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./auto_dispose.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/raw.dart deleted file mode 100644 index 4847d18d4..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/raw.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ - -final diceRollProvider = Provider.autoDispose((ref) { - // Poiché questo provider è .autoDispose, smettere di ascoltarlo ne disporrà lo stato esposto attuale. - // Quindi, ogni volta che questo provider viene ascoltato di nuovo, - // verrà tirato un nuovo dado e lo stato verrà esposto di nuovo. - final dice = Random().nextInt(10); - return dice.isEven; -}); - -final cachedDiceRollProvider = Provider.autoDispose((ref) { - final coin = Random().nextInt(10); - if (coin > 5) throw Exception('Way too large.'); - // La condizione sopra potrebbe fallire; - // Se non lo fa, l'istruzione seguente dice al Provider - // di mantenere il suo stato in cache, *anche quando nessuno lo ascolta più*. - ref.keepAlive(); - return coin.isEven; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/combine.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/combine.dart deleted file mode 100644 index ecd1915da..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/combine.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'combine.g.dart'; - -/* SNIPPET START */ - -@riverpod -int number(NumberRef ref) { - return Random().nextInt(10); -} - -@riverpod -int doubled(DoubledRef ref) { - final number = ref.watch(numberProvider); - - return number * 2; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/index.tsx deleted file mode 100644 index 2ff7dfbaa..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./combine.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/raw.dart deleted file mode 100644 index ad33636e7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ - -final numberProvider = Provider.autoDispose((ref) { - return Random().nextInt(10); -}); - -final doubledProvider = Provider.autoDispose((ref) { - final number = ref.watch(numberProvider); - - return number * 2; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx index aadb58d49..4241264fb 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx @@ -2,12 +2,12 @@ title: Motivazione --- -import sameType from "./same_type"; -import combine from "./combine"; -import asyncValues from "./async_values"; -import autoDispose from "./auto_dispose"; -import override from "./override"; -import sideEffects from "./side_effects"; +import sameType from "/docs/from_provider/motivation/same_type"; +import combine from "/docs/from_provider/motivation/combine"; +import asyncValues from "/docs/from_provider/motivation/async_values"; +import autoDispose from "/docs/from_provider/motivation/auto_dispose"; +import override from "/docs/from_provider/motivation/override"; +import sideEffects from "/docs/from_provider/motivation/side_effects"; import { AutoSnippet, } from "../../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/index.tsx deleted file mode 100644 index 43ec56b51..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./override.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/override.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/override.dart deleted file mode 100644 index 860020903..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/override.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../combine/combine.dart'; - -/* SNIPPET START */ - -void main() { - test('it doubles the value correctly', () async { - final container = ProviderContainer( - overrides: [numberProvider.overrideWith((ref) => 9)], - ); - final doubled = container.read(doubledProvider); - expect(doubled, 9 * 2); - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/raw.dart deleted file mode 100644 index 860020903..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/override/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../combine/combine.dart'; - -/* SNIPPET START */ - -void main() { - test('it doubles the value correctly', () async { - final container = ProviderContainer( - overrides: [numberProvider.overrideWith((ref) => 9)], - ); - final doubled = container.read(doubledProvider); - expect(doubled, 9 * 2); - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/index.tsx deleted file mode 100644 index 8569e8316..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./same_type.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/raw.dart deleted file mode 100644 index dacfe9b9d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; - -/* SNIPPET START */ - -final itemsProvider = Provider.autoDispose( - (ref) => [], // ... -); - -final evenItemsProvider = Provider.autoDispose((ref) { - final items = ref.watch(itemsProvider); - return [...items.whereIndexed((index, element) => index.isEven)]; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/same_type.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/same_type.dart deleted file mode 100644 index 94a4ab086..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/same_type.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; - -part 'same_type.g.dart'; - -/* SNIPPET START */ - -@riverpod -List items(ItemsRef ref) { - return []; // ... -} - -@riverpod -List evenItems(EvenItemsRef ref) { - final items = ref.watch(itemsProvider); - return [...items.whereIndexed((index, element) => index.isEven)]; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/index.tsx deleted file mode 100644 index f4797a94f..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./side_effects.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/raw.dart deleted file mode 100644 index 61f016870..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/raw.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../auto_dispose/auto_dispose.dart'; - -/* SNIPPET START */ - -class DiceRollWidget extends ConsumerWidget { - const DiceRollWidget({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(diceRollProvider, (previous, next) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Dice roll! We got: $next')), - ); - }); - return TextButton.icon( - onPressed: () => ref.invalidate(diceRollProvider), - icon: const Icon(Icons.casino), - label: const Text('Roll a dice'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/side_effects.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/side_effects.dart deleted file mode 100644 index 61f016870..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/side_effects.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../auto_dispose/auto_dispose.dart'; - -/* SNIPPET START */ - -class DiceRollWidget extends ConsumerWidget { - const DiceRollWidget({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(diceRollProvider, (previous, next) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Dice roll! We got: $next')), - ); - }); - return TextButton.icon( - onPressed: () => ref.invalidate(diceRollProvider), - icon: const Icon(Icons.casino), - label: const Text('Roll a dice'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx index dff3aaa22..10fb0b42d 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx @@ -2,7 +2,7 @@ title: Provider vs Riverpod --- -import family from "./family"; +import family from "/docs/from_provider/family"; import { AutoSnippet, } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx index 941063d06..bce9b921b 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx @@ -8,9 +8,9 @@ import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; import pubspec from "./getting_started/pubspec"; -import dartHelloWorld from "./getting_started/dart_hello_world"; +import dartHelloWorld from "/docs/introduction/getting_started/dart_hello_world"; import pubadd from "./getting_started/pub_add"; -import helloWorld from "./getting_started/hello_world"; +import helloWorld from "/docs/introduction/getting_started/hello_world"; import dartPubspec from "./getting_started/dart_pubspec"; import dartPubadd from "./getting_started/dart_pub_add"; import { diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/index.tsx deleted file mode 100644 index 898aa0914..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./main.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/main.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/main.dart deleted file mode 100644 index 4394668b2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/main.dart +++ /dev/null @@ -1,25 +0,0 @@ -// ignore_for_file: avoid_print - -/* SNIPPET START */ - -import 'package:riverpod/riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -// Creiamo un "provider", che conterrà un valore (qui "Hello, world"). -// Utilizzando un provider, ciò ci consente di simulare/sostituire il valore esposto. -@riverpod -String helloWorld(HelloWorldRef ref) { - return 'Hello world'; -} - -void main() { - // Questo oggetto è dove lo stato dei nostri provider sarà salvato. - final container = ProviderContainer(); - - // Grazie a "container", possiamo leggere il nostro provider. - final value = container.read(helloWorldProvider); - - print(value); // Hello world -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/raw.dart deleted file mode 100644 index 445bc0a9c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: avoid_print - -/* SNIPPET START */ - -import 'package:riverpod/riverpod.dart'; - -// We create a "provider", which will store a value (here "Hello world"). -// By using a provider, this allows us to mock/override the value exposed. -final helloWorldProvider = Provider((_) => 'Hello world'); - -void main() { - // This object is where the state of our providers will be stored. - final container = ProviderContainer(); - - // Thanks to "container", we can read our provider. - final value = container.read(helloWorldProvider); - - print(value); // Hello world -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/hooks_codegen/main.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/hooks_codegen/main.dart deleted file mode 100644 index d2929e44b..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/hooks_codegen/main.dart +++ /dev/null @@ -1,46 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -// Creiamo un "provider", che conterrà un valore (qui "Hello, world"). -// Utilizzando un provider, ciò ci consente di simulare/sostituire il valore esposto. -@riverpod -String helloWorld(HelloWorldRef ref) { - return 'Hello world'; -} - -void main() { - runApp( - // Per consentire ai widget di leggere i provider, è necessario incapsulare l'intera - // applicazione in un widget "ProviderScope". - // Questo è il luogo in cui verrà memorizzato lo stato dei nostri provider. - ProviderScope( - child: MyApp(), - ), - ); -} - -// Estendiamo HookConsumerWidget invece di StatelessWidget, il quale è esposto da Riverpod -class MyApp extends HookConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Possiamo usare gli hooks all'interno di un HookConsumerWidget - final counter = useState(0); - - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text('$value ${counter.value}'), - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/index.tsx deleted file mode 100644 index 3f10c2a94..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen from "!!raw-loader!./main.dart"; -import hooksCodegen from "!!raw-loader!./hooks_codegen/main.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: hooksCodegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/main.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/main.dart deleted file mode 100644 index 535266fa1..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/main.dart +++ /dev/null @@ -1,42 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -// Creiamo un "provider", che conterrà un valore (qui "Hello, world"). -// Utilizzando un provider, ciò ci consente di simulare/sostituire il valore esposto. -@riverpod -String helloWorld(HelloWorldRef ref) { - return 'Hello world'; -} - -void main() { - runApp( - // Per consentire ai widget di leggere i provider, è necessario incapsulare l'intera - // applicazione in un widget "ProviderScope". - // Questo è il luogo in cui verrà memorizzato lo stato dei nostri provider. - ProviderScope( - child: MyApp(), - ), - ); -} - -// Estendiamo ConsumerWidget invece di StatelessWidget, il quale è esposto da Riverpod -class MyApp extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text(value), - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw.dart deleted file mode 100644 index 7cbad6012..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -// Creiamo un "provider", che conterrà un valore (qui "Hello, world"). -// Utilizzando un provider, ciò ci consente di simulare/sostituire il valore esposto. -final helloWorldProvider = Provider((_) => 'Hello world'); - -void main() { - runApp( - // Per consentire ai widget di leggere i provider, è necessario incapsulare l'intera - // applicazione in un widget "ProviderScope". - // Questo è il luogo in cui verrà memorizzato lo stato dei nostri provider. - ProviderScope( - child: MyApp(), - ), - ); -} - -// Estendiamo ConsumerWidget invece di StatelessWidget, il quale è esposto da Riverpod -class MyApp extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text(value), - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw_hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw_hooks.dart deleted file mode 100644 index 57ddda404..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw_hooks.dart +++ /dev/null @@ -1,40 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -// Creiamo un "provider", che conterrà un valore (qui "Hello, world"). -// Utilizzando un provider, ciò ci consente di simulare/sostituire il valore esposto. -final helloWorldProvider = Provider((_) => 'Hello world'); - -void main() { - runApp( - // Per consentire ai widget di leggere i provider, è necessario incapsulare l'intera - // applicazione in un widget "ProviderScope". - // Questo è il luogo in cui verrà memorizzato lo stato dei nostri provider. - ProviderScope( - child: MyApp(), - ), - ); -} - -// Estendiamo HookConsumerWidget invece di StatelessWidget, il quale è esposto da Riverpod -class MyApp extends HookConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Possiamo usare gli hooks all'interno di un HookConsumerWidget - final counter = useState(0); - - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text('$value ${counter.value}'), - ), - ), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx index c556de7cd..bc9ebccf4 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx @@ -3,7 +3,7 @@ title: Perché Riverpod? version: 1 --- -import whyRiverpod from "./why_riverpod"; +import whyRiverpod from "/docs/introduction/why_riverpod"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; ## Che cos'è Riverpod? diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/codegen.dart deleted file mode 100644 index 3e2022906..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/codegen.dart +++ /dev/null @@ -1,31 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -class Package { - static Package fromJson(dynamic json) { - throw UnimplementedError(); - } -} - -/* SNIPPET START */ - -// Recupera l'elenco dei package da pub.dev -@riverpod -Future> fetchPackages( - FetchPackagesRef ref, { - required int page, - String search = '', -}) async { - final dio = Dio(); - // Effettua una richiesta API. Qui stiamo utilizzando il package 'dio', ma potremmo usare qualsiasi altro package. - final response = await dio.get>( - 'https://pub.dartlang.org/api/search?page=$page&q=${Uri.encodeQueryComponent(search)}', - ); - - // Decodifica la risposta JSON in una classe Dart. - return response.data?.map(Package.fromJson).toList() ?? const []; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/raw.dart deleted file mode 100644 index b79a3debd..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/introduction/why_riverpod/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Package { - static Package fromJson(dynamic json) { - throw UnimplementedError(); - } -} - -/* SNIPPET START */ - -// Recupera l'elenco dei package da pub.dev -final fetchPackagesProvider = FutureProvider.autoDispose - .family, ({int page, String? search})>((ref, params) async { - final page = params.page; - final search = params.search ?? ''; - final dio = Dio(); - // Effettua una richiesta API. Qui stiamo utilizzando il package 'dio', ma potremmo usare qualsiasi altro package. - final response = await dio.get>( - 'https://pub.dartlang.org/api/search?page=$page&q=${Uri.encodeQueryComponent(search)}', - ); - - // Decodifica la risposta JSON in una classe Dart. - return response.data?.map(Package.fromJson).toList() ?? const []; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx index 69d0f8ab0..05ac7c1b3 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx @@ -2,10 +2,10 @@ title: Da `ChangeNotifier` --- -import old from "!!raw-loader!./from_change_notifier/old.dart"; -import declaration from "./from_change_notifier/declaration"; -import initialization from "./from_change_notifier/initialization"; -import migrated from "./from_change_notifier/migrated"; +import old from "!!raw-loader!/docs/migration/from_change_notifier/old.dart"; +import declaration from "/docs/migration/from_change_notifier/declaration"; +import initialization from "/docs/migration/from_change_notifier/initialization"; +import migrated from "/docs/migration/from_change_notifier/migrated"; import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/declaration.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/declaration.dart deleted file mode 100644 index b3ca06ef2..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/declaration.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'declaration.g.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - FutureOr> build() { - // TODO ... - return []; - } - - Future addTodo(Todo todo) async { - // TODO - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/index.tsx deleted file mode 100644 index 1ad659c31..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./declaration.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/raw.dart deleted file mode 100644 index c7485bbba..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/raw.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends AutoDisposeAsyncNotifier> { - @override - FutureOr> build() { - // TODO ... - return []; - } - - Future addTodo(Todo todo) async { - // TODO - } -} - -final myNotifierProvider = AsyncNotifierProvider.autoDispose(MyNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/index.tsx deleted file mode 100644 index 3b3fbd2cb..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./initialization.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/initialization.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/initialization.dart deleted file mode 100644 index 4da805e13..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/initialization.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'initialization.g.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - return [...json.map(Todo.fromJson)]; - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/raw.dart deleted file mode 100644 index 24ab265f7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/raw.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends AutoDisposeAsyncNotifier> { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - return [...json.map(Todo.fromJson)]; - } -} - -final myNotifierProvider = AsyncNotifierProvider.autoDispose(MyNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/index.tsx deleted file mode 100644 index 075bfbdf5..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./migrated.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/migrated.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/migrated.dart deleted file mode 100644 index b8f4ba829..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/migrated.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'migrated.g.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - Future addTodo(Todo todo) async { - // optional: state = const AsyncLoading(); - final json = await http.post('api/todos'); - final newTodos = [...json.map(Todo.fromJson)]; - state = AsyncData(newTodos); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/raw.dart deleted file mode 100644 index 8572db71d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/raw.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends AutoDisposeAsyncNotifier> { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - Future addTodo(Todo todo) async { - // optional: state = const AsyncLoading(); - final json = await http.post('api/todos'); - final newTodos = [...json.map(Todo.fromJson)]; - state = AsyncData(newTodos); - } -} - -final myNotifierProvider = AsyncNotifierProvider.autoDispose(MyNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/old.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/old.dart deleted file mode 100644 index 4e65e823d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_change_notifier/old.dart +++ /dev/null @@ -1,60 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -class MyChangeNotifier extends ChangeNotifier { - MyChangeNotifier() { - _init(); - } - List todos = []; - bool isLoading = true; - bool hasError = false; - - Future _init() async { - try { - final json = await http.get('api/todos'); - todos = [...json.map(Todo.fromJson)]; - } on Exception { - hasError = true; - } finally { - isLoading = false; - notifyListeners(); - } - } - - Future addTodo(int id) async { - isLoading = true; - notifyListeners(); - - try { - final json = await http.post('api/todos'); - todos = [...json.map(Todo.fromJson)]; - hasError = false; - } on Exception { - hasError = true; - } finally { - isLoading = false; - notifyListeners(); - } - } -} - -final myChangeProvider = ChangeNotifierProvider((ref) { - return MyChangeNotifier(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx index 23f96416f..96d6e1411 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx @@ -2,21 +2,21 @@ title: Da `StateNotifier` --- -import buildInit from "./from_state_notifier/build_init"; -import buildInitOld from "!!raw-loader!./from_state_notifier/build_init_old.dart"; -import consumersDontChange from "!!raw-loader!./from_state_notifier/consumers_dont_change.dart"; -import familyAndDispose from "./from_state_notifier/family_and_dispose"; -import familyAndDisposeOld from "!!raw-loader!./from_state_notifier/family_and_dispose_old.dart"; -import asyncNotifier from "./from_state_notifier/async_notifier"; -import asyncNotifierOld from "!!raw-loader!./from_state_notifier/async_notifier_old.dart"; -import addListener from "./from_state_notifier/add_listener"; -import addListenerOld from "!!raw-loader!./from_state_notifier/add_listener_old.dart"; -import fromStateProvider from "./from_state_notifier/from_state_provider"; -import fromStateProviderOld from "!!raw-loader!./from_state_notifier/from_state_provider_old.dart"; -import oldLifecycles from "./from_state_notifier/old_lifecycles"; -import oldLifecyclesOld from "!!raw-loader!./from_state_notifier/old_lifecycles_old.dart"; -import oldLifecyclesFinal from "./from_state_notifier/old_lifecycles_final"; -import obtainNotifierOnTests from "!!raw-loader!./from_state_notifier/obtain_notifier_on_tests.dart"; +import buildInit from "/docs/migration/from_state_notifier/build_init"; +import buildInitOld from "!!raw-loader!/docs/migration/from_state_notifier/build_init_old.dart"; +import consumersDontChange from "!!raw-loader!/docs/migration/from_state_notifier/consumers_dont_change.dart"; +import familyAndDispose from "/docs/migration/from_state_notifier/family_and_dispose"; +import familyAndDisposeOld from "!!raw-loader!/docs/migration/from_state_notifier/family_and_dispose_old.dart"; +import asyncNotifier from "/docs/migration/from_state_notifier/async_notifier"; +import asyncNotifierOld from "!!raw-loader!/docs/migration/from_state_notifier/async_notifier_old.dart"; +import addListener from "/docs/migration/from_state_notifier/add_listener"; +import addListenerOld from "!!raw-loader!/docs/migration/from_state_notifier/add_listener_old.dart"; +import fromStateProvider from "/docs/migration/from_state_notifier/from_state_provider"; +import fromStateProviderOld from "!!raw-loader!/docs/migration/from_state_notifier/from_state_provider_old.dart"; +import oldLifecycles from "/docs/migration/from_state_notifier/old_lifecycles"; +import oldLifecyclesOld from "!!raw-loader!/docs/migration/from_state_notifier/old_lifecycles_old.dart"; +import oldLifecyclesFinal from "/docs/migration/from_state_notifier/old_lifecycles_final"; +import obtainNotifierOnTests from "!!raw-loader!/docs/migration/from_state_notifier/obtain_notifier_on_tests.dart"; import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/add_listener.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/add_listener.dart deleted file mode 100644 index ead1c72d8..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/add_listener.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter/material.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'add_listener.g.dart'; - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - ref.listenSelf((_, next) => debugPrint('$next')); - return 0; - } - - void add() => state++; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/index.tsx deleted file mode 100644 index 6d7ac6d37..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./add_listener.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/raw.dart deleted file mode 100644 index e25b4a181..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter/material.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() { - ref.listenSelf((_, next) => debugPrint('$next')); - return 0; - } - - void add() => state++; -} - -final myNotifierProvider = NotifierProvider(MyNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener_old.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener_old.dart deleted file mode 100644 index 1f020617c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener_old.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -class MyNotifier extends StateNotifier { - MyNotifier() : super(0); - - void add() => state++; -} - -final myNotifierProvider = StateNotifierProvider((ref) { - final notifier = MyNotifier(); - - final cleanup = notifier.addListener((state) => debugPrint('$state')); - ref.onDispose(cleanup); - - // O in modo equivalente: - // final listener = notifier.stream.listen((event) => debugPrint('$event')); - // ref.onDispose(listener.cancel); - - return notifier; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/async_notifier.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/async_notifier.dart deleted file mode 100644 index 5ead76378..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/async_notifier.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_notifier.g.dart'; - -class Todo { - Todo.fromJson(Object obj); -} - -class Http { - Future> get(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class AsyncTodosNotifier extends _$AsyncTodosNotifier { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - // ... -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/index.tsx deleted file mode 100644 index a0ff513c3..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./async_notifier.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/raw.dart deleted file mode 100644 index 52da61d76..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/raw.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - Todo.fromJson(Object obj); -} - -class Http { - Future> get(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -class AsyncTodosNotifier extends AsyncNotifier> { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - // ... -} - -final asyncTodosNotifier = AsyncNotifierProvider>( - AsyncTodosNotifier.new, -); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier_old.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier_old.dart deleted file mode 100644 index 50d7f4aed..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier_old.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class Todo { - Todo.fromJson(Object obj); -} - -class Http { - Future> get(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -class AsyncTodosNotifier extends StateNotifier>> { - AsyncTodosNotifier() : super(const AsyncLoading()) { - _postInit(); - } - - Future _postInit() async { - state = await AsyncValue.guard(() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - }); - } - - // ... -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/build_init.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/build_init.dart deleted file mode 100644 index 3e2303b7a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/build_init.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'build_init.g.dart'; - -/* SNIPPET START */ -@riverpod -class CounterNotifier extends _$CounterNotifier { - @override - int build() => 0; - - void increment() => state++; - void decrement() => state++; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/index.tsx deleted file mode 100644 index 276a143ac..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./build_init.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/raw.dart deleted file mode 100644 index 0ba8eebed..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -class CounterNotifier extends Notifier { - @override - int build() => 0; - - void increment() => state++; - void decrement() => state++; -} - -final counterNotifierProvider = NotifierProvider(CounterNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init_old.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init_old.dart deleted file mode 100644 index 82a8c54bd..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init_old.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -class CounterNotifier extends StateNotifier { - CounterNotifier() : super(0); - - void increment() => state++; - void decrement() => state++; -} - -final counterNotifierProvider = StateNotifierProvider((ref) { - return CounterNotifier(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/consumers_dont_change.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/consumers_dont_change.dart deleted file mode 100644 index 6a964a5a6..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/consumers_dont_change.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class CounterNotifier extends StateNotifier { - CounterNotifier() : super(0); - - void increment() => state++; - void decrement() => state++; -} - -final counterNotifierProvider = StateNotifierProvider((ref) { - return CounterNotifier(); -}); - -/* SNIPPET START */ -class SomeConsumer extends ConsumerWidget { - const SomeConsumer({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - /* highlight-start */ - final counter = ref.watch(counterNotifierProvider); - /* highlight-end */ - return Column( - children: [ - Text("You've counted up until $counter, good job!"), - TextButton( - /* highlight-start */ - onPressed: ref.read(counterNotifierProvider.notifier).increment, - /* highlight-end */ - child: const Text('Count even more!'), - ) - ], - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/family_and_dispose.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/family_and_dispose.dart deleted file mode 100644 index 9a695614c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/family_and_dispose.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unnecessary_this - -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -part 'family_and_dispose.g.dart'; - -/* SNIPPET START */ -@riverpod -class BugsEncounteredNotifier extends _$BugsEncounteredNotifier { - @override - FutureOr build(String featureId) { - return 99; - } - - Future fix(int amount) async { - final old = await future; - final result = await ref.read(taskTrackerProvider).fix(id: this.featureId, fixed: amount); - state = AsyncData(max(old - result, 0)); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/index.tsx deleted file mode 100644 index 0780f2135..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./family_and_dispose.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/raw.dart deleted file mode 100644 index 8dfce9447..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -// ignore_for_file: unnecessary_this - -import 'dart:math'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -/* SNIPPET START */ -class BugsEncounteredNotifier extends AutoDisposeFamilyAsyncNotifier { - @override - FutureOr build(String featureId) { - return 99; - } - - Future fix(int amount) async { - final old = await future; - final result = await ref.read(taskTrackerProvider).fix(id: this.arg, fixed: amount); - state = AsyncData(max(old - result, 0)); - } -} - -final bugsEncounteredNotifierProvider = - AsyncNotifierProvider.family.autoDispose( - BugsEncounteredNotifier.new, -); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose_old.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose_old.dart deleted file mode 100644 index 28f93a65c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose_old.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: unnecessary_this - -import 'dart:math'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../utils.dart'; - -/* SNIPPET START */ -class BugsEncounteredNotifier extends StateNotifier> { - BugsEncounteredNotifier({ - required this.ref, - required this.featureId, - }) : super(const AsyncData(99)); - final String featureId; - final Ref ref; - - Future fix(int amount) async { - state = await AsyncValue.guard(() async { - final old = state.requireValue; - final result = await ref.read(taskTrackerProvider).fix(id: featureId, fixed: amount); - return max(old - result, 0); - }); - } -} - -final bugsEncounteredNotifierProvider = - StateNotifierProvider.family.autoDispose((ref, id) { - return BugsEncounteredNotifier(ref: ref, featureId: id); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/from_state_provider.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/from_state_provider.dart deleted file mode 100644 index 2c71d6144..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/from_state_provider.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'from_state_provider.g.dart'; - -/* SNIPPET START */ -@riverpod -class CounterNotifier extends _$CounterNotifier { - @override - int build() => 0; - - @override - set state(int newState) => super.state = newState; - int update(int Function(int state) cb) => state = cb(state); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/index.tsx deleted file mode 100644 index f59794999..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./from_state_provider.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/raw.dart deleted file mode 100644 index 97e4564f3..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -class CounterNotifier extends Notifier { - @override - int build() => 0; - - @override - set state(int newState) => super.state = newState; - int update(int Function(int state) cb) => state = cb(state); -} - -final counterNotifierProvider = NotifierProvider(CounterNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider_old.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider_old.dart deleted file mode 100644 index 246f44a0c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider_old.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ -final counterProvider = StateProvider((ref) { - return 0; -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/obtain_notifier_on_tests.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/obtain_notifier_on_tests.dart deleted file mode 100644 index 4a0d4e07c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/obtain_notifier_on_tests.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: unused_local_variable,omit_local_variable_types - -import 'package:flutter_test/flutter_test.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class MyNotifier extends AutoDisposeNotifier { - @override - int build() { - return 0; - } -} - -final myNotifierProvider = NotifierProvider.autoDispose(MyNotifier.new); - -/* SNIPPET START */ -void main(List args) { - test('my test', () { - final container = ProviderContainer(); - addTearDown(container.dispose); - - // Ottenendo un notifier - /* highlight-start */ - final AutoDisposeNotifier notifier = container.read(myNotifierProvider.notifier); - /* highlight-end */ - - // Ottenendo il suo stato esposto - /* highlight-start */ - final int state = container.read(myNotifierProvider); - /* highlight-end */ - - // TODO scrivi i tuoi test - }); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/index.tsx deleted file mode 100644 index 9b77f551a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./old_lifecycles.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/old_lifecycles.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/old_lifecycles.dart deleted file mode 100644 index 7da7d4adc..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/old_lifecycles.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -part 'old_lifecycles.g.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - // Basta leggere/scrivere il codice qui, in un posto - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - await ref.read(repositoryProvider).update(state + 1); - // `mounted` non è più necessario! - state++; // This might throw. - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/raw.dart deleted file mode 100644 index 691d71af9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/raw.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() { - // Just read/write the code here, in one place - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - await ref.read(repositoryProvider).update(state + 1); - // `mounted` is no more! - state++; // This might throw. - } -} - -final myNotifierProvider = NotifierProvider(MyNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/index.tsx deleted file mode 100644 index 9823b1564..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./old_lifecycles_final.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/old_lifecycles_final.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/old_lifecycles_final.dart deleted file mode 100644 index e343cdaa7..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/old_lifecycles_final.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -part 'old_lifecycles_final.g.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - // Legge/scrive il codice solamente qui, in un posto unico - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - final cancelToken = CancelToken(); - ref.onDispose(cancelToken.cancel); - await ref.read(repositoryProvider).update(state + 1, token: cancelToken); - // Quando `cancelToken.cancel` è invocato, una Exception personalizzata viene generata - state++; - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/raw.dart deleted file mode 100644 index 09aa16913..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/raw.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() { - // Legge/scrive il codice solamente qui, in un posto unico - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - final cancelToken = CancelToken(); - ref.onDispose(cancelToken.cancel); - await ref.read(repositoryProvider).update(state + 1, token: cancelToken); - state++; - } -} - -final myNotifierProvider = NotifierProvider(MyNotifier.new); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_old.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_old.dart deleted file mode 100644 index 8f6eaa485..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_old.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../utils.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -class MyNotifier extends StateNotifier { - MyNotifier(this.ref, this.period) : super(0) { - // 1 init logic - _timer = Timer.periodic(period, (t) => update()); // 2 side effect on init - } - final Duration period; - final Ref ref; - late final Timer _timer; - - Future update() async { - await ref.read(repositoryProvider).update(state + 1); // 3 mutation - if (mounted) state++; // 4 check for mounted props - } - - @override - void dispose() { - _timer.cancel(); // 5 custom dispose logic - super.dispose(); - } -} - -final myNotifierProvider = StateNotifierProvider((ref) { - // 6 provider definition - final period = ref.watch(durationProvider); // 7 reactive dependency logic - return MyNotifier(ref, period); // 8 pipe down `ref` -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider.mdx index 6f114320a..b32ad0964 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider.mdx @@ -3,8 +3,8 @@ title: FutureProvider version: 1 --- -import configProvider from "./future_provider/config_provider"; -import configConsumer from "./future_provider/config_consumer"; +import configProvider from "/docs/providers/future_provider/config_provider"; +import configConsumer from "/docs/providers/future_provider/config_consumer"; import { AutoSnippet} from "../../../../../src/components/CodeSnippet"; :::caution diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/codegen.dart deleted file mode 100644 index a96f35e72..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/codegen.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../config_provider/codegen.dart'; - -/* SNIPPET START */ - -Widget build(BuildContext context, WidgetRef ref) { - final config = ref.watch(fetchConfigurationProvider); - - return switch (config) { - AsyncError(:final error) => Text('Error: $error'), - AsyncData(:final value) => Text(value.host), - _ => const CircularProgressIndicator(), - }; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks.dart deleted file mode 100644 index 44d9b4df9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../config_provider/raw.dart'; - -/* SNIPPET START */ - -class MyConfiguration extends HookConsumerWidget { - const MyConfiguration({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final config = ref.watch(configProvider); - return Scaffold( - body: switch (config) { - AsyncError(:final error) => Center(child: Text('Error: $error')), - AsyncData(:final value) => Center(child: Text(value.host)), - _ => const Center(child: CircularProgressIndicator()), - }, - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks_codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks_codegen.dart deleted file mode 100644 index ade0628fd..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks_codegen.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../config_provider/codegen.dart'; - -/* SNIPPET START */ - -class MyConfiguration extends HookConsumerWidget { - const MyConfiguration({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final config = ref.watch(fetchConfigurationProvider); - return Scaffold( - body: switch (config) { - AsyncError(:final error) => Center(child: Text('Error: $error')), - AsyncData(:final value) => Center(child: Text(value.host)), - _ => const Center(child: CircularProgressIndicator()), - }, - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/index.tsx deleted file mode 100644 index 8e7b2a443..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import hooks from "!!raw-loader!./hooks.dart"; -import hooksCodegen from "!!raw-loader!./hooks_codegen.dart" - -export default { - raw, - hooks, - codegen, - hooksCodegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/raw.dart deleted file mode 100644 index 9d39f3bcd..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/raw.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../config_provider/raw.dart'; - -/* SNIPPET START */ - -Widget build(BuildContext context, WidgetRef ref) { - AsyncValue config = ref.watch(configProvider); - - return switch (config) { - AsyncData(:final value) => Text(value.host), - AsyncError(:final error) => Text('Error: $error'), - _ => const CircularProgressIndicator(), - }; -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/codegen.dart deleted file mode 100644 index 2aa87a29e..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/codegen.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'dart:convert'; - -import 'package:flutter/services.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; -part 'codegen.g.dart'; -class Configuration { - Configuration.fromJson(Map json); - final String host = ''; -} - -/* SNIPPET START */ - -@riverpod -Future fetchConfiguration(FetchConfigurationRef ref) async { - final content = json.decode( - await rootBundle.loadString('assets/configurations.json'), - ) as Map; - - return Configuration.fromJson(content); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/raw.dart deleted file mode 100644 index 62d7926ca..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/raw.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'dart:convert'; - -import 'package:flutter/services.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Configuration { - Configuration.fromJson(Map json); - - final String host = ''; -} - -/* SNIPPET START */ - -final configProvider = FutureProvider((ref) async { - final content = json.decode( - await rootBundle.loadString('assets/configurations.json'), - ) as Map; - - return Configuration.fromJson(content); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx index 4432f874f..750b46700 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx @@ -3,9 +3,9 @@ title: (Async)NotifierProvider --- import CodeBlock from "@theme/CodeBlock"; -import todos from "./notifier_provider/todos"; +import todos from "/docs/providers/notifier_provider/todos"; import todosConsumer from "!!raw-loader!/docs/providers/notifier_provider/todos/todos_consumer.dart"; -import remoteTodos from "./notifier_provider/remote_todos"; +import remoteTodos from "/docs/providers/notifier_provider/remote_todos"; import remoteTodosConsumer from "!!raw-loader!/docs/providers/notifier_provider/remote_todos/todos_consumer.dart"; import { trimSnippet, AutoSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart deleted file mode 100644 index e02195f87..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart +++ /dev/null @@ -1,82 +0,0 @@ -import 'dart:convert'; - -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -class Http { - Future get(String str) async => str; - Future delete(String str) async => str; - Future post(String str, Map body) async => str; - Future patch(String str, Map body) async => str; -} - -final http = Http(); - -/* SNIPPET START */ - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; - - factory Todo.fromJson(Map json) => _$TodoFromJson(json); -} - -// This will generates a AsyncNotifier and AsyncNotifierProvider. -// The AsyncNotifier class that will be passed to our AsyncNotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -// Finally, we are using asyncTodosProvider(AsyncNotifierProvider) to allow the UI to -// interact with our Todos class. -@riverpod -class AsyncTodos extends _$AsyncTodos { - Future> _fetchTodo() async { - final json = await http.get('api/todos'); - final todos = jsonDecode(json) as List>; - return todos.map(Todo.fromJson).toList(); - } - - @override - FutureOr> build() async { - // Load initial todo list from the remote repository - return _fetchTodo(); - } - - Future addTodo(Todo todo) async { - // Set the state to loading - state = const AsyncValue.loading(); - // Add the new todo and reload the todo list from the remote repository - state = await AsyncValue.guard(() async { - await http.post('api/todos', todo.toJson()); - return _fetchTodo(); - }); - } - - // Let's allow removing todos - Future removeTodo(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.delete('api/todos/$todoId'); - return _fetchTodo(); - }); - } - - // Let's mark a todo as completed - Future toggle(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.patch( - 'api/todos/$todoId', - {'completed': true}, - ); - return _fetchTodo(); - }); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart deleted file mode 100644 index f4455a338..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Http { - Future get(String str) async => str; - Future delete(String str) async => str; - Future post(String str, Map body) async => str; - Future patch(String str, Map body) async => str; -} - -final http = Http(); - -/* SNIPPET START */ - -// An immutable state is preferred. -// We could also use packages like Freezed to help with the implementation. -@immutable -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - factory Todo.fromJson(Map map) { - return Todo( - id: map['id'] as String, - description: map['description'] as String, - completed: map['completed'] as bool, - ); - } - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - Map toJson() => { - 'id': id, - 'description': description, - 'completed': completed, - }; -} - -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -class AsyncTodosNotifier extends AsyncNotifier> { - Future> _fetchTodo() async { - final json = await http.get('api/todos'); - final todos = jsonDecode(json) as List>; - return todos.map(Todo.fromJson).toList(); - } - - @override - Future> build() async { - // Load initial todo list from the remote repository - return _fetchTodo(); - } - - Future addTodo(Todo todo) async { - // Set the state to loading - state = const AsyncValue.loading(); - // Add the new todo and reload the todo list from the remote repository - state = await AsyncValue.guard(() async { - await http.post('api/todos', todo.toJson()); - return _fetchTodo(); - }); - } - - // Let's allow removing todos - Future removeTodo(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.delete('api/todos/$todoId'); - return _fetchTodo(); - }); - } - - // Let's mark a todo as completed - Future toggle(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.patch( - 'api/todos/$todoId', - {'completed': true}, - ); - return _fetchTodo(); - }); - } -} - -// Finally, we are using NotifierProvider to allow the UI to interact with -// our TodosNotifier class. -final asyncTodosProvider = - AsyncNotifierProvider>(() { - return AsyncTodosNotifier(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart deleted file mode 100644 index 5d00d05d9..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'codegen.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // rebuild the widget when the todo list changes - final asyncTodos = ref.watch(asyncTodosProvider); - - // Let's render the todos in a scrollable list view - return switch (asyncTodos) { - AsyncData(:final value) => ListView( - children: [ - for (final todo in value) - CheckboxListTile( - value: todo.completed, - // When tapping on the todo, change its completed status - onChanged: (value) { - ref.read(asyncTodosProvider.notifier).toggle(todo.id); - }, - title: Text(todo.description), - ), - ], - ), - AsyncError(:final error) => Text('Error: $error'), - _ => const Center(child: CircularProgressIndicator()), - }; - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart deleted file mode 100644 index 866ed37bb..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart +++ /dev/null @@ -1,68 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; -} - -// This will generates a Notifier and NotifierProvider. -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -// Finally, we are using todosProvider(NotifierProvider) to allow the UI to -// interact with our Todos class. -@riverpod -class Todos extends _$Todos { - @override - List build() { - return []; - } - - // Let's allow the UI to add todos. - void addTodo(Todo todo) { - // Since our state is immutable, we are not allowed to do `state.add(todo)`. - // Instead, we should create a new list of todos which contains the previous - // items and the new one. - // Using Dart's spread operator here is helpful! - state = [...state, todo]; - // No need to call "notifyListeners" or anything similar. Calling "state =" - // will automatically rebuild the UI when necessary. - } - - // Let's allow removing todos - void removeTodo(String todoId) { - // Again, our state is immutable. So we're making a new list instead of - // changing the existing list. - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // Let's mark a todo as completed - void toggle(String todoId) { - state = [ - for (final todo in state) - // we're marking only the matching todo as completed - if (todo.id == todoId) - // Once more, since our state is immutable, we need to make a copy - // of the todo. We're using our `copyWith` method implemented before - // to help with that. - todo.copyWith(completed: !todo.completed) - else - // other todos are not modified - todo, - ]; - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart deleted file mode 100644 index ec3e50308..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart +++ /dev/null @@ -1,85 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// An immutable state is preferred. -// We could also use packages like Freezed to help with the implementation. -@immutable -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - // Since Todo is immutable, we implement a method that allows cloning the - // Todo with slightly different content. - Todo copyWith({String? id, String? description, bool? completed}) { - return Todo( - id: id ?? this.id, - description: description ?? this.description, - completed: completed ?? this.completed, - ); - } -} - -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -class TodosNotifier extends Notifier> { - // We initialize the list of todos to an empty list - @override - List build() { - return []; - } - - // Let's allow the UI to add todos. - void addTodo(Todo todo) { - // Since our state is immutable, we are not allowed to do `state.add(todo)`. - // Instead, we should create a new list of todos which contains the previous - // items and the new one. - // Using Dart's spread operator here is helpful! - state = [...state, todo]; - // No need to call "notifyListeners" or anything similar. Calling "state =" - // will automatically rebuild the UI when necessary. - } - - // Let's allow removing todos - void removeTodo(String todoId) { - // Again, our state is immutable. So we're making a new list instead of - // changing the existing list. - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // Let's mark a todo as completed - void toggle(String todoId) { - state = [ - for (final todo in state) - // we're marking only the matching todo as completed - if (todo.id == todoId) - // Once more, since our state is immutable, we need to make a copy - // of the todo. We're using our `copyWith` method implemented before - // to help with that. - todo.copyWith(completed: !todo.completed) - else - // other todos are not modified - todo, - ]; - } -} - -// Finally, we are using NotifierProvider to allow the UI to interact with -// our TodosNotifier class. -final todosProvider = NotifierProvider>(() { - return TodosNotifier(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart deleted file mode 100644 index 192cb9f66..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart +++ /dev/null @@ -1,32 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'codegen.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // rebuild the widget when the todo list changes - List todos = ref.watch(todosProvider); - - // Let's render the todos in a scrollable list view - return ListView( - children: [ - for (final todo in todos) - CheckboxListTile( - value: todo.completed, - // When tapping on the todo, change its completed status - onChanged: (value) => - ref.read(todosProvider.notifier).toggle(todo.id), - title: Text(todo.description), - ), - ], - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider.mdx index 136c8edbc..143ef2d6d 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider.mdx @@ -3,11 +3,11 @@ title: Provider --- import CodeBlock from "@theme/CodeBlock"; -import todo from "./provider/todo"; -import completedTodos from "./provider/completed_todos"; +import todo from "/docs/providers/provider/todo"; +import completedTodos from "/docs/providers/provider/completed_todos"; import todosConsumer from "!!raw-loader!/docs/providers/provider/todos_consumer.dart"; -import unoptimizedPreviousButton from "./provider/unoptimized_previous_button"; -import optimizedPreviousButton from "./provider/optimized_previous_button"; +import unoptimizedPreviousButton from "/docs/providers/provider/unoptimized_previous_button"; +import optimizedPreviousButton from "/docs/providers/provider/optimized_previous_button"; import { trimSnippet, AutoSnippet } from "../../../../../src/components/CodeSnippet"; :::caution diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/completed_todos.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/completed_todos.dart deleted file mode 100644 index 1a29d96f5..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/completed_todos.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../todo/todo.dart'; - -part 'completed_todos.g.dart'; - -/* SNIPPET START */ - -@riverpod -List completedTodos(CompletedTodosRef ref) { - final todos = ref.watch(todosProvider); - - // we return only the completed todos - return todos.where((todo) => todo.isCompleted).toList(); -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/index.tsx deleted file mode 100644 index 11451aa1c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./completed_todos.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/raw.dart deleted file mode 100644 index e24c48bd5..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../todo/raw.dart'; - -/* SNIPPET START */ - -final completedTodosProvider = Provider>((ref) { - // We obtain the list of all todos from the todosProvider - final todos = ref.watch(todosProvider); - - // we return only the completed todos - return todos.where((todo) => todo.isCompleted).toList(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/index.tsx deleted file mode 100644 index fb83c92f1..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./optimized_previous_button.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/optimized_previous_button.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/optimized_previous_button.dart deleted file mode 100644 index 7d3b8a332..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/optimized_previous_button.dart +++ /dev/null @@ -1,50 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'optimized_previous_button.g.dart'; - -/* SNIPPET START */ - -@riverpod -class PageIndex extends _$PageIndex { - @override - int build() { - return 0; - } - - void goToPreviousPage() { - state = state - 1; - } -} - -// A provider which computes whether the user is allowed to go to the previous page -@riverpod -/* highlight-start */ -bool canGoToPreviousPage(CanGoToPreviousPageRef ref) { -/* highlight-end */ - return ref.watch(pageIndexProvider) != 0; -} - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // We are now watching our new Provider - // Our widget is no longer calculating whether we can go to the previous page. -/* highlight-start */ - final canGoToPreviousPage = ref.watch(canGoToPreviousPageProvider); -/* highlight-end */ - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).goToPreviousPage(); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/raw.dart deleted file mode 100644 index 30b1cc673..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/raw.dart +++ /dev/null @@ -1,36 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final pageIndexProvider = StateProvider((ref) => 0); - -// A provider which computes whether the user is allowed to go to the previous page -/* highlight-start */ -final canGoToPreviousPageProvider = Provider((ref) { -/* highlight-end */ - return ref.watch(pageIndexProvider) != 0; -}); - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // We are now watching our new Provider - // Our widget is no longer calculating whether we can go to the previous page. -/* highlight-start */ - final canGoToPreviousPage = ref.watch(canGoToPreviousPageProvider); -/* highlight-end */ - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).update((state) => state - 1); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/index.tsx deleted file mode 100644 index 91d9cc4aa..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./todo.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/raw.dart deleted file mode 100644 index 11e62bc3a..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -class Todo { - Todo(this.description, this.isCompleted); - final bool isCompleted; - final String description; -} - -class TodosNotifier extends Notifier> { - @override - List build() { - return []; - } - - void addTodo(Todo todo) { - state = [...state, todo]; - } - // TODO add other methods, such as "removeTodo", ... -} - -final todosProvider = NotifierProvider>(() { - return TodosNotifier(); -}); diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/todo.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/todo.dart deleted file mode 100644 index 7089bc962..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/todo/todo.dart +++ /dev/null @@ -1,25 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'todo.g.dart'; - -/* SNIPPET START */ - -class Todo { - Todo(this.description, this.isCompleted); - final bool isCompleted; - final String description; -} - -@riverpod -class Todos extends _$Todos { - @override - List build() { - return []; - } - - void addTodo(Todo todo) { - state = [...state, todo]; - } - // TODO add other methods, such as "removeTodo", ... -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/index.tsx deleted file mode 100644 index d345d4f5d..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./unoptimized_previous_button.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/raw.dart deleted file mode 100644 index 828d382d5..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/raw.dart +++ /dev/null @@ -1,26 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final pageIndexProvider = StateProvider((ref) => 0); - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // if not on first page, the previous button is active - final canGoToPreviousPage = ref.watch(pageIndexProvider) != 0; - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).update((state) => state - 1); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/unoptimized_previous_button.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/unoptimized_previous_button.dart deleted file mode 100644 index f77de56c3..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/unoptimized_previous_button.dart +++ /dev/null @@ -1,39 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'unoptimized_previous_button.g.dart'; - -/* SNIPPET START */ - -@riverpod -class PageIndex extends _$PageIndex { - @override - int build() { - return 0; - } - - void goToPreviousPage() { - state = state - 1; - } -} - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // if not on first page, the previous button is active - final canGoToPreviousPage = ref.watch(pageIndexProvider) != 0; - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).goToPreviousPage(); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx index bd40cfc5f..32e6c7f97 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx @@ -4,7 +4,7 @@ title: StreamProvider import CodeBlock from "@theme/CodeBlock"; import { trimSnippet,AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import streamProvider from "./stream_provider/live_stream_chat_provider"; +import streamProvider from "/docs/providers/stream_provider/live_stream_chat_provider"; import streamConsumer from "!!raw-loader!/docs/providers/stream_provider/live_stream_chat_consumer.dart"; :::caution diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/codegen.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/codegen.dart deleted file mode 100644 index e2e34878c..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'dart:convert'; -import 'dart:io'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -Stream> chat(ChatRef ref) async* { - // Connect to an API using sockets, and decode the output - final socket = await Socket.connect('my-api', 4242); - ref.onDispose(socket.close); - - var allMessages = const []; - await for (final message in socket.map(utf8.decode)) { - // A new message has been received. Let's add it to the list of all messages. - allMessages = [...allMessages, message]; - yield allMessages; - } -} diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/index.tsx b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/raw.dart b/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/raw.dart deleted file mode 100644 index beb2bcd05..000000000 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/raw.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final chatProvider = StreamProvider>((ref) async* { - // Connect to an API using sockets, and decode the output - final socket = await Socket.connect('my-api', 4242); - ref.onDispose(socket.close); - - var allMessages = const []; - await for (final message in socket.map(utf8.decode)) { - // A new message has been received. Let's add it to the list of all messages. - allMessages = [...allMessages, message]; - yield allMessages; - } -}); diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml index 6a5911185..864fd5f97 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/codegen.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: riverpod: ^2.1.3 diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml index 7c8025595..d0a5ecbd2 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/dart_pubspec/raw.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" dependencies: riverpod: ^2.1.3 \ No newline at end of file diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml index a6fab5137..098fd4088 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/codegen.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml index 66cecf549..cb19518e6 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml index ff505c223..e7f32ee6a 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/hooks_codegen.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml index 4a4472dcd..a00be715d 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/getting_started/pubspec/raw.yaml @@ -1,6 +1,6 @@ name: my_app_name environment: - sdk: ">=2.17.0 <3.0.0" + sdk: ">=2.17.0 <4.0.0" flutter: ">=3.0.0" dependencies: diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select.mdx index b1b5a4b88..0c80e5d2f 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select.mdx @@ -3,7 +3,7 @@ title: 성능 최적화하기 --- import { AutoSnippet } from "/src/components/CodeSnippet"; -import select from "./select/select"; +import select from "/docs/advanced/select/select"; import selectAsync from "/docs/advanced/select/select_async"; 지금까지 살펴본 내용을 통해 이미 모든 기능을 갖춘 애플리케이션을 구축할 수 있습니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/codegen.dart deleted file mode 100644 index f875f67e2..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/codegen.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_multiple_declarations_per_line, omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -class User { - late String firstName, lastName; -} - -@riverpod -User example(ExampleRef ref) => User() - ..firstName = 'John' - ..lastName = 'Doe'; - -class ConsumerExample extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // 이렇게 작성하는 대신: - // String name = ref.watch(provider).firstName!; - // 이렇게 작성할수 있습니다: - String name = ref.watch(exampleProvider.select((it) => it.firstName)); - // 이렇게 하면 위젯이 "firstName"의 변경 사항만 수신합니다. - - return Text('Hello $name'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/raw.dart deleted file mode 100644 index 46524af88..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/advanced/select/select/raw.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_multiple_declarations_per_line, omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -class User { - late String firstName, lastName; -} - -final provider = Provider( - (ref) => User() - ..firstName = 'John' - ..lastName = 'Doe', -); - -class ConsumerExample extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // Instead of writing: - // String name = ref.watch(provider).firstName!; - // We can write: - String name = ref.watch(provider.select((it) => it.firstName)); - // This will cause the widget to only listen to changes on "firstName". - - return Text('Hello $name'); - } -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx index 27fcea046..1e1d18569 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel.mdx @@ -6,10 +6,10 @@ import { Link } from "../../../../../src/components/Link"; import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; import homeScreen from "!raw-loader!./cancel/home_screen.dart"; import extension from "!raw-loader!./cancel/extension.dart"; -import detailScreen from "./cancel/detail_screen"; -import detailScreenCancel from "./cancel/detail_screen_cancel"; -import detailScreenDebounce from "./cancel/detail_screen_debounce"; -import providerWithExtension from "./cancel/provider_with_extension"; +import detailScreen from "/docs/case_studies/cancel/detail_screen"; +import detailScreenCancel from "/docs/case_studies/cancel/detail_screen_cancel"; +import detailScreenDebounce from "/docs/case_studies/cancel/detail_screen_debounce"; +import providerWithExtension from "/docs/case_studies/cancel/provider_with_extension"; 애플리케이션이 복잡해짐에 따라 동시에 여러 개의 네트워크 요청이 발생하는 것이 일반적입니다. 예를 들어, 사용자가 검색창에 입력할 때마다 새로운 요청이 트리거될 수 있습니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/codegen.dart deleted file mode 100644 index e3bf193a2..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/codegen.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -/* SNIPPET START */ -@freezed -class Activity with _$Activity { - factory Activity({ - required String activity, - required String type, - required int participants, - required double price, - }) = _Activity; - - factory Activity.fromJson(Map json) => - _$ActivityFromJson(json); -} - -@riverpod -Future activity(ActivityRef ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} - -class DetailPageView extends ConsumerWidget { - const DetailPageView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar( - title: const Text('Detail page'), - ), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const Center(child: CircularProgressIndicator()), - }, - ], - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/raw.dart deleted file mode 100644 index b3ad1faaf..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen/raw.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -/* SNIPPET START */ -class Activity { - Activity({ - required this.activity, - required this.type, - required this.participants, - required this.price, - }); - - factory Activity.fromJson(Map json) { - return Activity( - activity: json['activity']! as String, - type: json['type']! as String, - participants: json['participants']! as int, - price: json['price']! as double, - ); - } - - final String activity; - final String type; - final int participants; - final double price; -} - -final activityProvider = FutureProvider.autoDispose((ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); - -class DetailPageView extends ConsumerWidget { - const DetailPageView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar( - title: const Text('Detail page'), - ), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const Center(child: CircularProgressIndicator()), - }, - ], - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/codegen.dart deleted file mode 100644 index 3d5dff27d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/codegen.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../detail_screen/codegen.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - // package:http를 사용하여 HTTP 클라이언트를 생성합니다. - final client = http.Client(); - // dispose 시 클라이언트를 닫습니다. - // 그러면 클라이언트에 있을 수 있는 모든 보류 중인 요청이 취소됩니다. - ref.onDispose(client.close); - - // 이제 "get" 함수 대신 클라이언트를 사용하여 요청을 수행합니다. - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - // 나머지 코드는 이전과 동일합니다. - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/raw.dart deleted file mode 100644 index 2bf5a4d5e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_cancel/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import '../detail_screen/codegen.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - // We create an HTTP client using package:http - final client = http.Client(); - // On dispose, we close the client. - // This will cancel any pending request that the client might have. - ref.onDispose(client.close); - - // We now use the client to make the request instead of the "get" function. - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - // The rest of the code is the same as before - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/codegen.dart deleted file mode 100644 index 1dacaaeca..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/codegen.dart +++ /dev/null @@ -1,39 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../detail_screen/codegen.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - // provider가 현재 폐기(disposed)되었는지 여부를 캡처합니다. - var didDispose = false; - ref.onDispose(() => didDispose = true); - - // 사용자가 새로 고침(refreshing)을 중단할 때까지 기다리기 위해 - // 요청을 500밀리초 지연합니다. - await Future.delayed(const Duration(milliseconds: 500)); - - // 지연 중에 provider가 폐기(disposed)되었다면 사용자가 다시 새로고침했다는 의미입니다. - // 예외를 던져 요청을 취소합니다. - // Riverpod에 의해 잡히므로 여기서 예외를 사용하는 것이 안전합니다. - if (didDispose) { - throw Exception('Cancelled'); - } - - // 다음 코드는 이전 스니펫에서 변경되지 않았습니다. - final client = http.Client(); - ref.onDispose(client.close); - - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/raw.dart deleted file mode 100644 index 624842ecf..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/detail_screen_debounce/raw.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import '../detail_screen/codegen.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - // We capture whether the provider is currently disposed or not. - var didDispose = false; - ref.onDispose(() => didDispose = true); - - // We delay the request by 500ms, to wait for the user to stop refreshing. - await Future.delayed(const Duration(milliseconds: 500)); - - // If the provider was disposed during the delay, it means that the user - // refreshed again. We throw an exception to cancel the request. - // It is safe to use an exception here, as it will be caught by Riverpod. - if (didDispose) { - throw Exception('Cancelled'); - } - - // The following code is unchanged from the previous snippet - final client = http.Client(); - ref.onDispose(client.close); - - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/codegen.dart deleted file mode 100644 index 2868bf735..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/codegen.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'dart:convert'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../detail_screen/codegen.dart'; -import '../extension.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - // 앞서 만든 확장자를 사용하여 HTTP 클라이언트를 가져옵니다. - final client = await ref.getDebouncedHttpClient(); - - // 이제 "get" 함수 대신 클라이언트를 사용하여 요청을 수행합니다. - // 사용자가 페이지를 떠나면 요청은 자연스럽게 디바운스(debounced)되고 취소(cancelled)됩니다. - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/raw.dart deleted file mode 100644 index 36ef098f7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/cancel/provider_with_extension/raw.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../detail_screen/codegen.dart'; -import '../extension.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - // We obtain an HTTP client using the extension we created earlier. - final client = await ref.getDebouncedHttpClient(); - - // We now use the client to make the request instead of the "get" function. - // Our request will naturally be debounced and be cancelled if the user - // leaves the page. - final response = await client.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx index 8add0ebe9..403839bfa 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh.mdx @@ -4,13 +4,13 @@ title: 당겨서 새로고침(Pull to refresh) import { Link } from "../../../../../src/components/Link"; import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import activity from "./pull_to_refresh/activity"; -import fetchActivity from "./pull_to_refresh/fetch_activity"; -import displayActivity from "!!raw-loader!./pull_to_refresh/display_activity.dart"; -import displayActivity2 from "!!raw-loader!./pull_to_refresh/display_activity2.dart"; -import displayActivity3 from "!!raw-loader!./pull_to_refresh/display_activity3.dart"; -import displayActivity4 from "!!raw-loader!./pull_to_refresh/display_activity4.dart"; -import fullApp from "./pull_to_refresh/full_app"; +import activity from "/docs/case_studies/pull_to_refresh/activity"; +import fetchActivity from "/docs/case_studies/pull_to_refresh/fetch_activity"; +import displayActivity from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity.dart"; +import displayActivity2 from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity2.dart"; +import displayActivity3 from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity3.dart"; +import displayActivity4 from "!!raw-loader!/docs/case_studies/pull_to_refresh/display_activity4.dart"; +import fullApp from "/docs/case_studies/pull_to_refresh/full_app"; Riverpod은 선언적 성격 덕분에 당겨서 새로고침(pull-to-refresh)를 기본적으로 지원합니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/codegen.dart deleted file mode 100644 index ac3e1b17d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/codegen.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'codegen.g.dart'; -part 'codegen.freezed.dart'; - -/* SNIPPET START */ -@freezed -class Activity with _$Activity { - factory Activity({ - required String activity, - required String type, - required int participants, - required double price, - }) = _Activity; - - factory Activity.fromJson(Map json) => - _$ActivityFromJson(json); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/raw.dart deleted file mode 100644 index 42365b7bb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/activity/raw.dart +++ /dev/null @@ -1,24 +0,0 @@ -/* SNIPPET START */ -class Activity { - Activity({ - required this.activity, - required this.type, - required this.participants, - required this.price, - }); - - factory Activity.fromJson(Map json) { - return Activity( - activity: json['activity']! as String, - type: json['type']! as String, - participants: json['participants']! as int, - price: json['price']! as double, - ); - } - - final String activity; - final String type; - final int participants; - final double price; -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity.dart deleted file mode 100644 index 8313781ca..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: Center( - // 액티비티가 있으면 표시하고, 그렇지 않으면 대기합니다. - child: Text(activity.valueOrNull?.activity ?? ''), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity2.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity2.dart deleted file mode 100644 index 7394ea664..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity2.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: avoid_print, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - /* highlight-start */ - body: RefreshIndicator( - onRefresh: () async => print('refresh'), - child: ListView( - children: [ - /* highlight-end */ - Text(activity.valueOrNull?.activity ?? ''), - ], - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity3.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity3.dart deleted file mode 100644 index 17e661a0c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity3.dart +++ /dev/null @@ -1,31 +0,0 @@ -// ignore_for_file: avoid_print, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - // "activityProvider.future"를 새로 고침으로, 해당 결과를 반환하면, - // 새 액티비티를 가져올 때까지 - // 새로 고침 표시기(refresh indicator)가 계속 표시됩니다. - /* highlight-start */ - onRefresh: () => ref.refresh(activityProvider.future), - /* highlight-end */ - child: ListView( - children: [ - Text(activity.valueOrNull?.activity ?? ''), - ], - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity4.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity4.dart deleted file mode 100644 index 54564c4c0..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/display_activity4.dart +++ /dev/null @@ -1,35 +0,0 @@ -// ignore_for_file: avoid_print, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'activity/codegen.dart'; -import 'fetch_activity/codegen.dart'; - -/* SNIPPET START */ -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - // 일부 데이터를 사용할 수 있는 경우 해당 데이터를 표시합니다. - // 새로 고침 중에도 데이터를 계속 사용할 수 있습니다. - AsyncValue(:final valueOrNull?) => Text(valueOrNull.activity), - // 오류를 사용할 수 있으므로 렌더링합니다. - AsyncValue(:final error?) => Text('Error: $error'), - // 데이터/오류가 없으므로 로딩 상태입니다. - _ => const CircularProgressIndicator(), - }, - ], - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/codegen.dart deleted file mode 100644 index 0cec67cba..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/codegen.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../activity/codegen.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future activity(ActivityRef ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/raw.dart deleted file mode 100644 index 1cec3b128..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/fetch_activity/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../activity/raw.dart'; - -/* SNIPPET START */ -final activityProvider = FutureProvider.autoDispose((ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/codegen.dart deleted file mode 100644 index b7d53c744..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/codegen.dart +++ /dev/null @@ -1,69 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unreachable_from_main - -/* SNIPPET START */ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; -part 'codegen.freezed.dart'; - -void main() => runApp(ProviderScope(child: MyApp())); - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp(home: ActivityView()); - } -} - -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => - Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const CircularProgressIndicator(), - }, - ], - ), - ), - ); - } -} - -@riverpod -Future activity(ActivityRef ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(Map.from(json)); -} - -@freezed -class Activity with _$Activity { - factory Activity({ - required String activity, - required String type, - required int participants, - required double price, - }) = _Activity; - - factory Activity.fromJson(Map json) => - _$ActivityFromJson(json); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/raw.dart deleted file mode 100644 index c4186fb31..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/case_studies/pull_to_refresh/full_app/raw.dart +++ /dev/null @@ -1,73 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unreachable_from_main - -/* SNIPPET START */ -import 'dart:convert'; - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -void main() => runApp(ProviderScope(child: MyApp())); - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp(home: ActivityView()); - } -} - -class ActivityView extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final activity = ref.watch(activityProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Pull to refresh')), - body: RefreshIndicator( - onRefresh: () => ref.refresh(activityProvider.future), - child: ListView( - children: [ - switch (activity) { - AsyncValue(:final valueOrNull?) => - Text(valueOrNull.activity), - AsyncValue(:final error?) => Text('Error: $error'), - _ => const CircularProgressIndicator(), - }, - ], - ), - ), - ); - } -} - -final activityProvider = FutureProvider.autoDispose((ref) async { - final response = await http.get( - Uri.https('www.boredapi.com', '/api/activity'), - ); - - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); - -class Activity { - Activity({ - required this.activity, - required this.type, - required this.participants, - required this.price, - }); - - factory Activity.fromJson(Map json) { - return Activity( - activity: json['activity']! as String, - type: json['type']! as String, - participants: json['participants']! as int, - price: json['price']! as double, - ); - } - - final String activity; - final String type; - final int participants; - final double price; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx index 6d3046125..030bd75a8 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_code_generation.mdx @@ -6,28 +6,28 @@ version: 1 import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import fetchUser from "!!raw-loader!./about_codegen/main.dart"; -import rawFetchUser from "!!raw-loader!./about_codegen/raw.dart"; +import fetchUser from "!!raw-loader!/docs/concepts/about_codegen/main.dart"; +import rawFetchUser from "!!raw-loader!/docs/concepts/about_codegen/raw.dart"; import { Link } from "../../../../../src/components/Link"; import { trimSnippet, CodeSnippet } from "../../../../../src/components/CodeSnippet"; -import syncFn from "!!raw-loader!./about_codegen/provider_type/sync_fn.dart"; -import syncClass from "!!raw-loader!./about_codegen/provider_type/sync_class.dart"; -import asyncFnFuture from "!!raw-loader!./about_codegen/provider_type/async_fn_future.dart"; -import asyncClassFuture from "!!raw-loader!./about_codegen/provider_type/async_class_future.dart"; -import asyncFnStream from "!!raw-loader!./about_codegen/provider_type/async_fn_stream.dart"; -import asyncClassStream from "!!raw-loader!./about_codegen/provider_type/async_class_stream.dart"; -import familyFn from "!!raw-loader!./about_codegen/provider_type/family_fn.dart"; -import familyClass from "!!raw-loader!./about_codegen/provider_type/family_class.dart"; -import provider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/provider.dart"; -import notifierProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/notifier_provider.dart"; -import futureProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/future_provider.dart"; -import asyncNotifierProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/async_notifier_provider.dart"; -import streamProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/stream_provider.dart"; -import streamNotifierProvider from "!!raw-loader!./about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart"; -import autoDisposeCodeGen from "!!raw-loader!./about_codegen/provider_type/auto_dispose.dart"; -import autoDisposeNonCodeGen from "!!raw-loader!./about_codegen/provider_type/non_code_gen/auto_dispose.dart"; -import familyCodeGen from "!!raw-loader!./about_codegen/provider_type/family.dart"; -import familyNonCodeGen from "!!raw-loader!./about_codegen/provider_type/non_code_gen/family.dart"; +import syncFn from "!!raw-loader!/docs/concepts/about_codegen/provider_type/sync_fn.dart"; +import syncClass from "!!raw-loader!/docs/concepts/about_codegen/provider_type/sync_class.dart"; +import asyncFnFuture from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_fn_future.dart"; +import asyncClassFuture from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_class_future.dart"; +import asyncFnStream from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_fn_stream.dart"; +import asyncClassStream from "!!raw-loader!/docs/concepts/about_codegen/provider_type/async_class_stream.dart"; +import familyFn from "!!raw-loader!/docs/concepts/about_codegen/provider_type/family_fn.dart"; +import familyClass from "!!raw-loader!/docs/concepts/about_codegen/provider_type/family_class.dart"; +import provider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/provider.dart"; +import notifierProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart"; +import futureProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart"; +import asyncNotifierProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart"; +import streamProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart"; +import streamNotifierProvider from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart"; +import autoDisposeCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/auto_dispose.dart"; +import autoDisposeNonCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart"; +import familyCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/family.dart"; +import familyNonCodeGen from "!!raw-loader!/docs/concepts/about_codegen/provider_type/non_code_gen/family.dart"; const TRANSPARENT_STYLE = { backgroundColor: "transparent" }; const RED_STYLE = { color: "indianred", fontWeight: "700" }; const BLUE_STYLE = { color: "rgb(103, 134, 196)", fontWeight: "700" }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/main.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/main.dart deleted file mode 100644 index 1ccb42807..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/main.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -class User { - User.fromJson(Object obj); -} - -class Http { - Future get(String str) async => str; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -Future fetchUser(FetchUserRef ref, {required int userId}) async { - final json = await http.get('api/user/$userId'); - return User.fromJson(json); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_future.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_future.dart deleted file mode 100644 index 1988ec140..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_future.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_class_future.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - Future build() async { - return Future.value('foo'); - } - - // 상태(State) 변경(Mutation)을 위한 메서드 추가 -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_stream.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_stream.dart deleted file mode 100644 index fdde7f0ef..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_class_stream.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_class_stream.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - Stream build() async* { - yield 'foo'; - } - - // 상태(State) 변경(Mutation)을 위한 메서드 추가 -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_future.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_future.dart deleted file mode 100644 index 95fdd909c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_future.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_fn_future.g.dart'; - -/* SNIPPET START */ -@riverpod -Future example(ExampleRef ref) async { - return Future.value('foo'); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_stream.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_stream.dart deleted file mode 100644 index 74da790ad..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/async_fn_stream.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_fn_stream.g.dart'; - -/* SNIPPET START */ -@riverpod -Stream example(ExampleRef ref) async* { - yield 'foo'; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/auto_dispose.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/auto_dispose.dart deleted file mode 100644 index 587576695..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/auto_dispose.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'auto_dispose.g.dart'; - -/* SNIPPET START */ -// 자동폐기(AutoDispose) provider (keepAlive는 기본적으로 false) -@riverpod -String example1(Example1Ref ref) => 'foo'; - -// 비자동폐기(Non autoDispose) provider -@Riverpod(keepAlive: true) -String example2(Example2Ref ref) => 'foo'; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family.dart deleted file mode 100644 index e1ee685fb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family.g.dart'; - -/* SNIPPET START */ -@riverpod -String example(ExampleRef ref, int param) => 'Hello $param'; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_class.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_class.dart deleted file mode 100644 index f071d44f6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_class.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family_class.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - String build( - int param1, { - String param2 = 'foo', - }) { - return 'Hello $param1 & param2'; - } - - // 상태(State) 변경(Mutation)을 위한 메서드 추가 -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_fn.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_fn.dart deleted file mode 100644 index 863df6f40..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/family_fn.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family_fn.g.dart'; - -/* SNIPPET START */ -@riverpod -String example( - ExampleRef ref, - int param1, { - String param2 = 'foo', -}) { - return 'Hello $param1 & param2'; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart deleted file mode 100644 index 05afdc3ef..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/async_notifier_provider.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = AsyncNotifierProvider.autoDispose( - ExampleNotifier.new, -); - -class ExampleNotifier extends AutoDisposeAsyncNotifier { - @override - Future build() async { - return Future.value('foo'); - } - - // 상태(State) 변경(Mutation)을 위한 메서드 추가 -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart deleted file mode 100644 index 6bfb8babd..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/auto_dispose.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -// 자동폐기(autodispose) 프로바이더 -final example1Provider = Provider.autoDispose((ref) { - return 'foo'; -}); - -// 비동기 자동폐기(autodispose) 프로바이더 -final example2Provider = Provider((ref) { - return 'foo'; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/family.dart deleted file mode 100644 index a9e59d48d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/family.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = Provider.family((ref, param) { - return 'Hello $param'; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart deleted file mode 100644 index 6306a76fb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/future_provider.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = - FutureProvider.autoDispose((ref) async { - return Future.value('foo'); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart deleted file mode 100644 index 852beb863..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/notifier_provider.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = NotifierProvider.autoDispose( - ExampleNotifier.new, -); - -class ExampleNotifier extends AutoDisposeNotifier { - @override - String build() { - return 'foo'; - } - - // 상태(State) 변경(Mutation)을 위한 메서드 추가 -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/provider.dart deleted file mode 100644 index 1f541352a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/provider.dart +++ /dev/null @@ -1,8 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = Provider.autoDispose( - (ref) { - return 'foo'; - }, -); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart deleted file mode 100644 index 2ba322eb1..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_notifier_provider.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = StreamNotifierProvider.autoDispose(() { - return ExampleNotifier(); -}); - -class ExampleNotifier extends AutoDisposeStreamNotifier { - @override - Stream build() async* { - yield 'foo'; - } - - // 상태(State) 변경(Mutation)을 위한 메서드 추가 -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart deleted file mode 100644 index 60d227f8f..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/non_code_gen/stream_provider.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final exampleProvider = StreamProvider.autoDispose((ref) async* { - yield 'foo'; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_class.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_class.dart deleted file mode 100644 index dbe0773f9..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_class.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'sync_class.g.dart'; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - String build() { - return 'foo'; - } - - // 상태(State) 변경(Mutation)을 위한 메서드 추가 -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_fn.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_fn.dart deleted file mode 100644 index 0d4922734..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/sync_fn.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'sync_fn.g.dart'; - -/* SNIPPET START */ -@riverpod -String example(ExampleRef ref) { - return 'foo'; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/raw.dart deleted file mode 100644 index 4630c27ff..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types, avoid_unused_constructor_parameters - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class User { - User.fromJson(Object obj); -} - -class Http { - Future get(String str) async => str; -} - -final http = Http(); - -/* SNIPPET START */ -final fetchUserProvider = FutureProvider.autoDispose.family((ref, userId) async { - final json = await http.get('api/user/$userId'); - return User.fromJson(json); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx index 5dcf7354d..008b3bf9d 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks.mdx @@ -4,9 +4,9 @@ title: 훅(hooks)에 대한 정보 import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; -import hookAndConsumer from "!!raw-loader!./about_hooks/hook_and_consumer.dart"; -import hookConsumer from "!!raw-loader!./about_hooks/hook_consumer.dart"; -import hookConsumerWidget from "!!raw-loader!./about_hooks/hook_consumer_widget.dart"; +import hookAndConsumer from "!!raw-loader!/docs/concepts/about_hooks/hook_and_consumer.dart"; +import hookConsumer from "!!raw-loader!/docs/concepts/about_hooks/hook_consumer.dart"; +import hookConsumerWidget from "!!raw-loader!/docs/concepts/about_hooks/hook_consumer_widget.dart"; import { CodeSnippet } from "../../../../../src/components/CodeSnippet"; import { Link } from "../../../../../src/components/Link"; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_and_consumer.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_and_consumer.dart deleted file mode 100644 index b8d4be89e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_and_consumer.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../providers/creating_a_provider/codegen.dart'; - -class MyValue {} - -/* SNIPPET START */ - -class Example extends StatelessWidget { - @override - Widget build(BuildContext context) { - // 두 패키지 모두에서 제공하는 빌더를 사용할 수 있습니다. - return Consumer( - builder: (context, ref, child) { - return HookBuilder(builder: (context) { - final counter = useState(0); - final value = ref.watch(myProvider); - - return Text('Hello $counter $value'); - }); - }, - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer.dart deleted file mode 100644 index 5d23c0d0a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer.dart +++ /dev/null @@ -1,26 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../providers/creating_a_provider/codegen.dart'; - -class MyValue {} - -/* SNIPPET START */ - -class Example extends StatelessWidget { - @override - Widget build(BuildContext context) { - // Consumer와 HookBuilder 모두 사용하는 것과 동일합니다. - return HookConsumer( - builder: (context, ref, child) { - final counter = useState(0); - final value = ref.watch(myProvider); - - return Text('Hello $counter $value'); - }, - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer_widget.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer_widget.dart deleted file mode 100644 index 9d857d887..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_hooks/hook_consumer_widget.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../providers/creating_a_provider/codegen.dart'; - -class MyValue {} - -/* SNIPPET START */ - -// HookWidget 대신 HookConsumerWidget을 확장합니다. -class Example extends HookConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // 여기서는 hooks과 providers를 모두 사용할 수 있습니다. - final counter = useState(0); - final value = ref.watch(myProvider); - - return Text('Hello $counter $value'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/codegen.dart deleted file mode 100644 index b544b3778..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/codegen.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import 'models.dart'; - -part 'codegen.g.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -// The current search filter -final searchProvider = StateProvider((ref) => ''); - -@riverpod -Stream configs(ConfigsRef ref) { - return Stream.value(Configuration()); -} - -@riverpod -Future> characters(CharactersRef ref) async { - final search = ref.watch(searchProvider); - final configs = await ref.watch(configsProvider.future); - final response = await dio.get>>( - '${configs.host}/characters?search=$search'); - - return response.data!.map(Character.fromJson).toList(); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/models.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/models.dart deleted file mode 100644 index e21e1d7c6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/models.dart +++ /dev/null @@ -1,17 +0,0 @@ - -class Character { - Character(); - - // ignore: avoid_unused_constructor_parameters - factory Character.fromJson(Map json) { - return Character(); - } -} - -class Configuration { - Configuration({ - this.host = '', - }); - - final String host; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/raw.dart deleted file mode 100644 index 948148bd0..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/characters_provider/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'models.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -// The current search filter -final searchProvider = StateProvider((ref) => ''); - -/// Configurations which can change over time -final configsProvider = StreamProvider( - (ref) => Stream.value(Configuration()), -); - -final charactersProvider = FutureProvider>((ref) async { - final search = ref.watch(searchProvider); - final configs = await ref.watch(configsProvider.future); - final response = await dio.get>>( - '${configs.host}/characters?search=$search'); - - return response.data!.map(Character.fromJson).toList(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/codegen.dart deleted file mode 100644 index 8b8f234b9..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/codegen.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -String city(CityRef ref) => 'London'; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/raw.dart deleted file mode 100644 index d8093431c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/city_provider/raw.dart +++ /dev/null @@ -1,4 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final cityProvider = Provider((ref) => 'London'); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/codegen.dart deleted file mode 100644 index 0d2e49b28..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/codegen.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../todo_list_provider/raw.dart'; - -part 'codegen.g.dart'; - -enum Filter { - none, - completed, - uncompleted, -} - -final filterProvider = StateProvider((ref) => Filter.none); - -/* SNIPPET START */ - -@riverpod -List filteredTodoList(FilteredTodoListRef ref) { - final filter = ref.watch(filterProvider); - final todos = ref.watch(todoListProvider); - - switch (filter) { - case Filter.none: - return todos; - case Filter.completed: - return todos.where((todo) => todo.completed).toList(); - case Filter.uncompleted: - return todos.where((todo) => !todo.completed).toList(); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/raw.dart deleted file mode 100644 index 85885e800..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/filtered_todo_list_provider/raw.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../todo_list_provider/raw.dart'; - -enum Filter { - none, - completed, - uncompleted, -} - -final filterProvider = StateProvider((ref) => Filter.none); - -/* SNIPPET START */ - -final filteredTodoListProvider = Provider>((ref) { - final filter = ref.watch(filterProvider); - final todos = ref.watch(todoListProvider); - - switch (filter) { - case Filter.none: - return todos; - case Filter.completed: - return todos.where((todo) => todo.completed).toList(); - case Filter.uncompleted: - return todos.where((todo) => !todo.completed).toList(); - } -}); \ No newline at end of file diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/codegen.dart deleted file mode 100644 index b1cb3dbe3..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -MyValue another(AnotherRef ref) => MyValue(); - -class MyValue {} - -/* SNIPPET START */ - -@riverpod -MyValue my(MyRef ref) { - // Bad practice to call `read` here - final value = ref.read(anotherProvider); - return value; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/raw.dart deleted file mode 100644 index 76bae4653..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/read_in_provider/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -final anotherProvider = Provider((ref) => MyValue()); - -class MyValue {} - -/* SNIPPET START */ - -final myProvider = Provider((ref) { - // Bad practice to call `read` here - final value = ref.read(anotherProvider); - return value; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/codegen.dart deleted file mode 100644 index e44e202bc..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/codegen.dart +++ /dev/null @@ -1,25 +0,0 @@ - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import 'models.dart'; - -part 'codegen.g.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -@riverpod -Stream config(ConfigRef ref) => Stream.value(Configuration()); - -@riverpod -Future> products(ProductsRef ref) async { - // Listens only to the host. If something else in the configurations - // changes, this will not pointlessly re-evaluate our provider. - final host = await ref.watch(configProvider.selectAsync((config) => config.host)); - - final result = await dio.get>>('$host/products'); - - return result.data!.map(Product.fromJson).toList(); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/models.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/models.dart deleted file mode 100644 index 3a711b4b6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/models.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: sort_constructors_first - -class Product { - const Product({this.title = ''}); - - final String title; - - factory Product.fromJson(Map map) { - return Product( - title: map['title'] as String, - ); - } -} - -class Configuration { - Configuration({ - this.host = '', - }); - - final String host; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/raw.dart deleted file mode 100644 index ae35300b0..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/select_async_provider/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'models.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -final configProvider = - StreamProvider((ref) => Stream.value(Configuration())); - -final productsProvider = FutureProvider>((ref) async { - // Listens only to the host. If something else in the configurations - // changes, this will not pointlessly re-evaluate our provider. - final host = await ref.watch(configProvider.selectAsync((config) => config.host)); - final result = await dio.get>>('$host/products'); - - return result.data!.map(Product.fromJson).toList(); -}); \ No newline at end of file diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/codegen.dart deleted file mode 100644 index a1942dbd4..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; -} - -/* SNIPPET START */ - -@riverpod -class TodoList extends _$TodoList { - @override - List build() { - return []; - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/raw.dart deleted file mode 100644 index a341b7f5b..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/todo_list_provider/raw.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: public_member_api_docs, sort_constructors_first -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - // Since Todo is immutable, we implement a method that allows cloning the - // Todo with slightly different content. - Todo copyWith({String? id, String? description, bool? completed}) { - return Todo( - id: id ?? this.id, - description: description ?? this.description, - completed: completed ?? this.completed, - ); - } -} - -/* SNIPPET START */ - -class TodoList extends Notifier> { - @override - List build() { - return []; - } -} - -final todoListProvider = NotifierProvider>(TodoList.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/codegen.dart deleted file mode 100644 index 8f7af2644..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/codegen.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -String city(CityRef ref) => 'London'; - -class Weather {} - -Future fetchWeather({required String city}) async => Weather(); -/* SNIPPET START */ -@riverpod -Future weather(WeatherRef ref) { - // We use `ref.watch` to listen to another provider, and we pass it the provider - // that we want to consume. Here: cityProvider - final city = ref.watch(cityProvider); - - // We can then use the result to do something based on the value of `cityProvider`. - return fetchWeather(city: city); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/raw.dart deleted file mode 100644 index d25ec4ffc..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/weather_provider/raw.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -final cityProvider = Provider((ref) => 'London'); - -class Weather {} - -Future fetchWeather({required String city}) async => Weather(); - -/* SNIPPET START */ - -final weatherProvider = FutureProvider((ref) async { - // We use `ref.watch` to listen to another provider, and we pass it the provider - // that we want to consume. Here: cityProvider - final city = ref.watch(cityProvider); - - // We can then use the result to do something based on the value of `cityProvider`. - return fetchWeather(city: city); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/codegen.dart deleted file mode 100644 index 1a90008ed..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import 'models.dart'; - -part 'codegen.g.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -@riverpod -Stream config(ConfigRef ref) => Stream.value(Configuration()); - -@riverpod -Future> products(ProductsRef ref) async { - // Will cause productsProvider to re-fetch the products if anything in the - // configurations changes - final configs = await ref.watch(configProvider.future); - - final result = - await dio.get>>('${configs.host}/products'); - return result.data!.map(Product.fromJson).toList(); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/models.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/models.dart deleted file mode 100644 index 8009c2fd8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/models.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -class Product { - Product(); - factory Product.fromJson(Map json) { - return Product(); - } -} - -class Configuration { - Configuration({ - this.host = '', - }); - - final String host; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/raw.dart deleted file mode 100644 index be2be903c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_provider_states/whole_object_provider/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'models.dart'; - -final dio = Dio(); - -/* SNIPPET START */ - -final configProvider = - StreamProvider((ref) => Stream.value(Configuration())); - -final productsProvider = FutureProvider>((ref) async { - // Will cause productsProvider to re-fetch the products if anything in the - // configurations changes - final configs = await ref.watch(configProvider.future); - - final result = await dio.get>>('${configs.host}/products'); - return result.data!.map(Product.fromJson).toList(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx index 5f5d33c9e..d7cdb6fbd 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/combining_providers.mdx @@ -2,14 +2,14 @@ title: Combining Provider States --- -import charactersProvider from "./combining_provider_states/characters_provider"; -import cityProvider from "./combining_provider_states/city_provider"; -import filteredTodoListProvider from "./combining_provider_states/filtered_todo_list_provider"; -import readInProvider from "./combining_provider_states/read_in_provider"; -import selectAsyncProvider from "./combining_provider_states/select_async_provider"; -import todoListProvider from "./combining_provider_states/todo_list_provider"; -import weatherProvider from "./combining_provider_states/weather_provider"; -import wholeObjectProvider from "./combining_provider_states/whole_object_provider"; +import charactersProvider from "/docs/concepts/combining_provider_states/characters_provider"; +import cityProvider from "/docs/concepts/combining_provider_states/city_provider"; +import filteredTodoListProvider from "/docs/concepts/combining_provider_states/filtered_todo_list_provider"; +import readInProvider from "/docs/concepts/combining_provider_states/read_in_provider"; +import selectAsyncProvider from "/docs/concepts/combining_provider_states/select_async_provider"; +import todoListProvider from "/docs/concepts/combining_provider_states/todo_list_provider"; +import weatherProvider from "/docs/concepts/combining_provider_states/weather_provider"; +import wholeObjectProvider from "/docs/concepts/combining_provider_states/whole_object_provider"; import { Link } from "../../../../../src/components/Link"; import { trimSnippet, diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart deleted file mode 100644 index 4ee7792f9..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/dialog_scope.dart +++ /dev/null @@ -1,58 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// Have a counter that is being incremented by the FloatingActionButton -final counterProvider = StateProvider((ref) => 0); - -class Home extends ConsumerWidget { - const Home({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // We want to show a dialog with the count on a button press - return Scaffold( - body: Column( - children: [ - ElevatedButton( - onPressed: () { - showDialog( - context: context, - builder: (c) { - // We wrap the dialog with a ProviderScope widget, providing the - // parent container to ensure the dialog can access the same providers - // that are accessible by the Home widget. - return ProviderScope( - parent: ProviderScope.containerOf(context), - child: const AlertDialog( - content: CounterDisplay(), - ), - ); - }, - ); - }, - child: const Text('Show Dialog'), - ), - ], - ), - floatingActionButton: FloatingActionButton( - child: const Icon(Icons.add), - onPressed: () { - ref.read(counterProvider.notifier).state++; - }, - )); - } -} - -class CounterDisplay extends ConsumerWidget { - const CounterDisplay({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final count = ref.watch(counterProvider); - return Text('$count'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/codegen.dart deleted file mode 100644 index 0977a8087..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/codegen.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: unnecessary_lambdas - -import 'dart:async'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Stream example(ExampleRef ref) { - final streamController = StreamController(); - - ref.onDispose(() { - // Closes the StreamController when the state of this provider is destroyed. - streamController.close(); - }); - - return streamController.stream; -} - diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/raw.dart deleted file mode 100644 index a9b5741d8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/lifecycle_on_dispose/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unnecessary_lambdas - -import 'dart:async'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -final example = StreamProvider.autoDispose((ref) { - final streamController = StreamController(); - - ref.onDispose(() { - // Closes the StreamController when the state of this provider is destroyed. - streamController.close(); - }); - - return streamController.stream; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx index 971ae56ef..832377393 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/provider_lifecycles.mdx @@ -3,7 +3,7 @@ title: Provider Lifecycles --- import CodeBlock from "@theme/CodeBlock"; -import onDispose from "./lifecycle_on_dispose"; +import onDispose from "/docs/concepts/lifecycle_on_dispose"; import { trimSnippet, When, AutoSnippet } from "../../../../../src/components/CodeSnippet"; :::caution diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers.mdx index 2bdf5467d..e9b7c75f7 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers.mdx @@ -2,8 +2,8 @@ title: Providers --- -import creatingProvider from "./providers/creating_a_provider"; -import declaringManyProviders from "./providers/declaring_many_providers"; +import creatingProvider from "/docs/concepts/providers/creating_a_provider"; +import declaringManyProviders from "/docs/concepts/providers/declaring_many_providers"; import { AutoSnippet, } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/codegen.dart deleted file mode 100644 index 8dc6c5e12..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/codegen.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -class MyValue {} - -/* SNIPPET START */ - -@riverpod -MyValue my(MyRef ref) { - return MyValue(); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/raw.dart deleted file mode 100644 index d63faf94b..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/creating_a_provider/raw.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class MyValue {} - -/* SNIPPET START */ - -final myProvider = Provider((ref) { - return MyValue(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/codegen.dart deleted file mode 100644 index a9472e02a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/codegen.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -String city(CityRef ref) => 'London'; -@riverpod -String country(CountryRef ref) => 'England'; - diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/raw.dart deleted file mode 100644 index 60a3d4786..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/providers/declaring_many_providers/raw.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final cityProvider = Provider((ref) => 'London'); -final countryProvider = Provider((ref) => 'England'); \ No newline at end of file diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading.mdx index 78345456a..b090c1dd7 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading.mdx @@ -3,19 +3,19 @@ title: Reading a Provider --- import CodeBlock from "@theme/CodeBlock"; -import counter from "./reading/counter"; -import consumerWidget from "./reading/consumer_widget"; -import consumerStatefulWidget from "./reading/consumer_stateful_widget"; +import counter from "/docs/concepts/reading/counter"; +import consumerWidget from "/docs/concepts/reading/consumer_widget"; +import consumerStatefulWidget from "/docs/concepts/reading/consumer_stateful_widget"; import consumerHook from "!!raw-loader!/docs/concepts/reading/consumer_hook.dart"; -import watch from "./reading/watch"; -import watchBuild from "./reading/watch_build"; -import listen from "./reading/listen"; -import listenBuild from "./reading/listen_build"; -import read from "./reading/read"; -import readBuild from "./reading/read_build"; -import readNotifierBuild from "./reading/read_notifier_build"; -import watchNotifierBuild from "./reading/watch_notifier_build"; -import provider from "./reading/provider"; +import watch from "/docs/concepts/reading/watch"; +import watchBuild from "/docs/concepts/reading/watch_build"; +import listen from "/docs/concepts/reading/listen"; +import listenBuild from "/docs/concepts/reading/listen_build"; +import read from "/docs/concepts/reading/read"; +import readBuild from "/docs/concepts/reading/read_build"; +import readNotifierBuild from "/docs/concepts/reading/read_notifier_build"; +import watchNotifierBuild from "/docs/concepts/reading/watch_notifier_build"; +import provider from "/docs/concepts/reading/provider"; import { trimSnippet, AutoSnippet, diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/hooks.dart deleted file mode 100644 index 7b9118cbc..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/hooks.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends StatefulHookConsumerWidget { - const HomeView({super.key}); - - @override - HomeViewState createState() => HomeViewState(); -} - -class HomeViewState extends ConsumerState { - @override - void initState() { - super.initState(); - // "ref" can be used in all life-cycles of a StatefulWidget. - ref.read(counterProvider); - } - - @override - Widget build(BuildContext context) { - // Like HookConsumerWidget, we can use hooks inside the builder - final state = useState(0); - - // We can also use "ref" to listen to a provider inside the build method - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/index.tsx deleted file mode 100644 index 9c0ae43de..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import hooks from "!!raw-loader!./hooks.dart"; - -export default { - raw, - hooks: hooks, - codegen: raw, - hooksCodegen: hooks, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/raw.dart deleted file mode 100644 index 98d7f3403..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_stateful_widget/raw.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends ConsumerStatefulWidget { - const HomeView({super.key}); - - @override - HomeViewState createState() => HomeViewState(); -} - -class HomeViewState extends ConsumerState { - @override - void initState() { - super.initState(); - // "ref" can be used in all life-cycles of a StatefulWidget. - ref.read(counterProvider); - } - - @override - Widget build(BuildContext context) { - // We can also use "ref" to listen to a provider inside the build method - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/hooks.dart deleted file mode 100644 index 1c5547428..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/hooks.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // HookConsumerWidget allows using hooks inside the build method - final state = useState(0); - - // We can also use the ref parameter to listen to providers. - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/index.tsx deleted file mode 100644 index 9c0ae43de..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import hooks from "!!raw-loader!./hooks.dart"; - -export default { - raw, - hooks: hooks, - codegen: raw, - hooksCodegen: hooks, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/raw.dart deleted file mode 100644 index d2df7c5a7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/consumer_widget/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - return Text('$counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/codegen.dart deleted file mode 100644 index ca1edf42e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final repositoryProvider = Provider((ref) => Repository()); - -class Repository { - Future post(String url) async {} -} - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - - void increment() { - // Counter can use the "ref" to read other providers - final repository = ref.read(repositoryProvider); - repository.post('...'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/raw.dart deleted file mode 100644 index b97c93b00..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/counter/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -final repositoryProvider = Provider((ref) => Repository()); - -class Repository { - Future post(String url) async {} -} - -/* SNIPPET START */ - -final counterProvider = StateNotifierProvider((ref) { - return Counter(ref); -}); - -class Counter extends StateNotifier { - Counter(this.ref) : super(0); - - final Ref ref; - - void increment() { - // Counter can use the "ref" to read other providers - final repository = ref.read(repositoryProvider); - repository.post('...'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/codegen.dart deleted file mode 100644 index 154e25e27..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/codegen.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; -import '../counter/raw.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -void another(AnotherRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - // ... -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/raw.dart deleted file mode 100644 index ab229db6e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:riverpod/riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final anotherProvider = Provider((ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - // ... -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen.dart deleted file mode 100644 index e22f4b169..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; -} - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - return Container(); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen_hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen_hooks.dart deleted file mode 100644 index 5b1147d28..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/codegen_hooks.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_hooks.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; -} - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - final greeting = useState('Hello'); - - return Container( - alignment: Alignment.center, - child: Text(greeting.value), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/index.tsx deleted file mode 100644 index a856c4980..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen_hooks from "!!raw-loader!./codegen_hooks.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: codegen_hooks, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw.dart deleted file mode 100644 index e59ddaf57..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = - StateNotifierProvider(Counter.new); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - return Container(); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw_hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw_hooks.dart deleted file mode 100644 index 9f86fc19f..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/listen_build/raw_hooks.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = - StateNotifierProvider(Counter.new); - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(counterProvider, (int? previousCount, int newCount) { - print('The counter changed $newCount'); - }); - - final greeting = useState('Hello'); - - return Container( - alignment: Alignment.center, - child: Text(greeting.value), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/codegen.dart deleted file mode 100644 index 201c92f91..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/codegen.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -class Repository { - String get() => ''; -} - -@riverpod -Repository repository(RepositoryRef ref) => Repository(); - -/* SNIPPET START */ - -@riverpod -String value(ValueRef ref) { - // use ref to obtain other providers - final repository = ref.watch(repositoryProvider); - return repository.get(); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/raw.dart deleted file mode 100644 index 28fdfed97..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/provider/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Repository { - void get() {} -} - -final repositoryProvider = Provider((ref) { - return Repository(); -}); - -/* SNIPPET START */ - -final valueProvider = Provider((ref) { - // use ref to obtain other providers - final repository = ref.watch(repositoryProvider); - return repository.get(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen.dart deleted file mode 100644 index 0742ed5e5..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen.dart +++ /dev/null @@ -1,32 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen_hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen_hooks.dart deleted file mode 100644 index 341087cde..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/codegen_hooks.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_hooks.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final greeting = useState('Hello'); - - return Scaffold( - body: Center(child: Text(greeting.value)), - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/index.tsx deleted file mode 100644 index d0caf89aa..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import codegen_hooks from "!!raw-loader!./codegen_hooks.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: codegen_hooks, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/raw.dart deleted file mode 100644 index 7d8685155..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/raw.dart +++ /dev/null @@ -1,26 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = StateNotifierProvider(Counter.new); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/raw_hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/raw_hooks.dart deleted file mode 100644 index acc6ba980..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read/raw_hooks.dart +++ /dev/null @@ -1,31 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../counter/raw.dart'; - -/* SNIPPET START */ - -final counterProvider = - StateNotifierProvider(Counter.new); - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final greeting = useState('Hello'); - - return Scaffold( - body: Center(child: Text(greeting.value)), - floatingActionButton: FloatingActionButton( - onPressed: () { - // Call `increment()` on the `Counter` class - ref.read(counterProvider.notifier).increment(); - }, - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/codegen.dart deleted file mode 100644 index 9a4347159..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/codegen.dart +++ /dev/null @@ -1,25 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -Widget build(BuildContext context, WidgetRef ref) { - // use "read" to ignore updates on a provider - final counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: counter.increment, - child: const Text('button'), - ); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/raw.dart deleted file mode 100644 index 266e00224..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_build/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -Widget build(BuildContext context, WidgetRef ref) { - // use "read" to ignore updates on a provider - final counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.state++, - child: const Text('button'), - ); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/codegen.dart deleted file mode 100644 index 6bf061abf..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -Widget build(BuildContext context, WidgetRef ref) { - Counter counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.increment(), - child: const Text('button'), - ); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/raw.dart deleted file mode 100644 index 0ec5b5958..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/read_notifier_build/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -Widget build(BuildContext context, WidgetRef ref) { - StateController counter = ref.read(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.state++, - child: const Text('button'), - ); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/codegen.dart deleted file mode 100644 index 31de6da74..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/codegen.dart +++ /dev/null @@ -1,45 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -/* SNIPPET START */ - -@riverpod -FilterType filterType(FilterTypeRef ref) { - return FilterType.none; -} - -@riverpod -class Todos extends _$Todos { - @override - List build() { - return []; - } -} - -@riverpod -List filteredTodoList(FilteredTodoListRef ref) { - // obtains both the filter and the list of todos - final FilterType filter = ref.watch(filterTypeProvider); - final List todos = ref.watch(todosProvider); - - switch (filter) { - case FilterType.completed: - // return the completed list of todos - return todos.where((todo) => todo.isCompleted).toList(); - case FilterType.none: - // returns the unfiltered list of todos - return todos; - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/raw.dart deleted file mode 100644 index 625c0fe9a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch/raw.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -class TodoList extends StateNotifier> { - TodoList() : super([]); -} - -/* SNIPPET START */ - -final filterTypeProvider = StateProvider((ref) => FilterType.none); -final todosProvider = - StateNotifierProvider>((ref) => TodoList()); - -final filteredTodoListProvider = Provider((ref) { - // obtains both the filter and the list of todos - final FilterType filter = ref.watch(filterTypeProvider); - final List todos = ref.watch(todosProvider); - - switch (filter) { - case FilterType.completed: - // return the completed list of todos - return todos.where((todo) => todo.isCompleted).toList(); - case FilterType.none: - // returns the unfiltered list of todos - return todos; - } -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen.dart deleted file mode 100644 index 80b63d216..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen.dart +++ /dev/null @@ -1,39 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -@riverpod -class TodoList extends _$TodoList { - @override - List build() => []; -} - -/* SNIPPET START */ - -@riverpod -int counter(CounterRef ref) => 0; - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('$counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen_hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen_hooks.dart deleted file mode 100644 index c82698304..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/codegen_hooks.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: omit_local_variable_types, avoid_types_on_closure_parameters, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_hooks.g.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -@riverpod -class TodoList extends _$TodoList { - @override - List build() => []; -} - -/* SNIPPET START */ - -@riverpod -int counter(CounterRef ref) => 0; - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // You can use hooks inside a HookConsumerWidget - final greeting = useState('Hello'); - - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('${greeting.value} $counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/index.tsx deleted file mode 100644 index a856c4980..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen_hooks from "!!raw-loader!./codegen_hooks.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: codegen_hooks, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw.dart deleted file mode 100644 index 8d5d430eb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -class TodoList extends StateNotifier> { - TodoList() : super([]); -} - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('$counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw_hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw_hooks.dart deleted file mode 100644 index 5f297850a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_build/raw_hooks.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -enum FilterType { - none, - completed, -} - -abstract class Todo { - bool get isCompleted; -} - -class TodoList extends StateNotifier> { - TodoList() : super([]); -} - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends HookConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // You can use hooks inside a HookConsumerWidget - final greeting = useState('Hello'); - - // use ref to listen to a provider - final counter = ref.watch(counterProvider); - - return Text('${greeting.value} $counter'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/codegen.dart deleted file mode 100644 index 6b76d0219..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class Counter extends _$Counter { - @override - int build() => 0; - void increment() => state = state + 1; -} - -Widget build(BuildContext context, WidgetRef ref) { - Counter counter = ref.watch(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.increment(), - child: const Text('button'), - ); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/raw.dart deleted file mode 100644 index 66c630717..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/reading/watch_notifier_build/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -Widget build(BuildContext context, WidgetRef ref) { - StateController counter = ref.watch(counterProvider.notifier); - return ElevatedButton( - onPressed: () => counter.state++, - child: const Text('button'), - ); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/scopes.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/scopes.mdx index f53d8315d..f9289b83b 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/scopes.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/scopes.mdx @@ -4,7 +4,6 @@ title: Scopes import CodeBlock from "@theme/CodeBlock"; import asyncInitialization from "!!raw-loader!/docs/concepts/async_initialization.dart"; -import dialogScope from "!!raw-loader!/docs/concepts/dialog_scope.dart"; import themeScope from "!!raw-loader!/docs/concepts/theme_scope.dart"; import subtreeScope from "!!raw-loader!/docs/concepts/subtree_scope.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; @@ -87,20 +86,6 @@ So how do you makes these sorts of provider states available synchronously? Here is an example that shows how scoping allows you override a dummy provider when your asynchronous API is ready. -{trimSnippet(asyncInitialization)} - -## Showing Dialogs - -When you show a `Dialog` or `OverlayEntry`, flutter creates a new `Route` or adds to an `Overlay` that has a different build scope, -so that it can escape the layout of it's parent, and can be shown above other `Routes`. -This presents a problem for `InheritedWidget`s in general, and since [ProviderScope] is an `InheritedWidget`, it is also affected. - -To solve this problem, Riverpod allows you to create a `ProviderScope` that can access the state of all providers in a `parent` scope. - -The following example shows how to use this, to allow a `Dialog` to access the state of a counter from the context that caused the `Dialog` to be shown. - -{trimSnippet(dialogScope)} - ## Subtree Scoping Scoping allows you to override the state of a provider for a specific subtree of your widget tree. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx index 4e23da9fc..640d98e35 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability.mdx @@ -4,7 +4,7 @@ title: Why Immutability import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; -import whyImmutability from "./why_immutability" +import whyImmutability from "/docs/concepts/why_immutability" import { trimSnippet, AutoSnippet, diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/codegen.dart deleted file mode 100644 index fd286a36c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/codegen.dart +++ /dev/null @@ -1,58 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -class ThemeNotifier extends _$ThemeNotifier { - @override - ThemeSettings build() => const ThemeSettings( - mode: ThemeMode.light, - primaryColor: Colors.blue, - ); - - void toggle() { - state = state.copyWith(mode: state.mode.toggle); - } - - void setDarkTheme() { - state = state.copyWith(mode: ThemeMode.dark); - } - - void setLightTheme() { - state = state.copyWith(mode: ThemeMode.light); - } - - void setSystemTheme() { - state = state.copyWith(mode: ThemeMode.system); - } - - void setPrimaryColor(Color color) { - state = state.copyWith(primaryColor: color); - } -} - -@freezed -class ThemeSettings with _$ThemeSettings { - const factory ThemeSettings({ - required ThemeMode mode, - required Color primaryColor, - }) = _ThemeSettings; -} - -extension ToggleTheme on ThemeMode { - ThemeMode get toggle { - switch (this) { - case ThemeMode.dark: - return ThemeMode.light; - case ThemeMode.light: - return ThemeMode.dark; - case ThemeMode.system: - return ThemeMode.system; - } - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/raw.dart deleted file mode 100644 index 1e34c694c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/why_immutability/raw.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final themeProvider = - NotifierProvider(ThemeNotifier.new); - -class ThemeNotifier extends Notifier { - @override - ThemeSettings build() { - return ThemeSettings(mode: ThemeMode.system, primaryColor: Colors.blue); - } - - void toggle() { - state = state.copyWith(mode: state.mode.toggle); - } - - void setDarkTheme() { - state = state.copyWith(mode: ThemeMode.dark); - } - - void setLightTheme() { - state = state.copyWith(mode: ThemeMode.light); - } - - void setSystemTheme() { - state = state.copyWith(mode: ThemeMode.system); - } - - void setPrimaryColor(Color color) { - state = state.copyWith(primaryColor: color); - } -} - -class ThemeSettings { - ThemeSettings({ - required this.mode, - required this.primaryColor, - }); - - final ThemeMode mode; - final Color primaryColor; - - ThemeSettings copyWith({ - ThemeMode? mode, - Color? primaryColor, - }) { - return ThemeSettings( - mode: mode ?? this.mode, - primaryColor: primaryColor ?? this.primaryColor, - ); - } -} - -extension ToggleTheme on ThemeMode { - ThemeMode get toggle { - switch (this) { - case ThemeMode.dark: - return ThemeMode.light; - case ThemeMode.light: - return ThemeMode.dark; - case ThemeMode.system: - return ThemeMode.system; - } - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx index e3f1407da..95d3086b3 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose.mdx @@ -4,14 +4,14 @@ title: "캐시 지우기 및 상태 폐기(disposal)에 반응하기" import { Link } from "../../../../../src/components/Link"; import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import onDisposeExample from "./auto_dispose/on_dispose_example"; -import codegenKeepAlive from "!!raw-loader!./auto_dispose/codegen_keep_alive.dart"; -import rawAutoDispose from "!!raw-loader!./auto_dispose/raw_auto_dispose.dart"; -import invalidateExample from "!!raw-loader!./auto_dispose/invalidate_example.dart"; -import keepAlive from "./auto_dispose/keep_alive"; -import cacheForExtension from "!!raw-loader!./auto_dispose/cache_for_extension.dart"; -import cacheForUsage from "./auto_dispose/cache_for_usage"; -import invalidateFamilyExample from './auto_dispose/invalidate_family_example' +import onDisposeExample from "/docs/essentials/auto_dispose/on_dispose_example"; +import codegenKeepAlive from "!!raw-loader!/docs/essentials/auto_dispose/codegen_keep_alive.dart"; +import rawAutoDispose from "!!raw-loader!/docs/essentials/auto_dispose/raw_auto_dispose.dart"; +import invalidateExample from "!!raw-loader!/docs/essentials/auto_dispose/invalidate_example.dart"; +import keepAlive from "/docs/essentials/auto_dispose/keep_alive"; +import cacheForExtension from "!!raw-loader!/docs/essentials/auto_dispose/cache_for_extension.dart"; +import cacheForUsage from "/docs/essentials/auto_dispose/cache_for_usage"; +import invalidateFamilyExample from '/docs/essentials/auto_dispose/invalidate_family_example' 지금까지 일부 상태(state)를 생성하거나 업데이트하는 방법을 살펴보았습니다. 하지만 언제 상태가 소멸(destruction)되는지에 대해서는 아직 이야기하지 않았습니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_extension.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_extension.dart deleted file mode 100644 index 6ea5d7fef..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_extension.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'dart:async'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -extension CacheForExtension on AutoDisposeRef { - /// [duration]동안 공급자를 살아있게 유지합니다. - void cacheFor(Duration duration) { - // 상태가 파괴되는 것을 즉시 방지합니다. - final link = keepAlive(); - // 기간이 경과하면 자동 폐기를 다시 활성화합니다. - final timer = Timer(duration, link.close); - - // 선택 사항: provider가 다시 계산되면(예: ref.watch 사용) 보류 중인 타이머를 취소합니다. - onDispose(timer.cancel); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/codegen.dart deleted file mode 100644 index db007483d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../cache_for_extension.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future example(ExampleRef ref) async { - /// 5분 동안 상태를 유지합니다. - ref.cacheFor(const Duration(minutes: 5)); - - return http.get(Uri.https('example.com')); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/raw.dart deleted file mode 100644 index 2a2cf358a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/cache_for_usage/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../cache_for_extension.dart'; - -/* SNIPPET START */ -final provider = FutureProvider.autoDispose((ref) async { - /// Keeps the state alive for 5 minutes - ref.cacheFor(const Duration(minutes: 5)); - - return http.get(Uri.https('example.com')); -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/codegen_keep_alive.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/codegen_keep_alive.dart deleted file mode 100644 index d3a3536c4..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/codegen_keep_alive.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen_keep_alive.g.dart'; - -/* SNIPPET START */ -// 어노테이션에 "keepAlive"를 지정하여 -// 자동 상태 소멸을 비활성화할 수 있습니다. -@Riverpod(keepAlive: true) -int example(ExampleRef ref) { - return 0; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_example.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_example.dart deleted file mode 100644 index 09390ff9e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_example.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -// 자동 상태 소멸을 활성화하려면 autoDispose를 지정할 수 있습니다. -final someProvider = Provider.autoDispose((ref) { - return 0; -}); - -/* SNIPPET START */ -class MyWidget extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - return ElevatedButton( - onPressed: () { - // 클릭 시 공급자를 삭제합니다. - ref.invalidate(someProvider); - }, - child: const Text('dispose a provider'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/codegen.dart deleted file mode 100644 index 9ce0d96b8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -late WidgetRef ref; - -/* SNIPPET START */ -@riverpod -String label(LabelRef ref, String userName) { - return 'Hello $userName'; -} - -// ... - -void onTap() { - // 이 provider의 가능한 모든 매개변수 조합을 무효화합니다. - ref.invalidate(labelProvider); - // 특정 조합만 무효화 - ref.invalidate(labelProvider('John')); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/raw.dart deleted file mode 100644 index 1f3164bfb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/invalidate_family_example/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -late WidgetRef ref; - -/* SNIPPET START */ -final provider = Provider.autoDispose.family((ref, name) { - return 'Hello $name'; -}); - -// ... - -void onTap() { - // Invalidate all possible parameter combinations of this provider. - ref.invalidate(provider); - // Invalidate a specific combination only - ref.invalidate(provider('John')); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/codegen.dart deleted file mode 100644 index 1828451dc..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/codegen.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Future example(ExampleRef ref) async { - final response = await http.get(Uri.parse('https://example.com')); - // 요청이 성공적으로 완료된 후에만 프로바이더를 살아있게 유지합니다. - // 요청이 실패한 경우(그리고 throw된 경우), 공급자에 청취를 중단하면 상태가 소멸됩니다. - ref.keepAlive(); - - // `link`를 사용하여 자동 폐기 동작을 복원할 수 있습니다: - // link.close(); - - return response.body; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/raw.dart deleted file mode 100644 index f0fc6a3ba..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/keep_alive/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -final provider = FutureProvider.autoDispose((ref) async { - final response = await http.get(Uri.parse('https://example.com')); - // We keep the provider alive only after the request has successfully completed. - // If the request failed (and threw an exception), then when the provider stops being - // listened to, the state will be destroyed. - final link = ref.keepAlive(); - - // We can use the `link` to restore the auto-dispose behavior with: - // link.close(); - - return response.body; -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/codegen.dart deleted file mode 100644 index 013988467..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:async'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -int other(OtherRef ref) => 0; - -/* SNIPPET START */ -@riverpod -Stream example(ExampleRef ref) { - final controller = StreamController(); - - // 상태가 소멸되면 StreamController를 닫습니다. - ref.onDispose(controller.close); - - // TO-DO: StreamController의 값들을 푸시합니다. - return controller.stream; -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/raw.dart deleted file mode 100644 index 4e4940777..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/on_dispose_example/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:async'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -final provider = StreamProvider((ref) { - final controller = StreamController(); - - // When the state is destroyed, we close the StreamController. - ref.onDispose(controller.close); - - // TO-DO: Push some values in the StreamController - return controller.stream; -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/raw_auto_dispose.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/raw_auto_dispose.dart deleted file mode 100644 index e6746e2a0..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/auto_dispose/raw_auto_dispose.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -// 자동 상태 소멸을 활성화하려면 autoDispose를 지정할 수 있습니다. -final provider = Provider.autoDispose((ref) { - return 0; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx index ede4c45d0..29d87ba28 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests.mdx @@ -5,12 +5,12 @@ version: 1 import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import functionalRef from "./combining_requests/functional_ref"; -import notifierRef from "./combining_requests/notifier_ref"; -import watchExample from "./combining_requests/watch_example"; -import watchPlacement from "./combining_requests/watch_placement"; -import listenExample from "./combining_requests/listen_example"; -import readExample from './combining_requests/read_example' +import functionalRef from "/docs/essentials/combining_requests/functional_ref"; +import notifierRef from "/docs/essentials/combining_requests/notifier_ref"; +import watchExample from "/docs/essentials/combining_requests/watch_example"; +import watchPlacement from "/docs/essentials/combining_requests/watch_placement"; +import listenExample from "/docs/essentials/combining_requests/listen_example"; +import readExample from '/docs/essentials/combining_requests/read_example' 지금까지는 요청이 서로 독립적인 경우만 보았습니다. 하지만 일반적인 사용 사례는 다른 요청의 결과에 따라 요청을 트리거해야 하는 경우입니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/codegen.dart deleted file mode 100644 index 2d6aa1460..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/codegen.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -int other(OtherRef ref) => 0; - -/* SNIPPET START */ -@riverpod -int example(ExampleRef ref) { - // 다른 provider를 읽으려면 여기에서 "Ref"를 사용할 수 있습니다. - final otherValue = ref.watch(otherProvider); - - return 0; -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/raw.dart deleted file mode 100644 index 19962d9cd..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/functional_ref/raw.dart +++ /dev/null @@ -1,14 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = Provider((ref) { - // "Ref" can be used here to read other providers - final otherValue = ref.watch(otherProvider); - - return 0; -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/codegen.dart deleted file mode 100644 index 25c6a2f37..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -@riverpod -int example(ExampleRef ref) { - ref.listen(otherProvider, (previous, next) { - print('Changed from: $previous, next: $next'); - }); - - return 0; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/raw.dart deleted file mode 100644 index 12b578dd0..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/listen_example/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = Provider((ref) { - ref.listen(otherProvider, (previous, next) { - print('Changed from: $previous, next: $next'); - }); - - return 0; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/codegen.dart deleted file mode 100644 index 1454617d1..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/codegen.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -@riverpod -int other(OtherRef ref) => 0; - -/* SNIPPET START */ -@riverpod -class Example extends _$Example { - @override - int build() { - // 다른 provider를 읽으려면 여기에서 "Ref"를 사용할 수 있습니다. - final otherValue = ref.watch(otherProvider); - - return 0; - } -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/raw.dart deleted file mode 100644 index d292fea5e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/notifier_ref/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = NotifierProvider(MyNotifier.new); - -class MyNotifier extends Notifier { - @override - int build() { - // "Ref" can be used here to read other providers - final otherValue = ref.watch(otherProvider); - - return 0; - } -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/codegen.dart deleted file mode 100644 index fc46f5927..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - // Bad! 여기서는 reactive가 아니므로 'read'를 사용하지 마세요. - ref.read(otherProvider); - - return 0; - } - - void increment() { - ref.read(otherProvider); // 여기서 'read'를 사용해도 괜찮습니다. - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/raw.dart deleted file mode 100644 index e269310eb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/read_example/raw.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final notifierProvider = NotifierProvider(MyNotifier.new); - -class MyNotifier extends Notifier { - @override - int build() { - // Bad! Do not use "read" here as it is not reactive - ref.read(otherProvider); - - return 0; - } - - void increment() { - ref.read(otherProvider); // Using "read" here is fine - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/codegen.dart deleted file mode 100644 index 2521721cb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/codegen.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -const someStream = Stream<({double longitude, double latitude})>.empty(); - -/* SNIPPET START */ -@riverpod -Stream<({double longitude, double latitude})> location(LocationRef ref) { - // TO-DO: 현재 위치를 가져오는 Stream을 반환합니다. - return someStream; -} - -@riverpod -Future> restaurantsNearMe(RestaurantsNearMeRef ref) async { - // "ref.watch"를 사용하여 최신 위치를 가져옵니다. - // 공급자 뒤에 ".future"를 지정하면 코드가 적어도 하나의 위치를 사용할 수 있을 때까지 기다립니다. - final location = await ref.watch(locationProvider.future); - - // 이제 해당 위치를 기반으로 네트워크 요청을 할 수 있습니다. - // 예를 들어 Google 지도 API를 사용할 수 있습니다: - // https://developers.google.com/maps/documentation/places/web-service/search-nearby - final response = await http.get( - Uri.https('maps.googleapis.com', 'maps/api/place/nearbysearch/json', { - 'location': '${location.latitude},${location.longitude}', - 'radius': '1500', - 'type': 'restaurant', - 'key': '', - }), - ); - // JSON에서 레스토랑 이름 가져오기 - final json = jsonDecode(response.body) as Map; - final results = (json['results'] as List).cast>(); - return results.map((e) => e['name']! as String).toList(); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/raw.dart deleted file mode 100644 index f4e85466e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_example/raw.dart +++ /dev/null @@ -1,41 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -const someStream = Stream<({double longitude, double latitude})>.empty(); - -/* SNIPPET START */ -final locationProvider = - StreamProvider<({double longitude, double latitude})>((ref) { - // TO-DO: Return a stream which obtains the current location - return someStream; -}); - -final restaurantsNearMeProvider = FutureProvider>((ref) async { - // We use "ref.watch" to obtain the latest location. - // By specifying that ".future" after the provider, our code will wait - // for at least one location to be available. - final location = await ref.watch(locationProvider.future); - - // We can now make a network request based on that location. - // For example, we could use the Google Map API: - // https://developers.google.com/maps/documentation/places/web-service/search-nearby - final response = await http.get( - Uri.https('maps.googleapis.com', 'maps/api/place/nearbysearch/json', { - 'location': '${location.latitude},${location.longitude}', - 'radius': '1500', - 'type': 'restaurant', - 'key': '', - }), - ); - // Obtain the restaurant names from the JSON - final json = jsonDecode(response.body) as Map; - final results = (json['results'] as List).cast>(); - return results.map((e) => e['name']! as String).toList(); -}); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/codegen.dart deleted file mode 100644 index 736d1ecc7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/codegen.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/foundation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -@riverpod -int example(ExampleRef ref) { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - final someListenable = ValueNotifier(0); - someListenable.addListener(() { - ref.watch(otherProvider); // Bad! - }); - - return 0; -} - -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - return 0; - } - - void increment() { - ref.watch(otherProvider); // Bad! - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/raw.dart deleted file mode 100644 index 34fa8f6c9..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/combining_requests/watch_placement/raw.dart +++ /dev/null @@ -1,35 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/foundation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -final otherProvider = Provider((ref) => 0); - -/* SNIPPET START */ -final provider = Provider((ref) { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - final someListenable = ValueNotifier(0); - someListenable.addListener(() { - ref.watch(otherProvider); // Bad! - }); - - return 0; -}); - -final notifierProvider = NotifierProvider(MyNotifier.new); - -class MyNotifier extends Notifier { - @override - int build() { - ref.watch(otherProvider); // Good! - ref.onDispose(() => ref.watch(otherProvider)); // Bad! - - return 0; - } - - void increment() { - ref.watch(otherProvider); // Bad! - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx index c934ddb60..1d87d2591 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization.mdx @@ -5,9 +5,9 @@ version: 1 import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import consumerExample from "!!raw-loader!./eager_initialization/consumer_example.dart"; -import asyncConsumerExample from "!!raw-loader!./eager_initialization/async_consumer_example.dart"; -import requireValue from "./eager_initialization/require_value"; +import consumerExample from "!!raw-loader!/docs/essentials/eager_initialization/consumer_example.dart"; +import asyncConsumerExample from "!!raw-loader!/docs/essentials/eager_initialization/async_consumer_example.dart"; +import requireValue from "/docs/essentials/eager_initialization/require_value"; 모든 providers는 기본적으로 느리게(Lazy) 초기화됩니다. 즉, provider는 처음 사용될 때만 초기화됩니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/async_consumer_example.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/async_consumer_example.dart deleted file mode 100644 index 17bc6de79..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/async_consumer_example.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors, unused_element - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -final myProvider = FutureProvider((ref) => 0); - -/* SNIPPET START */ -class _EagerInitialization extends ConsumerWidget { - const _EagerInitialization({required this.child}); - final Widget child; - - @override - Widget build(BuildContext context, WidgetRef ref) { - final result = ref.watch(myProvider); - - // 오류 상태 및 로딩 상태 처리 - if (result.isLoading) { - return const CircularProgressIndicator(); - } else if (result.hasError) { - return const Text('Oopsy!'); - } - - return child; - } -} -/* SNIPPET END */ - diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/consumer_example.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/consumer_example.dart deleted file mode 100644 index e9df84f4b..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/consumer_example.dart +++ /dev/null @@ -1,36 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -final myProvider = Provider((ref) => 0); - -/* SNIPPET START */ -void main() { - runApp(ProviderScope(child: MyApp())); -} - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return const _EagerInitialization( - // TODO: 여기에서 앱 렌더링 - child: MaterialApp(), - ); - } -} - -class _EagerInitialization extends ConsumerWidget { - const _EagerInitialization({required this.child}); - final Widget child; - - @override - Widget build(BuildContext context, WidgetRef ref) { - // providers를 감시하여 이른 초기화(Eagerly initialize)합니다. - // "watch"를 사용하면 provider가 폐기(disposed)되지 않고 계속 살아 있습니다. - ref.watch(myProvider); - return child; - } -} -/* SNIPPET END */ - diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/codegen.dart deleted file mode 100644 index 7025bd12d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/codegen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -// 이른 초기화된 provider -@riverpod -Future example(ExampleRef ref) async => 'Hello world'; - -class MyConsumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final result = ref.watch(exampleProvider); - - /// provider가 올바르게 초기화되었다면, - /// "requireValue"로 데이터를 직접 읽을 수 있습니다. - return Text(result.requireValue); - } -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/raw.dart deleted file mode 100644 index 0a7b0580b..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/eager_initialization/require_value/raw.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: unused_local_variable, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -// An eagerly initialized provider. -final exampleProvider = FutureProvider((ref) async => 'Hello world'); - -class MyConsumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final result = ref.watch(exampleProvider); - - /// If the provider was correctly eagerly initialized, then we can - /// directly read the data with "requireValue". - return Text(result.requireValue); - } -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx index 5bf4dc7c0..05c8157a7 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args.mdx @@ -5,15 +5,15 @@ version: 1 import { Link } from "../../../../../src/components/Link"; import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import noArgProvider from "./passing_args/no_arg_provider"; +import noArgProvider from "/docs/essentials/passing_args/no_arg_provider"; import family from "!!raw-loader!./passing_args/raw/family.dart"; import codegenFamily from "!!raw-loader!./passing_args/codegen/family.dart"; -import consumerProvider from "!!raw-loader!./passing_args/raw/consumer_provider.dart"; -import consumerFamily from "!!raw-loader!./passing_args/raw/consumer_family.dart"; -import consumerListFamily from "!!raw-loader!./passing_args/raw/consumer_list_family.dart"; -import multipleConsumerFamily from "!!raw-loader!./passing_args/raw/multiple_consumer_family.dart"; -import tupleFamily from "!!raw-loader!./passing_args/raw/tuple_family.dart"; -import consumerTupleFamily from "!!raw-loader!./passing_args/raw/consumer_tuple_family.dart"; +import consumerProvider from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_provider.dart"; +import consumerFamily from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_family.dart"; +import consumerListFamily from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_list_family.dart"; +import multipleConsumerFamily from "!!raw-loader!/docs/essentials/passing_args/raw/multiple_consumer_family.dart"; +import tupleFamily from "!!raw-loader!/docs/essentials/passing_args/raw/tuple_family.dart"; +import consumerTupleFamily from "!!raw-loader!/docs/essentials/passing_args/raw/consumer_tuple_family.dart"; 이전 글에서 "provider"를 정의하여 간단한 _GET_ HTTP 요청을 만드는 방법을 살펴봤습니다. 하지만 HTTP 요청은 외부 매개변수(external parameters)에 의존하는 경우가 많습니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_family.dart deleted file mode 100644 index ed154e255..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_family.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../../first_request/raw/activity.dart'; -import 'family.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - AsyncValue activity = ref.watch( - // 이제 provider는 액티비티 타입을 기대하는 함수입니다. - // 단순화를 위해 지금은 상수 문자열을 전달하겠습니다. - activityProvider('recreational'), - ); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_list_family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_list_family.dart deleted file mode 100644 index 3bd3fdf27..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_list_family.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -final activityProvider = Provider.family((ref, id) { - throw UnimplementedError(); -}); - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - // 대신 문자열 목록을 허용하도록 activityProvider를 업데이트할 수 있습니다. - // 그런 다음 watch를 호출하여 해당 목록을 직접 만들 수 있습니다. - ref.watch(activityProvider(['recreational', 'cooking'])); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_provider.dart deleted file mode 100644 index 337eab2d1..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_provider.dart +++ /dev/null @@ -1,20 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../../first_request/raw/activity.dart'; -import 'provider.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - AsyncValue activity = ref.watch(activityProvider); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_tuple_family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_tuple_family.dart deleted file mode 100644 index e9ce32d48..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/consumer_tuple_family.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'tuple_family.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { -/* SNIPPET START */ - ref.watch( - // Record를 사용하여 매개 변수를 전달할 수 있습니다. - // Record가 ==를 재정의하므로 watch 호출에서 직접 Record를 생성해도 괜찮습니다. - activityProvider((type: 'recreational', maxPrice: 40)), - ); -/* SNIPPET END */ - - return Container(); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/multiple_consumer_family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/multiple_consumer_family.dart deleted file mode 100644 index 3a8160027..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/multiple_consumer_family.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../../first_request/raw/activity.dart'; -import 'family.dart'; - -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - AsyncValue activity = ref.watch( - // 이제 provider는 액티비티 타입을 기대하는 함수입니다. - // 단순화를 위해 지금은 상수 문자열을 전달하겠습니다. - activityProvider('recreational'), - ); - /* SNIPPET START */ - return Consumer( - builder: (context, ref, child) { - final recreational = ref.watch(activityProvider('recreational')); - final cooking = ref.watch(activityProvider('cooking')); - - // 그러면 두 활동을 모두 렌더링할 수 있습니다. - // 두 요청이 모두 병렬로 발생하고 올바르게 캐시됩니다. - return Column( - children: [ - Text(recreational.valueOrNull?.activity ?? ''), - Text(cooking.valueOrNull?.activity ?? ''), - ], - ); - }, - ); - /* SNIPPET END */ - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/tuple_family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/tuple_family.dart deleted file mode 100644 index d0a6edaf6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/passing_args/raw/tuple_family.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: omit_local_variable_types, unused_local_variable, prefer_final_locals - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import '../../first_request/raw/activity.dart'; - -/* SNIPPET START */ - -// provider에게 전달할 매개변수를 나타내는 record를 정의합니다. -// typedef는 선택 사항이지만 코드를 더 읽기 쉽게 만들 수 있습니다. - -typedef ActivityParameters = ({String type, int maxPrice}); - -final activityProvider = FutureProvider.autoDispose - // 이제 새로 정의된 record를 인수 유형으로 사용합니다. - .family((ref, arguments) async { - final response = await http.get( - Uri( - scheme: 'https', - host: 'boredapi.com', - path: '/api/activity', - queryParameters: { - // 마지막으로 인수를 사용하여 쿼리 매개변수를 업데이트할 수 있습니다. - 'type': arguments.type, - 'price': arguments.maxPrice, - }, - ), - ); - final json = jsonDecode(response.body) as Map; - return Activity.fromJson(json); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx index 419ff377a..71520b65b 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/provider_observer.mdx @@ -4,7 +4,7 @@ title: 로깅 및 오류 보고 import { Link } from "../../../../../src/components/Link"; import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import providerObserver from "!!raw-loader!./provider_observer/provider_observer.dart"; +import providerObserver from "!!raw-loader!/docs/essentials/provider_observer/provider_observer.dart"; Riverpod은 기본적으로 provider 트리에서 발생하는 모든 이벤트를 수신하는 방법을 제공합니다. 이 기능은 모든 이벤트를 기록하거나 원격 서비스에 오류를 보고하는 데 사용할 수 있습니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/provider_observer/provider_observer.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/provider_observer/provider_observer.dart deleted file mode 100644 index dd75afb01..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/provider_observer/provider_observer.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -class MyObserver extends ProviderObserver { - @override - void didAddProvider( - ProviderBase provider, - Object? value, - ProviderContainer container, - ) { - print('Provider $provider was initialized with $value'); - } - - @override - void didDisposeProvider( - ProviderBase provider, - ProviderContainer container, - ) { - print('Provider $provider was disposed'); - } - - @override - void didUpdateProvider( - ProviderBase provider, - Object? previousValue, - Object? newValue, - ProviderContainer container, - ) { - print('Provider $provider updated from $previousValue to $newValue'); - } - - @override - void providerDidFail( - ProviderBase provider, - Object error, - StackTrace stackTrace, - ProviderContainer container, - ) { - print('Provider $provider threw $error at $stackTrace'); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx index 348ad0158..720ce0a41 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects.mdx @@ -9,11 +9,11 @@ import Legend, { colors } from "./first_request/legend/legend"; import todoListProvider from "./side_effects/todo_list_provider"; import todoListNotifier from "./side_effects/todo_list_notifier"; import todoListNotifierAddTodo from "./side_effects/todo_list_notifier_add_todo"; -import consumerAddTodoCall from "!!raw-loader!./side_effects/raw/consumer_add_todo_call.dart"; -import restAddTodo from "!!raw-loader!./side_effects/raw/rest_add_todo.dart"; -import invalidateSelfAddTodo from "!!raw-loader!./side_effects/raw/invalidate_self_add_todo.dart"; -import manualAddTodo from "!!raw-loader!./side_effects/raw/manual_add_todo.dart"; -import mutableManualAddTodo from "!!raw-loader!./side_effects/raw/mutable_manual_add_todo.dart"; +import consumerAddTodoCall from "!!raw-loader!/docs/essentials/side_effects/raw/consumer_add_todo_call.dart"; +import restAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/rest_add_todo.dart"; +import invalidateSelfAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/invalidate_self_add_todo.dart"; +import manualAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/manual_add_todo.dart"; +import mutableManualAddTodo from "!!raw-loader!/docs/essentials/side_effects/raw/mutable_manual_add_todo.dart"; import renderAddTodo from "./side_effects/render_add_todo"; 지금까지는 데이터를 가져오는 방법(일명 _GET_ HTTP 요청 수행)만 살펴봤습니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/consumer_add_todo_call.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/consumer_add_todo_call.dart deleted file mode 100644 index f869a1175..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/consumer_add_todo_call.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../raw/todo_list_notifier.dart' show Todo; -import '../raw/todo_list_notifier_add_todo.dart'; - -/* SNIPPET START */ -class Example extends ConsumerWidget { - const Example({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return ElevatedButton( - onPressed: () { - // "ref.read"를 "myProvider.notifier"와 사용하면 - // notifier의 클래스 인스턴스를 얻을 수 있습니다. - // 이를 통해 "addTodo" 메서드를 호출할 수 있습니다. - ref - .read(todoListProvider.notifier) - .addTodo(Todo(description: 'This is a new todo')); - }, - child: const Text('Add todo'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/invalidate_self_add_todo.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/invalidate_self_add_todo.dart deleted file mode 100644 index e83b3708f..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/invalidate_self_add_todo.dart +++ /dev/null @@ -1,38 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = - AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - /* SNIPPET START */ - Future addTodo(Todo todo) async { - // API 응답은 신경 쓰지 않습니다. - await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - // 포스트 요청이 완료되면 로컬 캐시를 더티(dirty)로 표시할 수 있습니다. - // 이렇게 하면 notifier의 "build"가 비동기적으로 다시 호출되고, 이 때 리스너(listener)에게 알림이 전송됩니다. - - ref.invalidateSelf(); - - // (선택 사항) 그런 다음 새 상태가 계산될 때까지 기다릴 수 있습니다. - // 이렇게 하면 새 상태를 사용할 수 있을 때까지 "addTodo"가 완료되지 않습니다. - await future; - } -/* SNIPPET END */ -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/manual_add_todo.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/manual_add_todo.dart deleted file mode 100644 index 54e454954..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/manual_add_todo.dart +++ /dev/null @@ -1,39 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = - AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - /* SNIPPET START */ - Future addTodo(Todo todo) async { - // API 응답은 신경 쓰지 않습니다. - await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - // 그런 다음 로컬 캐시를 수동으로 업데이트할 수 있습니다. 이를 위해서는 이전 상태를 가져와야 합니다. - // 주의: 이전 상태가 여전히 로딩 중이거나 오류 상태일 수 있습니다. - // 이 문제를 우아하게 처리하는 방법은 `this.state` 대신 `this.future`를 읽어서 로딩 상태를 기다리게 하고 - // 상태가 오류 상태인 경우 오류를 발생시키는 것입니다. - final previousState = await future; - - // 그런 다음 새 상태 객체를 생성하여 상태를 업데이트할 수 있습니다. - // 그러면 모든 리스너에게 알림이 전송됩니다. - state = AsyncData([...previousState, todo]); - } -/* SNIPPET END */ -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/mutable_manual_add_todo.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/mutable_manual_add_todo.dart deleted file mode 100644 index aece4d511..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/mutable_manual_add_todo.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - Future addTodo(Todo todo) async { - // API 응답은 신경 쓰지 않습니다. - await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - /* SNIPPET START */ - final previousState = await future; - // 이전 할 일 목록을 변경합니다. (Mutable) - previousState.add(todo); - // 리스너에게 수동으로 알림을 전송합니다. - ref.notifyListeners(); -/* SNIPPET END */ - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/rest_add_todo.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/rest_add_todo.dart deleted file mode 100644 index 392756b3d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/side_effects/raw/rest_add_todo.dart +++ /dev/null @@ -1,39 +0,0 @@ -// ignore_for_file: avoid_print, prefer_final_locals, omit_local_variable_types - -import 'dart:convert'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:http/http.dart' as http; - -import 'todo_list_notifier.dart'; - -final todoListProvider = - AsyncNotifierProvider.autoDispose>( - TodoList.new, -); - -class TodoList extends AutoDisposeAsyncNotifier> { - @override - Future> build() async => [/* ... */]; - - /* SNIPPET START */ - Future addTodo(Todo todo) async { - // POST 요청은 새 애플리케이션 상태와 일치하는 List를 반환합니다. - final response = await http.post( - Uri.https('your_api.com', '/todos'), - headers: {'Content-Type': 'application/json'}, - body: jsonEncode(todo.toJson()), - ); - - // API 응답을 디코딩하여 List로 변환합니다. - List newTodos = (jsonDecode(response.body) as List) - .cast>() - .map(Todo.fromJson) - .toList(); - - // 로컬 캐시를 새 상태와 일치하도록 업데이트합니다. - // 그러면 모든 리스너에게 알림이 전송됩니다. - state = AsyncData(newTodos); - } -/* SNIPPET END */ -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing.mdx index fe268049e..f4b868df7 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing.mdx @@ -3,17 +3,17 @@ title: providers 테스트하기 --- import { AutoSnippet, When } from "../../../../../src/components/CodeSnippet"; -import createContainer from "!!raw-loader!./testing/create_container.dart"; -import unitTest from "!!raw-loader!./testing/unit_test.dart"; -import widgetTest from "!!raw-loader!./testing/widget_test.dart"; -import fullWidgetTest from "!!raw-loader!./testing/full_widget_test.dart"; -import widgetContainerOf from "!!raw-loader!./testing/widget_container_of.dart"; -import providerToMock from "./testing/provider_to_mock"; -import mockProvider from "!!raw-loader!./testing/mock_provider.dart"; -import autoDisposeListen from "!!raw-loader!./testing/auto_dispose_listen.dart"; -import listenProvider from "!!raw-loader!./testing/listen_provider.dart"; -import awaitFuture from "!!raw-loader!./testing/await_future.dart"; -import notifierMock from "./testing/notifier_mock"; +import createContainer from "!!raw-loader!/docs/essentials/testing/create_container.dart"; +import unitTest from "!!raw-loader!/docs/essentials/testing/unit_test.dart"; +import widgetTest from "!!raw-loader!/docs/essentials/testing/widget_test.dart"; +import fullWidgetTest from "!!raw-loader!/docs/essentials/testing/full_widget_test.dart"; +import widgetContainerOf from "!!raw-loader!/docs/essentials/testing/widget_container_of.dart"; +import providerToMock from "/docs/essentials/testing/provider_to_mock"; +import mockProvider from "!!raw-loader!/docs/essentials/testing/mock_provider.dart"; +import autoDisposeListen from "!!raw-loader!/docs/essentials/testing/auto_dispose_listen.dart"; +import listenProvider from "!!raw-loader!/docs/essentials/testing/listen_provider.dart"; +import awaitFuture from "!!raw-loader!/docs/essentials/testing/await_future.dart"; +import notifierMock from "/docs/essentials/testing/notifier_mock"; Riverpod API의 핵심은 provider를 개별적으로 테스트할 수 있는 기능입니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/auto_dispose_listen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/auto_dispose_listen.dart deleted file mode 100644 index f16a2d6c8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/auto_dispose_listen.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = Provider((_) => 'Hello world'); - -void main() { - test('Some description', () { - final container = createContainer(); - /* SNIPPET START */ - final subscription = container.listen(provider, (_, __) {}); - - expect( - // `container.read(provider)`와 동일합니다. - // 그러나 "subscription"이 disposed되지 않는 한 provider는 disposed되지 않습니다. - subscription.read(), - 'Some value', - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/await_future.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/await_future.dart deleted file mode 100644 index 10bc7e238..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/await_future.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = FutureProvider((_) async => 42); - -void main() { - test('Some description', () async { - // 이 테스트에 대한 ProviderContainer를 생성합니다. - // DO NOT: 테스트 간에 ProviderContainer를 공유하지 마세요. - final container = createContainer(); - - /* SNIPPET START */ - // TODO: 컨테이너를 사용하여 애플리케이션을 테스트합니다. - // 기대는 비동기적이므로 "expectLater"를 사용해야 합니다. - await expectLater( - // "provider"대신 "provider.future"를 읽습니다. - // 이는 비동기 provider에서 가능하며, provider의 value로 resolve되는 future를 반환합니다. - container.read(provider.future), - // future가 예상 값으로 resolve되는지 확인할 수 있습니다. - // 또는 오류에 "throwsA"를 사용할 수 있습니다. - completion('some value'), - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/create_container.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/create_container.dart deleted file mode 100644 index c0aab45e6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/create_container.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:riverpod/riverpod.dart'; -import 'package:test/test.dart'; - -/// [ProviderContainer]를 생성하고 -/// 테스트가 끝나면 자동으로 폐기하는 테스트 유틸리티입니다. -ProviderContainer createContainer({ - ProviderContainer? parent, - List overrides = const [], - List? observers, -}) { - // ProviderContainer를 생성하고 선택적으로 매개변수 지정을 허용합니다. - final container = ProviderContainer( - parent: parent, - overrides: overrides, - observers: observers, - ); - - // 테스트가 끝나면 container를 폐기합니다. - addTearDown(container.dispose); - - return container; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/full_widget_test.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/full_widget_test.dart deleted file mode 100644 index 325292aa7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/full_widget_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -final provider = Provider((_) => 'some value'); - -class YourWidgetYouWantToTest extends StatelessWidget { - const YourWidgetYouWantToTest({super.key}); - - @override - Widget build(BuildContext context) => const Placeholder(); -} - -/* SNIPPET START */ -void main() { - testWidgets('Some description', (tester) async { - await tester.pumpWidget( - const ProviderScope(child: YourWidgetYouWantToTest()), - ); - - final element = tester.element(find.byType(YourWidgetYouWantToTest)); - final container = ProviderScope.containerOf(element); - - // TODO providers와 상호작용합니다. - expect( - container.read(provider), - 'some value', - ); - }); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/listen_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/listen_provider.dart deleted file mode 100644 index d2e840d9b..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/listen_provider.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable, avoid_print - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = Provider((_) => 'Hello world'); - -void main() { - test('Some description', () { - final container = createContainer(); - /* SNIPPET START */ - container.listen( - provider, - (previous, next) { - print('The provider changed from $previous to $next'); - }, - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/mock_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/mock_provider.dart deleted file mode 100644 index d939aa2e7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/mock_provider.dart +++ /dev/null @@ -1,45 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'create_container.dart'; -import 'full_widget_test.dart'; -import 'provider_to_mock/raw.dart'; - -void main() { - testWidgets('Some description', (tester) async { - await tester.pumpWidget( - const ProviderScope(child: YourWidgetYouWantToTest()), - ); - /* SNIPPET START */ - // 단위 테스트에서는 이전의 "createContainer" 유틸리티를 재사용합니다. - final container = createContainer( - // 모킹할 provider 목록을 지정할 수 있습니다: - overrides: [ - // 이 경우 "exampleProvider"를 모킹하고 있습니다. - exampleProvider.overrideWith((ref) { - // 이 함수는 provider의 일반적인 초기화 함수입니다. - // 일반적으로 "ref.watch"를 호출하여 초기 상태를 반환하는 곳입니다. - - // 기본값인 "Hello world"를 사용자 정의 값으로 바꾸어 보겠습니다. - // 그러면 `exampleProvider`와 상호 작용하면 이 값이 반환됩니다. - return 'Hello from tests'; - }), - ], - ); - - // ProviderScope를 사용하여 위젯 테스트에서도 동일한 작업을 수행할 수 있습니다: - await tester.pumpWidget( - ProviderScope( - // ProviderScopes에는 정확히 동일한 "overrides" 매개변수가 있습니다. - overrides: [ - // 이전과 동일 - exampleProvider.overrideWith((ref) => 'Hello from tests'), - ], - child: const YourWidgetYouWantToTest(), - ), - ); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/codegen.dart deleted file mode 100644 index ccb009f3f..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/codegen.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: prefer_mixin - -import 'package:mockito/mockito.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() => throw UnimplementedError(); -} - -// Mock 클래스는 notifier가 사용하는 것에 해당하는 Notifier base-class를 서브클래싱해야 합니다. -class MyNotifierMock extends _$MyNotifier with Mock implements MyNotifier {} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/raw.dart deleted file mode 100644 index e7b1c6f0e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/notifier_mock/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: prefer_mixin - -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:mockito/mockito.dart'; - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() => throw UnimplementedError(); -} - -// Your mock needs to subclass the Notifier base-class corresponding -// to whatever your notifier uses -class MyNotifierMock extends Notifier with Mock implements MyNotifier {} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/codegen.dart deleted file mode 100644 index 2aea771eb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/codegen.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -// 이른 초기화된 provider. -@riverpod -Future example(ExampleRef ref) async => 'Hello world'; -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/index.ts deleted file mode 100644 index 9d50c6614..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from '!!raw-loader!./raw.dart'; -import codegen from '!!raw-loader!./codegen.dart'; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/raw.dart deleted file mode 100644 index aad01febe..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/provider_to_mock/raw.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -// An eagerly initialized provider. -final exampleProvider = FutureProvider((ref) async => 'Hello world'); -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/unit_test.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/unit_test.dart deleted file mode 100644 index 06caf0b96..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/unit_test.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_test/flutter_test.dart'; -import 'package:riverpod/riverpod.dart'; - -import 'create_container.dart'; - -final provider = Provider((_) => 42); - -/* SNIPPET START */ -void main() { - test('Some description', () { - // 이 테스트에 대한 ProviderContainer를 생성합니다. - // DO NOT 테스트 간에 ProviderContainer를 공유하지 마세요. - final container = createContainer(); - - // TODO: use the container to test your application. - expect( - container.read(provider), - equals('some value'), - ); - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/widget_container_of.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/widget_container_of.dart deleted file mode 100644 index 61b2ca36b..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/widget_container_of.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'widget_test.dart'; - -void main() { - testWidgets('Some description', (tester) async { - /* SNIPPET START */ - final element = tester.element(find.byType(YourWidgetYouWantToTest)); - final container = ProviderScope.containerOf(element); - /* SNIPPET END */ - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/widget_test.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/widget_test.dart deleted file mode 100644 index b4afc835c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/testing/widget_test.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class YourWidgetYouWantToTest extends StatelessWidget { - const YourWidgetYouWantToTest({super.key}); - - @override - Widget build(BuildContext context) => const Placeholder(); -} - -/* SNIPPET START */ -void main() { - testWidgets('Some description', (tester) async { - await tester.pumpWidget( - const ProviderScope(child: YourWidgetYouWantToTest()), - ); - }); -} -/* SNIPPET END */ diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx index 39db8dcfe..da9d370c8 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync.mdx @@ -7,13 +7,13 @@ import { AutoSnippet, When, } from "../../../../../src/components/CodeSnippet"; -import syncDefinition from "./websockets_sync/sync_definition"; -import streamProvider from "./websockets_sync/stream_provider"; -import syncConsumer from "!!raw-loader!./websockets_sync/sync_consumer.dart"; -import rawUsage from "!!raw-loader!./websockets_sync/raw_usage.dart"; -import pipeChangeNotifier from "!!raw-loader!./websockets_sync/pipe_change_notifier.dart"; -import sharedPipeChangeNotifier from "!!raw-loader!./websockets_sync/shared_pipe_change_notifier.dart"; -import changeNotifierProvider from "!!raw-loader!./websockets_sync/change_notifier_provider.dart"; +import syncDefinition from "/docs/essentials/websockets_sync/sync_definition"; +import streamProvider from "/docs/essentials/websockets_sync/stream_provider"; +import syncConsumer from "!!raw-loader!/docs/essentials/websockets_sync/sync_consumer.dart"; +import rawUsage from "!!raw-loader!/docs/essentials/websockets_sync/raw_usage.dart"; +import pipeChangeNotifier from "!!raw-loader!/docs/essentials/websockets_sync/pipe_change_notifier.dart"; +import sharedPipeChangeNotifier from "!!raw-loader!/docs/essentials/websockets_sync/shared_pipe_change_notifier.dart"; +import changeNotifierProvider from "!!raw-loader!/docs/essentials/websockets_sync/change_notifier_provider.dart"; 지금까지는 `Future`를 생성하는 방법만 다루었습니다. 이는 의도적으로 `Future`가 Riverpod 애플리케이션을 빌드하는 방법의 핵심이기 때문입니다. diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/change_notifier_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/change_notifier_provider.dart deleted file mode 100644 index b285c78d0..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/change_notifier_provider.dart +++ /dev/null @@ -1,11 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final myProvider = ChangeNotifierProvider>((ref) { - // ValueNotifier를 수신하고 처리합니다. - // 그러면 위젯은 이 provider를 "ref.watch"하여 업데이트를 수신할 수 있습니다. - return ValueNotifier(0); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/pipe_change_notifier.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/pipe_change_notifier.dart deleted file mode 100644 index 63c17b4f7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/pipe_change_notifier.dart +++ /dev/null @@ -1,21 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/widgets.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'pipe_change_notifier.g.dart'; - -/* SNIPPET START */ -/// 값이 변경될 때마다 ValueNotifier를 생성하고 리스너를 업데이트하는 provider입니다. -@riverpod -ValueNotifier myListenable(MyListenableRef ref) { - final notifier = ValueNotifier(0); - - // provider가 dispose되면 notifier를 dispose합니다. - ref.onDispose(notifier.dispose); - - // ValueNotifier가 업데이트될 때마다 이 provider의 리스너에게 알립니다. - notifier.addListener(ref.notifyListeners); - - return notifier; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/raw_usage.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/raw_usage.dart deleted file mode 100644 index f5b829c33..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/raw_usage.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'raw_usage.g.dart'; - -/* SNIPPET START */ -@riverpod -Raw> rawStream(RawStreamRef ref) { - // "Raw"는 typedef입니다. "Raw" 생성자로 반환값을 Wrap할 필요가 없습니다. - return const Stream.empty(); -} - -class Consumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // 값이 더 이상 AsyncValue로 변환되지 않고, 생성된 스트림이 그대로 반환됩니다. - Stream stream = ref.watch(rawStreamProvider); - return StreamBuilder( - stream: stream, - builder: (context, snapshot) { - return Text('${snapshot.data}'); - }, - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/shared_pipe_change_notifier.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/shared_pipe_change_notifier.dart deleted file mode 100644 index f22edc35e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/shared_pipe_change_notifier.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: omit_local_variable_types - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'shared_pipe_change_notifier.g.dart'; - -/* SNIPPET START */ -extension on Ref { - // 이전 로직을 Ref 확장(extension)으로 옮길 수 있습니다. - // 이렇게 하면 provider 간에 로직을 재사용할 수 있습니다. - T disposeAndListenChangeNotifier(T notifier) { - onDispose(notifier.dispose); - notifier.addListener(notifyListeners); - // 사용 편의성을 높이기 위해 Notifier을 반환합니다. - return notifier; - } -} - -@riverpod -ValueNotifier myListenable(MyListenableRef ref) { - return ref.disposeAndListenChangeNotifier(ValueNotifier(0)); -} - -@riverpod -ValueNotifier anotherListenable(AnotherListenableRef ref) { - return ref.disposeAndListenChangeNotifier(ValueNotifier(42)); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/codegen.dart deleted file mode 100644 index ca81a540e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/codegen.dart +++ /dev/null @@ -1,34 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -Stream streamExample(StreamExampleRef ref) async* { - // 1초마다 0에서 41 사이의 숫자를 yield합니다. - // 이 값은 Firestore나 GraphQL 등의 스트림으로 대체할 수 있습니다. - for (var i = 0; i < 42; i++) { - yield i; - await Future.delayed(const Duration(seconds: 1)); - } -} - -class Consumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // 스트림을 수신하고 AsyncValue로 변환합니다. - AsyncValue value = ref.watch(streamExampleProvider); - - // 로딩/오류 상태를 처리하고 데이터를 표시하는 데 AsyncValue를 사용할 수 있습니다. - return switch (value) { - AsyncValue(:final error?) => Text('Error: $error'), - AsyncValue(:final valueOrNull?) => Text('$valueOrNull'), - _ => const CircularProgressIndicator(), - }; - } -} -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/index.ts deleted file mode 100644 index 4ee159de8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/raw.dart deleted file mode 100644 index c4beebb71..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/stream_provider/raw.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals, use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final streamExampleProvider = StreamProvider.autoDispose((ref) async* { - // Every 1 second, yield a number from 0 to 41. - // This could be replaced with a Stream from Firestore or GraphQL or anything else. - for (var i = 0; i < 42; i++) { - yield i; - await Future.delayed(const Duration(seconds: 1)); - } -}); - -class Consumer extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // The stream is listened to and converted to an AsyncValue. - AsyncValue value = ref.watch(streamExampleProvider); - - // We can use the AsyncValue to handle loading/error states and show the data. - return switch (value) { - AsyncValue(:final error?) => Text('Error: $error'), - AsyncValue(:final valueOrNull?) => Text('$valueOrNull'), - _ => const CircularProgressIndicator(), - }; - } -} -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_consumer.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_consumer.dart deleted file mode 100644 index 4864c30da..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_consumer.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'sync_definition/raw.dart'; - -void main() { -/* SNIPPET START */ - Consumer( - builder: (context, ref, child) { - // 값은 "AsyncValue"로 래핑되지 않습니다. - int value = ref.watch(synchronousExampleProvider); - - return Text('$value'); - }, - ); -/* SNIPPET END */ -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/codegen.dart deleted file mode 100644 index b18b8f76e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/codegen.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ -@riverpod -int synchronousExample(SynchronousExampleRef ref) { - return 0; -} -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/index.ts b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/index.ts deleted file mode 100644 index 4ee159de8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { raw, codegen }; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/raw.dart deleted file mode 100644 index 9c64294a0..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/essentials/websockets_sync/sync_definition/raw.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ -final synchronousExampleProvider = Provider.autoDispose((ref) { - return 0; -}); -/* SNIPPET END */ \ No newline at end of file diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/family.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/family.dart deleted file mode 100644 index 4d49c552a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/family.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'family.g.dart'; -/* SNIPPET START */ - -@riverpod -int random(RandomRef ref, {required int seed, required int max}) { - return Random(seed).nextInt(max); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/index.tsx deleted file mode 100644 index fa391f61a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./family.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/raw.dart deleted file mode 100644 index 68b84d40d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/family/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'dart:math'; - -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -@immutable -abstract class Equatable { - const Equatable(); - - List get props; -} - -/* SNIPPET START */ -class ParamsType extends Equatable { - const ParamsType({required this.seed, required this.max}); - - final int seed; - final int max; - - @override - List get props => [seed, max]; -} - -final randomProvider = - Provider.family.autoDispose((ref, params) { - return Random(params.seed).nextInt(params.max); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/async_values.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/async_values.dart deleted file mode 100644 index 802a23150..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/async_values.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; -import '../../helpers/json.dart'; - -part 'async_values.g.dart'; - -/* SNIPPET START */ - -@riverpod -Future> itemsApi(ItemsApiRef ref) async { - final client = Dio(); - final result = await client.get>('your-favorite-api'); - final parsed = [...result.data!.map((e) => Item.fromJson(e as Json))]; - return parsed; -} - -@riverpod -List evenItems(EvenItemsRef ref) { - final asyncValue = ref.watch(itemsApiProvider); - if (asyncValue.isReloading) return []; - if (asyncValue.hasError) return const [Item(id: -1)]; - - final items = asyncValue.requireValue; - - return [...items.whereIndexed((index, element) => index.isEven)]; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/index.tsx deleted file mode 100644 index 526f2dffe..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./async_values.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/raw.dart deleted file mode 100644 index 1ca8987ef..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/async_values/raw.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; -import '../../helpers/json.dart'; - -/* SNIPPET START */ - -final itemsApiProvider = FutureProvider.autoDispose((ref) async { - final client = Dio(); - final result = await client.get>('your-favorite-api'); - final parsed = [...result.data!.map((e) => Item.fromJson(e as Json))]; - return parsed; -}); - -final evenItemsProvider = Provider.autoDispose((ref) { - final asyncValue = ref.watch(itemsApiProvider); - if (asyncValue.isLoading) return []; - if (asyncValue.hasError) return const [Item(id: -1)]; - - final items = asyncValue.requireValue; - - return [...items.whereIndexed((index, element) => index.isEven)]; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/auto_dispose.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/auto_dispose.dart deleted file mode 100644 index 9d739eb38..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/auto_dispose.dart +++ /dev/null @@ -1,29 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'auto_dispose.g.dart'; - -/* SNIPPET START */ - -// 코드 생성 시 .autoDispose가 기본값 -@riverpod -int diceRoll(DiceRollRef ref) { - // 이 provider는 .autoDispose이므로 - // 리스닝을 해제하면 현재 노출된 상태가 폐기됩니다. - // 그런 다음 이 provider를 다시 수신할 때마다 - // 새로운 주사위를 굴려서 다시 노출합니다. - final dice = Random().nextInt(10); - return dice; -} - -@riverpod -int cachedDiceRoll(CachedDiceRollRef ref) { - final coin = Random().nextInt(10); - if (coin > 5) throw Exception('Way too large.'); - // 위의 조건은 실패할 수 있습니다; - // 그렇지 않은 경우, 다음 명령어는 아무도 더 이상 수신하지 않더라도 - // 캐시된 상태를 유지하도록 provider에게 지시합니다. - ref.keepAlive(); - return coin; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/index.tsx deleted file mode 100644 index 6c57cfffd..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./auto_dispose.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/raw.dart deleted file mode 100644 index d5961ad90..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/auto_dispose/raw.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ - -final diceRollProvider = Provider.autoDispose((ref) { - // Since this provider is .autoDispose, un-listening to it will dispose - // its current exposed state. - // Then, whenever this provider is listened to again, - // a new dice will be rolled and exposed again. - final dice = Random().nextInt(10); - return dice.isEven; -}); - -final cachedDiceRollProvider = Provider.autoDispose((ref) { - final coin = Random().nextInt(10); - if (coin > 5) throw Exception('Way too large.'); - // The above condition might fail; - // If it doesn't, the following instruction tells the Provider - // to keep its cached state, *even when no one listens to it anymore*. - ref.keepAlive(); - return coin.isEven; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/combine.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/combine.dart deleted file mode 100644 index ecd1915da..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/combine.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'combine.g.dart'; - -/* SNIPPET START */ - -@riverpod -int number(NumberRef ref) { - return Random().nextInt(10); -} - -@riverpod -int doubled(DoubledRef ref) { - final number = ref.watch(numberProvider); - - return number * 2; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/index.tsx deleted file mode 100644 index 2ff7dfbaa..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./combine.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/raw.dart deleted file mode 100644 index ad33636e7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/combine/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ - -final numberProvider = Provider.autoDispose((ref) { - return Random().nextInt(10); -}); - -final doubledProvider = Provider.autoDispose((ref) { - final number = ref.watch(numberProvider); - - return number * 2; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx index a8e75cd4f..46f970159 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/motivation.mdx @@ -5,12 +5,12 @@ title: 동기부여(Motivation) import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import sameType from "./same_type"; -import combine from "./combine"; -import asyncValues from "./async_values"; -import autoDispose from "./auto_dispose"; -import override from "./override"; -import sideEffects from "./side_effects"; +import sameType from "/docs/from_provider/motivation/same_type"; +import combine from "/docs/from_provider/motivation/combine"; +import asyncValues from "/docs/from_provider/motivation/async_values"; +import autoDispose from "/docs/from_provider/motivation/auto_dispose"; +import override from "/docs/from_provider/motivation/override"; +import sideEffects from "/docs/from_provider/motivation/side_effects"; import { trimSnippet, AutoSnippet, diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/index.tsx deleted file mode 100644 index 43ec56b51..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./override.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/override.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/override.dart deleted file mode 100644 index 860020903..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/override.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../combine/combine.dart'; - -/* SNIPPET START */ - -void main() { - test('it doubles the value correctly', () async { - final container = ProviderContainer( - overrides: [numberProvider.overrideWith((ref) => 9)], - ); - final doubled = container.read(doubledProvider); - expect(doubled, 9 * 2); - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/raw.dart deleted file mode 100644 index 860020903..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/override/raw.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../combine/combine.dart'; - -/* SNIPPET START */ - -void main() { - test('it doubles the value correctly', () async { - final container = ProviderContainer( - overrides: [numberProvider.overrideWith((ref) => 9)], - ); - final doubled = container.read(doubledProvider); - expect(doubled, 9 * 2); - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/index.tsx deleted file mode 100644 index 8569e8316..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./same_type.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/raw.dart deleted file mode 100644 index dacfe9b9d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; - -/* SNIPPET START */ - -final itemsProvider = Provider.autoDispose( - (ref) => [], // ... -); - -final evenItemsProvider = Provider.autoDispose((ref) { - final items = ref.watch(itemsProvider); - return [...items.whereIndexed((index, element) => index.isEven)]; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/same_type.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/same_type.dart deleted file mode 100644 index 94a4ab086..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/same_type/same_type.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../helpers/item.dart'; - -part 'same_type.g.dart'; - -/* SNIPPET START */ - -@riverpod -List items(ItemsRef ref) { - return []; // ... -} - -@riverpod -List evenItems(EvenItemsRef ref) { - final items = ref.watch(itemsProvider); - return [...items.whereIndexed((index, element) => index.isEven)]; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/index.tsx deleted file mode 100644 index f4797a94f..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./side_effects.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/raw.dart deleted file mode 100644 index 61f016870..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/raw.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../auto_dispose/auto_dispose.dart'; - -/* SNIPPET START */ - -class DiceRollWidget extends ConsumerWidget { - const DiceRollWidget({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(diceRollProvider, (previous, next) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Dice roll! We got: $next')), - ); - }); - return TextButton.icon( - onPressed: () => ref.invalidate(diceRollProvider), - icon: const Icon(Icons.casino), - label: const Text('Roll a dice'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/side_effects.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/side_effects.dart deleted file mode 100644 index 61f016870..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/motivation/side_effects/side_effects.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../auto_dispose/auto_dispose.dart'; - -/* SNIPPET START */ - -class DiceRollWidget extends ConsumerWidget { - const DiceRollWidget({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - ref.listen(diceRollProvider, (previous, next) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Dice roll! We got: $next')), - ); - }); - return TextButton.icon( - onPressed: () => ref.invalidate(diceRollProvider), - icon: const Icon(Icons.casino), - label: const Text('Roll a dice'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx index 16380ac37..38c7a36fd 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/from_provider/provider_vs_riverpod.mdx @@ -5,7 +5,7 @@ title: Provider vs Riverpod import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import family from "./family"; +import family from "/docs/from_provider/family"; import { trimSnippet, AutoSnippet, diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx index 68ba4fe88..5c70386f3 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started.mdx @@ -8,9 +8,9 @@ import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; import pubspec from "./getting_started/pubspec"; -import dartHelloWorld from "./getting_started/dart_hello_world"; +import dartHelloWorld from "/docs/introduction/getting_started/dart_hello_world"; import pubadd from "./getting_started/pub_add"; -import helloWorld from "./getting_started/hello_world"; +import helloWorld from "/docs/introduction/getting_started/hello_world"; import dartPubspec from "./getting_started/dart_pubspec"; import dartPubadd from "./getting_started/dart_pub_add"; import { diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/index.tsx deleted file mode 100644 index 898aa0914..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./main.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/main.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/main.dart deleted file mode 100644 index 89bbd92dc..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/main.dart +++ /dev/null @@ -1,25 +0,0 @@ -// ignore_for_file: avoid_print - -/* SNIPPET START */ - -import 'package:riverpod/riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -// 값(여기서는 "Hello world")을 저장할 "provider"를 생성합니다. -// provider를 이용하면, 노출된 값을 모의(Mock)하거나 오버라이드(override)할 수 있습니다. -@riverpod -String helloWorld(HelloWorldRef ref) { - return 'Hello world'; -} - -void main() { - // 이 객체는 providers의 상태가 저장되는 곳입니다. - final container = ProviderContainer(); - - // "container" 덕분에 provider를 읽을 수 있습니다. - final value = container.read(helloWorldProvider); - - print(value); // Hello world -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/raw.dart deleted file mode 100644 index 445bc0a9c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/dart_hello_world/raw.dart +++ /dev/null @@ -1,19 +0,0 @@ -// ignore_for_file: avoid_print - -/* SNIPPET START */ - -import 'package:riverpod/riverpod.dart'; - -// We create a "provider", which will store a value (here "Hello world"). -// By using a provider, this allows us to mock/override the value exposed. -final helloWorldProvider = Provider((_) => 'Hello world'); - -void main() { - // This object is where the state of our providers will be stored. - final container = ProviderContainer(); - - // Thanks to "container", we can read our provider. - final value = container.read(helloWorldProvider); - - print(value); // Hello world -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/hooks_codegen/main.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/hooks_codegen/main.dart deleted file mode 100644 index cd94bb4ad..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/hooks_codegen/main.dart +++ /dev/null @@ -1,48 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -// 값을 저장할 “provider"를 생성합니다(여기서는 "Hello world"). -// 프로바이더를 사용하면, 노출된 값을 모의(Mock)하거나 재정의(Override)할 수 있습니다. -@riverpod -String helloWorld(HelloWorldRef ref) { - return 'Hello world'; -} - -void main() { - runApp( - // 위젯이 프로바이더를 읽을 수 있도록 하려면, - // 전체 애플리케이션을 "ProviderScope" 위젯으로 감싸야 합니다. - // 여기에 프로바이더의 상태가 저장됩니다. - ProviderScope( - child: MyApp(), - ), - ); -} - -// HookWidget 대신 Riverpod에서 제공되는 HookConsumerWidget을 확장합니다. -class MyApp extends HookConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // HookConsumerWidget 내부에서 Hook을 사용할 수 있습니다. - final counter = useState(0); - - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text('$value ${counter.value}'), - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/index.tsx deleted file mode 100644 index 3f10c2a94..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import raw_hooks from "!!raw-loader!./raw_hooks.dart"; -import codegen from "!!raw-loader!./main.dart"; -import hooksCodegen from "!!raw-loader!./hooks_codegen/main.dart"; - -export default { - raw, - hooks: raw_hooks, - codegen, - hooksCodegen: hooksCodegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/main.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/main.dart deleted file mode 100644 index 77de400be..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/main.dart +++ /dev/null @@ -1,44 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'main.g.dart'; - -// 값을 저장할 “provider"를 생성합니다(여기서는 "Hello world"). -// 프로바이더를 사용하면, 노출된 값을 모의(Mock)하거나 재정의(Override)할 수 있습니다. -@riverpod -String helloWorld(HelloWorldRef ref) { - return 'Hello world'; -} - -void main() { - runApp( - // 위젯이 프로바이더를 읽을 수 있도록 하려면, - // 전체 애플리케이션을 "ProviderScope" 위젯으로 감싸야 합니다. - // 여기에 프로바이더의 상태가 저장됩니다. - ProviderScope( - child: MyApp(), - ), - ); -} - -// StatelessWidget 대신 Riverpod에서 제공되는 ConsumerWidget을 확장합니다. -class MyApp extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text(value), - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw.dart deleted file mode 100644 index e1926b759..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw.dart +++ /dev/null @@ -1,38 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -// We create a "provider", which will store a value (here "Hello world"). -// By using a provider, this allows us to mock/override the value exposed. -final helloWorldProvider = Provider((_) => 'Hello world'); - -void main() { - runApp( - // For widgets to be able to read providers, we need to wrap the entire - // application in a "ProviderScope" widget. - // This is where the state of our providers will be stored. - ProviderScope( - child: MyApp(), - ), - ); -} - -// Extend ConsumerWidget instead of StatelessWidget, which is exposed by Riverpod -class MyApp extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text(value), - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw_hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw_hooks.dart deleted file mode 100644 index e65ef60c6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/getting_started/hello_world/raw_hooks.dart +++ /dev/null @@ -1,42 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -/* SNIPPET START */ - -import 'package:flutter/material.dart'; -import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -// We create a "provider", which will store a value (here "Hello world"). -// By using a provider, this allows us to mock/override the value exposed. -final helloWorldProvider = Provider((_) => 'Hello world'); - -void main() { - runApp( - // For widgets to be able to read providers, we need to wrap the entire - // application in a "ProviderScope" widget. - // This is where the state of our providers will be stored. - ProviderScope( - child: MyApp(), - ), - ); -} - -// Extend HookConsumerWidget instead of HookWidget, which is exposed by Riverpod -class MyApp extends HookConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - // We can use hooks inside HookConsumerWidget - final counter = useState(0); - - final String value = ref.watch(helloWorldProvider); - - return MaterialApp( - home: Scaffold( - appBar: AppBar(title: const Text('Example')), - body: Center( - child: Text('$value ${counter.value}'), - ), - ), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx index cfd6b051e..db1d32adc 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod.mdx @@ -3,7 +3,7 @@ title: 왜 Riverpod인가? version: 1 --- -import whyRiverpod from "./why_riverpod"; +import whyRiverpod from "/docs/introduction/why_riverpod"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; ## Riverpod 이란? diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/codegen.dart deleted file mode 100644 index 83e1ff5b6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/codegen.dart +++ /dev/null @@ -1,31 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -class Package { - static Package fromJson(dynamic json) { - throw UnimplementedError(); - } -} - -/* SNIPPET START */ - -// Fetches the list of packages from pub.dev -@riverpod -Future> fetchPackages( - FetchPackagesRef ref, { - required int page, - String search = '', -}) async { - final dio = Dio(); - // Fetch an API. Here we're using package:dio, but we could use anything else. - final response = await dio.get>( - 'https://pub.dartlang.org/api/search?page=$page&q=${Uri.encodeQueryComponent(search)}', - ); - - // Decode the JSON response into a Dart class. - return response.data?.map(Package.fromJson).toList() ?? const []; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/raw.dart deleted file mode 100644 index 131981f7b..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/introduction/why_riverpod/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, omit_local_variable_types - -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Package { - static Package fromJson(dynamic json) { - throw UnimplementedError(); - } -} - -/* SNIPPET START */ - -// Fetches the list of packages from pub.dev -final fetchPackagesProvider = FutureProvider.autoDispose - .family, ({int page, String? search})>((ref, params) async { - final page = params.page; - final search = params.search ?? ''; - final dio = Dio(); - // Fetch an API. Here we're using package:dio, but we could use anything else. - final response = await dio.get>( - 'https://pub.dartlang.org/api/search?page=$page&q=${Uri.encodeQueryComponent(search)}', - ); - - // Decode the JSON response into a Dart class. - return response.data?.map(Package.fromJson).toList() ?? const []; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx index cc6683e73..b2f890594 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier.mdx @@ -2,10 +2,10 @@ title: "`ChangeNotifier`에서" --- -import old from "!!raw-loader!./from_change_notifier/old.dart"; -import declaration from "./from_change_notifier/declaration"; -import initialization from "./from_change_notifier/initialization"; -import migrated from "./from_change_notifier/migrated"; +import old from "!!raw-loader!/docs/migration/from_change_notifier/old.dart"; +import declaration from "/docs/migration/from_change_notifier/declaration"; +import initialization from "/docs/migration/from_change_notifier/initialization"; +import migrated from "/docs/migration/from_change_notifier/migrated"; import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/declaration.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/declaration.dart deleted file mode 100644 index b3ca06ef2..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/declaration.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'declaration.g.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - FutureOr> build() { - // TODO ... - return []; - } - - Future addTodo(Todo todo) async { - // TODO - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/index.tsx deleted file mode 100644 index 1ad659c31..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./declaration.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/raw.dart deleted file mode 100644 index c7485bbba..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/declaration/raw.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends AutoDisposeAsyncNotifier> { - @override - FutureOr> build() { - // TODO ... - return []; - } - - Future addTodo(Todo todo) async { - // TODO - } -} - -final myNotifierProvider = AsyncNotifierProvider.autoDispose(MyNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/index.tsx deleted file mode 100644 index 3b3fbd2cb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./initialization.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/initialization.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/initialization.dart deleted file mode 100644 index 4da805e13..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/initialization.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'initialization.g.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - return [...json.map(Todo.fromJson)]; - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/raw.dart deleted file mode 100644 index 24ab265f7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/initialization/raw.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends AutoDisposeAsyncNotifier> { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - return [...json.map(Todo.fromJson)]; - } -} - -final myNotifierProvider = AsyncNotifierProvider.autoDispose(MyNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/index.tsx deleted file mode 100644 index 075bfbdf5..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./migrated.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/migrated.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/migrated.dart deleted file mode 100644 index b8f4ba829..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/migrated.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'migrated.g.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - Future addTodo(Todo todo) async { - // optional: state = const AsyncLoading(); - final json = await http.post('api/todos'); - final newTodos = [...json.map(Todo.fromJson)]; - state = AsyncData(newTodos); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/raw.dart deleted file mode 100644 index 8572db71d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/migrated/raw.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class MyNotifier extends AutoDisposeAsyncNotifier> { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - Future addTodo(Todo todo) async { - // optional: state = const AsyncLoading(); - final json = await http.post('api/todos'); - final newTodos = [...json.map(Todo.fromJson)]; - state = AsyncData(newTodos); - } -} - -final myNotifierProvider = AsyncNotifierProvider.autoDispose(MyNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/old.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/old.dart deleted file mode 100644 index 4e65e823d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_change_notifier/old.dart +++ /dev/null @@ -1,60 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Todo { - const Todo(this.id); - Todo.fromJson(Object obj) : id = 0; - - final int id; -} - -class Http { - Future> get(String str) async => [str]; - Future> post(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -class MyChangeNotifier extends ChangeNotifier { - MyChangeNotifier() { - _init(); - } - List todos = []; - bool isLoading = true; - bool hasError = false; - - Future _init() async { - try { - final json = await http.get('api/todos'); - todos = [...json.map(Todo.fromJson)]; - } on Exception { - hasError = true; - } finally { - isLoading = false; - notifyListeners(); - } - } - - Future addTodo(int id) async { - isLoading = true; - notifyListeners(); - - try { - final json = await http.post('api/todos'); - todos = [...json.map(Todo.fromJson)]; - hasError = false; - } on Exception { - hasError = true; - } finally { - isLoading = false; - notifyListeners(); - } - } -} - -final myChangeProvider = ChangeNotifierProvider((ref) { - return MyChangeNotifier(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx index 881d10bb4..20b245302 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier.mdx @@ -2,21 +2,21 @@ title: "`StateNotifier`에서" --- -import buildInit from "./from_state_notifier/build_init"; -import buildInitOld from "!!raw-loader!./from_state_notifier/build_init_old.dart"; -import consumersDontChange from "!!raw-loader!./from_state_notifier/consumers_dont_change.dart"; -import familyAndDispose from "./from_state_notifier/family_and_dispose"; -import familyAndDisposeOld from "!!raw-loader!./from_state_notifier/family_and_dispose_old.dart"; -import asyncNotifier from "./from_state_notifier/async_notifier"; -import asyncNotifierOld from "!!raw-loader!./from_state_notifier/async_notifier_old.dart"; -import addListener from "./from_state_notifier/add_listener"; -import addListenerOld from "!!raw-loader!./from_state_notifier/add_listener_old.dart"; -import fromStateProvider from "./from_state_notifier/from_state_provider"; -import fromStateProviderOld from "!!raw-loader!./from_state_notifier/from_state_provider_old.dart"; -import oldLifecycles from "./from_state_notifier/old_lifecycles"; -import oldLifecyclesOld from "!!raw-loader!./from_state_notifier/old_lifecycles_old.dart"; -import oldLifecyclesFinal from "./from_state_notifier/old_lifecycles_final"; -import obtainNotifierOnTests from "!!raw-loader!./from_state_notifier/obtain_notifier_on_tests.dart"; +import buildInit from "/docs/migration/from_state_notifier/build_init"; +import buildInitOld from "!!raw-loader!/docs/migration/from_state_notifier/build_init_old.dart"; +import consumersDontChange from "!!raw-loader!/docs/migration/from_state_notifier/consumers_dont_change.dart"; +import familyAndDispose from "/docs/migration/from_state_notifier/family_and_dispose"; +import familyAndDisposeOld from "!!raw-loader!/docs/migration/from_state_notifier/family_and_dispose_old.dart"; +import asyncNotifier from "/docs/migration/from_state_notifier/async_notifier"; +import asyncNotifierOld from "!!raw-loader!/docs/migration/from_state_notifier/async_notifier_old.dart"; +import addListener from "/docs/migration/from_state_notifier/add_listener"; +import addListenerOld from "!!raw-loader!/docs/migration/from_state_notifier/add_listener_old.dart"; +import fromStateProvider from "/docs/migration/from_state_notifier/from_state_provider"; +import fromStateProviderOld from "!!raw-loader!/docs/migration/from_state_notifier/from_state_provider_old.dart"; +import oldLifecycles from "/docs/migration/from_state_notifier/old_lifecycles"; +import oldLifecyclesOld from "!!raw-loader!/docs/migration/from_state_notifier/old_lifecycles_old.dart"; +import oldLifecyclesFinal from "/docs/migration/from_state_notifier/old_lifecycles_final"; +import obtainNotifierOnTests from "!!raw-loader!/docs/migration/from_state_notifier/obtain_notifier_on_tests.dart"; import { Link } from "../../../../../src/components/Link"; import { AutoSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/add_listener.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/add_listener.dart deleted file mode 100644 index ead1c72d8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/add_listener.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter/material.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'add_listener.g.dart'; - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - ref.listenSelf((_, next) => debugPrint('$next')); - return 0; - } - - void add() => state++; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/index.tsx deleted file mode 100644 index 6d7ac6d37..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./add_listener.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/raw.dart deleted file mode 100644 index e25b4a181..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener/raw.dart +++ /dev/null @@ -1,17 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter/material.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() { - ref.listenSelf((_, next) => debugPrint('$next')); - return 0; - } - - void add() => state++; -} - -final myNotifierProvider = NotifierProvider(MyNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener_old.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener_old.dart deleted file mode 100644 index 4950216c6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/add_listener_old.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -class MyNotifier extends StateNotifier { - MyNotifier() : super(0); - - void add() => state++; -} - -final myNotifierProvider = StateNotifierProvider((ref) { - final notifier = MyNotifier(); - - final cleanup = notifier.addListener((state) => debugPrint('$state')); - ref.onDispose(cleanup); - - // 또는, 이와 동일하게: - // final listener = notifier.stream.listen((event) => debugPrint('$event')); - // ref.onDispose(listener.cancel); - - return notifier; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/async_notifier.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/async_notifier.dart deleted file mode 100644 index 5ead76378..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/async_notifier.dart +++ /dev/null @@ -1,28 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'async_notifier.g.dart'; - -class Todo { - Todo.fromJson(Object obj); -} - -class Http { - Future> get(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -@riverpod -class AsyncTodosNotifier extends _$AsyncTodosNotifier { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - // ... -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/index.tsx deleted file mode 100644 index a0ff513c3..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./async_notifier.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/raw.dart deleted file mode 100644 index 52da61d76..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier/raw.dart +++ /dev/null @@ -1,29 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -class Todo { - Todo.fromJson(Object obj); -} - -class Http { - Future> get(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -class AsyncTodosNotifier extends AsyncNotifier> { - @override - FutureOr> build() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - } - - // ... -} - -final asyncTodosNotifier = AsyncNotifierProvider>( - AsyncTodosNotifier.new, -); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier_old.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier_old.dart deleted file mode 100644 index 50d7f4aed..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/async_notifier_old.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: avoid_print, avoid_unused_constructor_parameters - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class Todo { - Todo.fromJson(Object obj); -} - -class Http { - Future> get(String str) async => [str]; -} - -final http = Http(); - -/* SNIPPET START */ -class AsyncTodosNotifier extends StateNotifier>> { - AsyncTodosNotifier() : super(const AsyncLoading()) { - _postInit(); - } - - Future _postInit() async { - state = await AsyncValue.guard(() async { - final json = await http.get('api/todos'); - - return [...json.map(Todo.fromJson)]; - }); - } - - // ... -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/build_init.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/build_init.dart deleted file mode 100644 index 3e2303b7a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/build_init.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'build_init.g.dart'; - -/* SNIPPET START */ -@riverpod -class CounterNotifier extends _$CounterNotifier { - @override - int build() => 0; - - void increment() => state++; - void decrement() => state++; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/index.tsx deleted file mode 100644 index 276a143ac..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./build_init.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/raw.dart deleted file mode 100644 index 0ba8eebed..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init/raw.dart +++ /dev/null @@ -1,15 +0,0 @@ -// ignore_for_file: avoid_print - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -class CounterNotifier extends Notifier { - @override - int build() => 0; - - void increment() => state++; - void decrement() => state++; -} - -final counterNotifierProvider = NotifierProvider(CounterNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init_old.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init_old.dart deleted file mode 100644 index 82a8c54bd..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/build_init_old.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -/* SNIPPET START */ -class CounterNotifier extends StateNotifier { - CounterNotifier() : super(0); - - void increment() => state++; - void decrement() => state++; -} - -final counterNotifierProvider = StateNotifierProvider((ref) { - return CounterNotifier(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/consumers_dont_change.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/consumers_dont_change.dart deleted file mode 100644 index 6a964a5a6..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/consumers_dont_change.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class CounterNotifier extends StateNotifier { - CounterNotifier() : super(0); - - void increment() => state++; - void decrement() => state++; -} - -final counterNotifierProvider = StateNotifierProvider((ref) { - return CounterNotifier(); -}); - -/* SNIPPET START */ -class SomeConsumer extends ConsumerWidget { - const SomeConsumer({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - /* highlight-start */ - final counter = ref.watch(counterNotifierProvider); - /* highlight-end */ - return Column( - children: [ - Text("You've counted up until $counter, good job!"), - TextButton( - /* highlight-start */ - onPressed: ref.read(counterNotifierProvider.notifier).increment, - /* highlight-end */ - child: const Text('Count even more!'), - ) - ], - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/family_and_dispose.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/family_and_dispose.dart deleted file mode 100644 index 9a695614c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/family_and_dispose.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: unnecessary_this - -import 'dart:math'; - -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -part 'family_and_dispose.g.dart'; - -/* SNIPPET START */ -@riverpod -class BugsEncounteredNotifier extends _$BugsEncounteredNotifier { - @override - FutureOr build(String featureId) { - return 99; - } - - Future fix(int amount) async { - final old = await future; - final result = await ref.read(taskTrackerProvider).fix(id: this.featureId, fixed: amount); - state = AsyncData(max(old - result, 0)); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/index.tsx deleted file mode 100644 index 0780f2135..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./family_and_dispose.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/raw.dart deleted file mode 100644 index 8dfce9447..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -// ignore_for_file: unnecessary_this - -import 'dart:math'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -/* SNIPPET START */ -class BugsEncounteredNotifier extends AutoDisposeFamilyAsyncNotifier { - @override - FutureOr build(String featureId) { - return 99; - } - - Future fix(int amount) async { - final old = await future; - final result = await ref.read(taskTrackerProvider).fix(id: this.arg, fixed: amount); - state = AsyncData(max(old - result, 0)); - } -} - -final bugsEncounteredNotifierProvider = - AsyncNotifierProvider.family.autoDispose( - BugsEncounteredNotifier.new, -); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose_old.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose_old.dart deleted file mode 100644 index 28f93a65c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/family_and_dispose_old.dart +++ /dev/null @@ -1,30 +0,0 @@ -// ignore_for_file: unnecessary_this - -import 'dart:math'; - -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../utils.dart'; - -/* SNIPPET START */ -class BugsEncounteredNotifier extends StateNotifier> { - BugsEncounteredNotifier({ - required this.ref, - required this.featureId, - }) : super(const AsyncData(99)); - final String featureId; - final Ref ref; - - Future fix(int amount) async { - state = await AsyncValue.guard(() async { - final old = state.requireValue; - final result = await ref.read(taskTrackerProvider).fix(id: featureId, fixed: amount); - return max(old - result, 0); - }); - } -} - -final bugsEncounteredNotifierProvider = - StateNotifierProvider.family.autoDispose((ref, id) { - return BugsEncounteredNotifier(ref: ref, featureId: id); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/from_state_provider.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/from_state_provider.dart deleted file mode 100644 index 2c71d6144..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/from_state_provider.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'from_state_provider.g.dart'; - -/* SNIPPET START */ -@riverpod -class CounterNotifier extends _$CounterNotifier { - @override - int build() => 0; - - @override - set state(int newState) => super.state = newState; - int update(int Function(int state) cb) => state = cb(state); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/index.tsx deleted file mode 100644 index f59794999..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./from_state_provider.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/raw.dart deleted file mode 100644 index 97e4564f3..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -/* SNIPPET START */ -class CounterNotifier extends Notifier { - @override - int build() => 0; - - @override - set state(int newState) => super.state = newState; - int update(int Function(int state) cb) => state = cb(state); -} - -final counterNotifierProvider = NotifierProvider(CounterNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider_old.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider_old.dart deleted file mode 100644 index 246f44a0c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/from_state_provider_old.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ -final counterProvider = StateProvider((ref) { - return 0; -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/obtain_notifier_on_tests.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/obtain_notifier_on_tests.dart deleted file mode 100644 index 1627be9e7..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/obtain_notifier_on_tests.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: unused_local_variable,omit_local_variable_types - -import 'package:flutter_test/flutter_test.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class MyNotifier extends AutoDisposeNotifier { - @override - int build() { - return 0; - } -} - -final myNotifierProvider = NotifierProvider.autoDispose(MyNotifier.new); - -/* SNIPPET START */ -void main(List args) { - test('my test', () { - final container = ProviderContainer(); - addTearDown(container.dispose); - - // notifier 획득 - /* highlight-start */ - final AutoDisposeNotifier notifier = container.read(myNotifierProvider.notifier); - /* highlight-end */ - - // 거기서 노출되는 상태 획득 - /* highlight-start */ - final int state = container.read(myNotifierProvider); - /* highlight-end */ - - // TODO write your tests - }); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/index.tsx deleted file mode 100644 index 9b77f551a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./old_lifecycles.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/old_lifecycles.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/old_lifecycles.dart deleted file mode 100644 index ffeed1c3e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/old_lifecycles.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -part 'old_lifecycles.g.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - // 한 곳에서 코드를 읽고 쓰면 됩니다. - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - await ref.read(repositoryProvider).update(state + 1); - // `mounted`는 더 이상 없습니다! - state++; //throw 될 수 있습니다 - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/raw.dart deleted file mode 100644 index 691d71af9..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles/raw.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() { - // Just read/write the code here, in one place - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - await ref.read(repositoryProvider).update(state + 1); - // `mounted` is no more! - state++; // This might throw. - } -} - -final myNotifierProvider = NotifierProvider(MyNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/index.tsx deleted file mode 100644 index 9823b1564..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./old_lifecycles_final.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/old_lifecycles_final.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/old_lifecycles_final.dart deleted file mode 100644 index 798fce7d8..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/old_lifecycles_final.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -part 'old_lifecycles_final.g.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -@riverpod -class MyNotifier extends _$MyNotifier { - @override - int build() { - // 한 곳에서 코드를 읽고 쓰면 됩니다. - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - final cancelToken = CancelToken(); - ref.onDispose(cancelToken.cancel); - await ref.read(repositoryProvider).update(state + 1, token: cancelToken); - // `cancelToken.cancel`이 호출되면 커스텀 예외가 발생합니다. - state++; - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/raw.dart deleted file mode 100644 index 94814a191..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_final/raw.dart +++ /dev/null @@ -1,36 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../../utils.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -class MyNotifier extends Notifier { - @override - int build() { - // Just read/write the code here, in one place - final period = ref.watch(durationProvider); - final timer = Timer.periodic(period, (t) => update()); - ref.onDispose(timer.cancel); - - return 0; - } - - Future update() async { - final cancelToken = CancelToken(); - ref.onDispose(cancelToken.cancel); - await ref.read(repositoryProvider).update(state + 1, token: cancelToken); - state++; - } -} - -final myNotifierProvider = NotifierProvider(MyNotifier.new); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_old.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_old.dart deleted file mode 100644 index 717637c81..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/migration/from_state_notifier/old_lifecycles_old.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'dart:async'; - -import 'package:dio/dio.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../utils.dart'; - -final repositoryProvider = Provider<_MyRepo>((ref) { - return _MyRepo(); -}); - -class _MyRepo { - Future update(int i, {CancelToken? token}) async {} -} - -/* SNIPPET START */ -class MyNotifier extends StateNotifier { - MyNotifier(this.ref, this.period) : super(0) { - // 1 초기화로직 - _timer = Timer.periodic(period, (t) => update()); // 2 초기화시 부가작업 - } - final Duration period; - final Ref ref; - late final Timer _timer; - - Future update() async { - await ref.read(repositoryProvider).update(state + 1); // 3 변이(mutation) - if (mounted) state++; // 4 마운트된 속성 확인 - } - - @override - void dispose() { - _timer.cancel(); // 5 커스텀 폐기(dispose) 로직 - super.dispose(); - } -} - -final myNotifierProvider = StateNotifierProvider((ref) { - // 6 provider 정의 - final period = ref.watch(durationProvider); // 7 리액티브 종속성 로직 - return MyNotifier(ref, period); // 8 `ref`로 연결(pipe down) -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider.mdx index 6f114320a..b32ad0964 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider.mdx @@ -3,8 +3,8 @@ title: FutureProvider version: 1 --- -import configProvider from "./future_provider/config_provider"; -import configConsumer from "./future_provider/config_consumer"; +import configProvider from "/docs/providers/future_provider/config_provider"; +import configConsumer from "/docs/providers/future_provider/config_consumer"; import { AutoSnippet} from "../../../../../src/components/CodeSnippet"; :::caution diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/codegen.dart deleted file mode 100644 index a96f35e72..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/codegen.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../config_provider/codegen.dart'; - -/* SNIPPET START */ - -Widget build(BuildContext context, WidgetRef ref) { - final config = ref.watch(fetchConfigurationProvider); - - return switch (config) { - AsyncError(:final error) => Text('Error: $error'), - AsyncData(:final value) => Text(value.host), - _ => const CircularProgressIndicator(), - }; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks.dart deleted file mode 100644 index 44d9b4df9..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; -import '../config_provider/raw.dart'; - -/* SNIPPET START */ - -class MyConfiguration extends HookConsumerWidget { - const MyConfiguration({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final config = ref.watch(configProvider); - return Scaffold( - body: switch (config) { - AsyncError(:final error) => Center(child: Text('Error: $error')), - AsyncData(:final value) => Center(child: Text(value.host)), - _ => const Center(child: CircularProgressIndicator()), - }, - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks_codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks_codegen.dart deleted file mode 100644 index ade0628fd..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/hooks_codegen.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -import '../config_provider/codegen.dart'; - -/* SNIPPET START */ - -class MyConfiguration extends HookConsumerWidget { - const MyConfiguration({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - final config = ref.watch(fetchConfigurationProvider); - return Scaffold( - body: switch (config) { - AsyncError(:final error) => Center(child: Text('Error: $error')), - AsyncData(:final value) => Center(child: Text(value.host)), - _ => const Center(child: CircularProgressIndicator()), - }, - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/index.tsx deleted file mode 100644 index 8e7b2a443..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; -import hooks from "!!raw-loader!./hooks.dart"; -import hooksCodegen from "!!raw-loader!./hooks_codegen.dart" - -export default { - raw, - hooks, - codegen, - hooksCodegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/raw.dart deleted file mode 100644 index 9d39f3bcd..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_consumer/raw.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../config_provider/raw.dart'; - -/* SNIPPET START */ - -Widget build(BuildContext context, WidgetRef ref) { - AsyncValue config = ref.watch(configProvider); - - return switch (config) { - AsyncData(:final value) => Text(value.host), - AsyncError(:final error) => Text('Error: $error'), - _ => const CircularProgressIndicator(), - }; -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/codegen.dart deleted file mode 100644 index 2aa87a29e..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/codegen.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'dart:convert'; - -import 'package:flutter/services.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; -part 'codegen.g.dart'; -class Configuration { - Configuration.fromJson(Map json); - final String host = ''; -} - -/* SNIPPET START */ - -@riverpod -Future fetchConfiguration(FetchConfigurationRef ref) async { - final content = json.decode( - await rootBundle.loadString('assets/configurations.json'), - ) as Map; - - return Configuration.fromJson(content); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/raw.dart deleted file mode 100644 index 62d7926ca..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/future_provider/config_provider/raw.dart +++ /dev/null @@ -1,22 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'dart:convert'; - -import 'package:flutter/services.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Configuration { - Configuration.fromJson(Map json); - - final String host = ''; -} - -/* SNIPPET START */ - -final configProvider = FutureProvider((ref) async { - final content = json.decode( - await rootBundle.loadString('assets/configurations.json'), - ) as Map; - - return Configuration.fromJson(content); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx index 4432f874f..750b46700 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider.mdx @@ -3,9 +3,9 @@ title: (Async)NotifierProvider --- import CodeBlock from "@theme/CodeBlock"; -import todos from "./notifier_provider/todos"; +import todos from "/docs/providers/notifier_provider/todos"; import todosConsumer from "!!raw-loader!/docs/providers/notifier_provider/todos/todos_consumer.dart"; -import remoteTodos from "./notifier_provider/remote_todos"; +import remoteTodos from "/docs/providers/notifier_provider/remote_todos"; import remoteTodosConsumer from "!!raw-loader!/docs/providers/notifier_provider/remote_todos/todos_consumer.dart"; import { trimSnippet, AutoSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart deleted file mode 100644 index e02195f87..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/codegen.dart +++ /dev/null @@ -1,82 +0,0 @@ -import 'dart:convert'; - -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -class Http { - Future get(String str) async => str; - Future delete(String str) async => str; - Future post(String str, Map body) async => str; - Future patch(String str, Map body) async => str; -} - -final http = Http(); - -/* SNIPPET START */ - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; - - factory Todo.fromJson(Map json) => _$TodoFromJson(json); -} - -// This will generates a AsyncNotifier and AsyncNotifierProvider. -// The AsyncNotifier class that will be passed to our AsyncNotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -// Finally, we are using asyncTodosProvider(AsyncNotifierProvider) to allow the UI to -// interact with our Todos class. -@riverpod -class AsyncTodos extends _$AsyncTodos { - Future> _fetchTodo() async { - final json = await http.get('api/todos'); - final todos = jsonDecode(json) as List>; - return todos.map(Todo.fromJson).toList(); - } - - @override - FutureOr> build() async { - // Load initial todo list from the remote repository - return _fetchTodo(); - } - - Future addTodo(Todo todo) async { - // Set the state to loading - state = const AsyncValue.loading(); - // Add the new todo and reload the todo list from the remote repository - state = await AsyncValue.guard(() async { - await http.post('api/todos', todo.toJson()); - return _fetchTodo(); - }); - } - - // Let's allow removing todos - Future removeTodo(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.delete('api/todos/$todoId'); - return _fetchTodo(); - }); - } - - // Let's mark a todo as completed - Future toggle(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.patch( - 'api/todos/$todoId', - {'completed': true}, - ); - return _fetchTodo(); - }); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart deleted file mode 100644 index f4455a338..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/raw.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -class Http { - Future get(String str) async => str; - Future delete(String str) async => str; - Future post(String str, Map body) async => str; - Future patch(String str, Map body) async => str; -} - -final http = Http(); - -/* SNIPPET START */ - -// An immutable state is preferred. -// We could also use packages like Freezed to help with the implementation. -@immutable -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - factory Todo.fromJson(Map map) { - return Todo( - id: map['id'] as String, - description: map['description'] as String, - completed: map['completed'] as bool, - ); - } - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - Map toJson() => { - 'id': id, - 'description': description, - 'completed': completed, - }; -} - -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -class AsyncTodosNotifier extends AsyncNotifier> { - Future> _fetchTodo() async { - final json = await http.get('api/todos'); - final todos = jsonDecode(json) as List>; - return todos.map(Todo.fromJson).toList(); - } - - @override - Future> build() async { - // Load initial todo list from the remote repository - return _fetchTodo(); - } - - Future addTodo(Todo todo) async { - // Set the state to loading - state = const AsyncValue.loading(); - // Add the new todo and reload the todo list from the remote repository - state = await AsyncValue.guard(() async { - await http.post('api/todos', todo.toJson()); - return _fetchTodo(); - }); - } - - // Let's allow removing todos - Future removeTodo(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.delete('api/todos/$todoId'); - return _fetchTodo(); - }); - } - - // Let's mark a todo as completed - Future toggle(String todoId) async { - state = const AsyncValue.loading(); - state = await AsyncValue.guard(() async { - await http.patch( - 'api/todos/$todoId', - {'completed': true}, - ); - return _fetchTodo(); - }); - } -} - -// Finally, we are using NotifierProvider to allow the UI to interact with -// our TodosNotifier class. -final asyncTodosProvider = - AsyncNotifierProvider>(() { - return AsyncTodosNotifier(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart deleted file mode 100644 index 5d00d05d9..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/remote_todos/todos_consumer.dart +++ /dev/null @@ -1,37 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'codegen.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // rebuild the widget when the todo list changes - final asyncTodos = ref.watch(asyncTodosProvider); - - // Let's render the todos in a scrollable list view - return switch (asyncTodos) { - AsyncData(:final value) => ListView( - children: [ - for (final todo in value) - CheckboxListTile( - value: todo.completed, - // When tapping on the todo, change its completed status - onChanged: (value) { - ref.read(asyncTodosProvider.notifier).toggle(todo.id); - }, - title: Text(todo.description), - ), - ], - ), - AsyncError(:final error) => Text('Error: $error'), - _ => const Center(child: CircularProgressIndicator()), - }; - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart deleted file mode 100644 index 866ed37bb..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/codegen.dart +++ /dev/null @@ -1,68 +0,0 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.freezed.dart'; -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@freezed -class Todo with _$Todo { - factory Todo({ - required String id, - required String description, - required bool completed, - }) = _Todo; -} - -// This will generates a Notifier and NotifierProvider. -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -// Finally, we are using todosProvider(NotifierProvider) to allow the UI to -// interact with our Todos class. -@riverpod -class Todos extends _$Todos { - @override - List build() { - return []; - } - - // Let's allow the UI to add todos. - void addTodo(Todo todo) { - // Since our state is immutable, we are not allowed to do `state.add(todo)`. - // Instead, we should create a new list of todos which contains the previous - // items and the new one. - // Using Dart's spread operator here is helpful! - state = [...state, todo]; - // No need to call "notifyListeners" or anything similar. Calling "state =" - // will automatically rebuild the UI when necessary. - } - - // Let's allow removing todos - void removeTodo(String todoId) { - // Again, our state is immutable. So we're making a new list instead of - // changing the existing list. - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // Let's mark a todo as completed - void toggle(String todoId) { - state = [ - for (final todo in state) - // we're marking only the matching todo as completed - if (todo.id == todoId) - // Once more, since our state is immutable, we need to make a copy - // of the todo. We're using our `copyWith` method implemented before - // to help with that. - todo.copyWith(completed: !todo.completed) - else - // other todos are not modified - todo, - ]; - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart deleted file mode 100644 index ec3e50308..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/raw.dart +++ /dev/null @@ -1,85 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// An immutable state is preferred. -// We could also use packages like Freezed to help with the implementation. -@immutable -class Todo { - const Todo({ - required this.id, - required this.description, - required this.completed, - }); - - // All properties should be `final` on our class. - final String id; - final String description; - final bool completed; - - // Since Todo is immutable, we implement a method that allows cloning the - // Todo with slightly different content. - Todo copyWith({String? id, String? description, bool? completed}) { - return Todo( - id: id ?? this.id, - description: description ?? this.description, - completed: completed ?? this.completed, - ); - } -} - -// The Notifier class that will be passed to our NotifierProvider. -// This class should not expose state outside of its "state" property, which means -// no public getters/properties! -// The public methods on this class will be what allow the UI to modify the state. -class TodosNotifier extends Notifier> { - // We initialize the list of todos to an empty list - @override - List build() { - return []; - } - - // Let's allow the UI to add todos. - void addTodo(Todo todo) { - // Since our state is immutable, we are not allowed to do `state.add(todo)`. - // Instead, we should create a new list of todos which contains the previous - // items and the new one. - // Using Dart's spread operator here is helpful! - state = [...state, todo]; - // No need to call "notifyListeners" or anything similar. Calling "state =" - // will automatically rebuild the UI when necessary. - } - - // Let's allow removing todos - void removeTodo(String todoId) { - // Again, our state is immutable. So we're making a new list instead of - // changing the existing list. - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // Let's mark a todo as completed - void toggle(String todoId) { - state = [ - for (final todo in state) - // we're marking only the matching todo as completed - if (todo.id == todoId) - // Once more, since our state is immutable, we need to make a copy - // of the todo. We're using our `copyWith` method implemented before - // to help with that. - todo.copyWith(completed: !todo.completed) - else - // other todos are not modified - todo, - ]; - } -} - -// Finally, we are using NotifierProvider to allow the UI to interact with -// our TodosNotifier class. -final todosProvider = NotifierProvider>(() { - return TodosNotifier(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart deleted file mode 100644 index 192cb9f66..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/notifier_provider/todos/todos_consumer.dart +++ /dev/null @@ -1,32 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'codegen.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // rebuild the widget when the todo list changes - List todos = ref.watch(todosProvider); - - // Let's render the todos in a scrollable list view - return ListView( - children: [ - for (final todo in todos) - CheckboxListTile( - value: todo.completed, - // When tapping on the todo, change its completed status - onChanged: (value) => - ref.read(todosProvider.notifier).toggle(todo.id), - title: Text(todo.description), - ), - ], - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider.mdx index 136c8edbc..143ef2d6d 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider.mdx @@ -3,11 +3,11 @@ title: Provider --- import CodeBlock from "@theme/CodeBlock"; -import todo from "./provider/todo"; -import completedTodos from "./provider/completed_todos"; +import todo from "/docs/providers/provider/todo"; +import completedTodos from "/docs/providers/provider/completed_todos"; import todosConsumer from "!!raw-loader!/docs/providers/provider/todos_consumer.dart"; -import unoptimizedPreviousButton from "./provider/unoptimized_previous_button"; -import optimizedPreviousButton from "./provider/optimized_previous_button"; +import unoptimizedPreviousButton from "/docs/providers/provider/unoptimized_previous_button"; +import optimizedPreviousButton from "/docs/providers/provider/optimized_previous_button"; import { trimSnippet, AutoSnippet } from "../../../../../src/components/CodeSnippet"; :::caution diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/completed_todos.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/completed_todos.dart deleted file mode 100644 index 1a29d96f5..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/completed_todos.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -import '../todo/todo.dart'; - -part 'completed_todos.g.dart'; - -/* SNIPPET START */ - -@riverpod -List completedTodos(CompletedTodosRef ref) { - final todos = ref.watch(todosProvider); - - // we return only the completed todos - return todos.where((todo) => todo.isCompleted).toList(); -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/index.tsx deleted file mode 100644 index 11451aa1c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./completed_todos.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/raw.dart deleted file mode 100644 index e24c48bd5..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/completed_todos/raw.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../todo/raw.dart'; - -/* SNIPPET START */ - -final completedTodosProvider = Provider>((ref) { - // We obtain the list of all todos from the todosProvider - final todos = ref.watch(todosProvider); - - // we return only the completed todos - return todos.where((todo) => todo.isCompleted).toList(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/index.tsx deleted file mode 100644 index fb83c92f1..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./optimized_previous_button.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/optimized_previous_button.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/optimized_previous_button.dart deleted file mode 100644 index 7d3b8a332..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/optimized_previous_button.dart +++ /dev/null @@ -1,50 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'optimized_previous_button.g.dart'; - -/* SNIPPET START */ - -@riverpod -class PageIndex extends _$PageIndex { - @override - int build() { - return 0; - } - - void goToPreviousPage() { - state = state - 1; - } -} - -// A provider which computes whether the user is allowed to go to the previous page -@riverpod -/* highlight-start */ -bool canGoToPreviousPage(CanGoToPreviousPageRef ref) { -/* highlight-end */ - return ref.watch(pageIndexProvider) != 0; -} - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // We are now watching our new Provider - // Our widget is no longer calculating whether we can go to the previous page. -/* highlight-start */ - final canGoToPreviousPage = ref.watch(canGoToPreviousPageProvider); -/* highlight-end */ - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).goToPreviousPage(); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/raw.dart deleted file mode 100644 index 30b1cc673..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/optimized_previous_button/raw.dart +++ /dev/null @@ -1,36 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final pageIndexProvider = StateProvider((ref) => 0); - -// A provider which computes whether the user is allowed to go to the previous page -/* highlight-start */ -final canGoToPreviousPageProvider = Provider((ref) { -/* highlight-end */ - return ref.watch(pageIndexProvider) != 0; -}); - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // We are now watching our new Provider - // Our widget is no longer calculating whether we can go to the previous page. -/* highlight-start */ - final canGoToPreviousPage = ref.watch(canGoToPreviousPageProvider); -/* highlight-end */ - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).update((state) => state - 1); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/index.tsx deleted file mode 100644 index 91d9cc4aa..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./todo.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/raw.dart deleted file mode 100644 index 11e62bc3a..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/raw.dart +++ /dev/null @@ -1,27 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -class Todo { - Todo(this.description, this.isCompleted); - final bool isCompleted; - final String description; -} - -class TodosNotifier extends Notifier> { - @override - List build() { - return []; - } - - void addTodo(Todo todo) { - state = [...state, todo]; - } - // TODO add other methods, such as "removeTodo", ... -} - -final todosProvider = NotifierProvider>(() { - return TodosNotifier(); -}); diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/todo.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/todo.dart deleted file mode 100644 index 7089bc962..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/todo/todo.dart +++ /dev/null @@ -1,25 +0,0 @@ -// ignore_for_file: avoid_positional_boolean_parameters -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'todo.g.dart'; - -/* SNIPPET START */ - -class Todo { - Todo(this.description, this.isCompleted); - final bool isCompleted; - final String description; -} - -@riverpod -class Todos extends _$Todos { - @override - List build() { - return []; - } - - void addTodo(Todo todo) { - state = [...state, todo]; - } - // TODO add other methods, such as "removeTodo", ... -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/index.tsx deleted file mode 100644 index d345d4f5d..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./unoptimized_previous_button.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/raw.dart deleted file mode 100644 index 828d382d5..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/raw.dart +++ /dev/null @@ -1,26 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final pageIndexProvider = StateProvider((ref) => 0); - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // if not on first page, the previous button is active - final canGoToPreviousPage = ref.watch(pageIndexProvider) != 0; - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).update((state) => state - 1); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/unoptimized_previous_button.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/unoptimized_previous_button.dart deleted file mode 100644 index f77de56c3..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/provider/unoptimized_previous_button/unoptimized_previous_button.dart +++ /dev/null @@ -1,39 +0,0 @@ -// A provider that controls the current page -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'unoptimized_previous_button.g.dart'; - -/* SNIPPET START */ - -@riverpod -class PageIndex extends _$PageIndex { - @override - int build() { - return 0; - } - - void goToPreviousPage() { - state = state - 1; - } -} - -class PreviousButton extends ConsumerWidget { - const PreviousButton({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // if not on first page, the previous button is active - final canGoToPreviousPage = ref.watch(pageIndexProvider) != 0; - - void goToPreviousPage() { - ref.read(pageIndexProvider.notifier).goToPreviousPage(); - } - - return ElevatedButton( - onPressed: canGoToPreviousPage ? goToPreviousPage : null, - child: const Text('previous'), - ); - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx index bd40cfc5f..32e6c7f97 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider.mdx @@ -4,7 +4,7 @@ title: StreamProvider import CodeBlock from "@theme/CodeBlock"; import { trimSnippet,AutoSnippet } from "../../../../../src/components/CodeSnippet"; -import streamProvider from "./stream_provider/live_stream_chat_provider"; +import streamProvider from "/docs/providers/stream_provider/live_stream_chat_provider"; import streamConsumer from "!!raw-loader!/docs/providers/stream_provider/live_stream_chat_consumer.dart"; :::caution diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/codegen.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/codegen.dart deleted file mode 100644 index e2e34878c..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/codegen.dart +++ /dev/null @@ -1,23 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'dart:convert'; -import 'dart:io'; -import 'package:riverpod_annotation/riverpod_annotation.dart'; - -part 'codegen.g.dart'; - -/* SNIPPET START */ - -@riverpod -Stream> chat(ChatRef ref) async* { - // Connect to an API using sockets, and decode the output - final socket = await Socket.connect('my-api', 4242); - ref.onDispose(socket.close); - - var allMessages = const []; - await for (final message in socket.map(utf8.decode)) { - // A new message has been received. Let's add it to the list of all messages. - allMessages = [...allMessages, message]; - yield allMessages; - } -} diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/index.tsx b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/index.tsx deleted file mode 100644 index 339b89a56..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import raw from "!!raw-loader!./raw.dart"; -import codegen from "!!raw-loader!./codegen.dart"; - -export default { - raw, - hooks: raw, - codegen, - hooksCodegen: codegen, -}; diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/raw.dart b/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/raw.dart deleted file mode 100644 index beb2bcd05..000000000 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/providers/stream_provider/live_stream_chat_provider/raw.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ -final chatProvider = StreamProvider>((ref) async* { - // Connect to an API using sockets, and decode the output - final socket = await Socket.connect('my-api', 4242); - ref.onDispose(socket.close); - - var allMessages = const []; - await for (final message in socket.map(utf8.decode)) { - // A new message has been received. Let's add it to the list of all messages. - allMessages = [...allMessages, message]; - yield allMessages; - } -}); diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx b/website/i18n/ru/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx index 7818a7344..027a19c64 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/concepts/provider_observer.mdx @@ -3,7 +3,7 @@ title: ProviderObserver --- import CodeBlock from "@theme/CodeBlock"; -import logger from "!!raw-loader!./provider_observer_logger.dart"; +import logger from "!!raw-loader!/docs/concepts/provider_observer_logger.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; [ProviderObserver] наблюдает за изменениями ProviderContainer. diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/concepts/provider_observer_logger.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/concepts/provider_observer_logger.dart deleted file mode 100644 index da15a3a50..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/concepts/provider_observer_logger.dart +++ /dev/null @@ -1,61 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors, avoid_print - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// Пример со счетчиком с использованием логгера и riverpod - -class Logger extends ProviderObserver { - @override - void didUpdateProvider( - ProviderBase provider, - Object? previousValue, - Object? newValue, - ProviderContainer container, - ) { - print(''' -{ - "provider": "${provider.name ?? provider.runtimeType}", - "newValue": "$newValue" -}'''); - } -} - -void main() { - runApp( - // Добавление ProviderScope делает Riverpod доступным для всего проекта - // Добавление логгера в список наблюдателей - ProviderScope(observers: [Logger()], child: const MyApp()), - ); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp(home: Home()); - } -} - -final counterProvider = StateProvider((ref) => 0, name: 'counter'); - -class Home extends ConsumerWidget { - @override - Widget build(BuildContext context, WidgetRef ref) { - final count = ref.watch(counterProvider); - - return Scaffold( - appBar: AppBar(title: const Text('Counter example')), - body: Center( - child: Text('$count'), - ), - floatingActionButton: FloatingActionButton( - onPressed: () => ref.read(counterProvider.notifier).state++, - child: const Icon(Icons.add), - ), - ); - } -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx index e70ddf2a2..c5a9dd622 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing.mdx @@ -5,13 +5,13 @@ title: Тестирование import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import testingOriginalTestFlutter from "!!raw-loader!./testing_original_test_flutter.dart"; -import testingOriginalTestDart from "!!raw-loader!./testing_original_test_dart.dart"; -import repositorySnippet from "!!raw-loader!./testing_repository.dart"; -import testFlutter from "!!raw-loader!./testing_flutter.dart"; -import testDart from "!!raw-loader!./testing_dart.dart"; -import testFull from "!!raw-loader!./testing_full.dart"; -import testOverrideInfo from "!!raw-loader!./testing_override_info.dart"; +import testingOriginalTestFlutter from "!!raw-loader!/docs/cookbooks/testing_original_test_flutter.dart"; +import testingOriginalTestDart from "!!raw-loader!/docs/cookbooks/testing_original_test_dart.dart"; +import repositorySnippet from "!!raw-loader!/docs/cookbooks/testing_repository.dart"; +import testFlutter from "!!raw-loader!/docs/cookbooks/testing_flutter.dart"; +import testDart from "!!raw-loader!/docs/cookbooks/testing_dart.dart"; +import testFull from "!!raw-loader!/docs/cookbooks/testing_full.dart"; +import testOverrideInfo from "!!raw-loader!/docs/cookbooks/testing_override_info.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; Любое приложение среднего размера необходимо тестировать. diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_dart.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_dart.dart deleted file mode 100644 index 5b32fecad..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_dart.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class FakeRepository {} - -final repositoryProvider = Provider((ref) => FakeRepository()); - -abstract class Todo { - String get id; - String get label; - bool get completed; -} - -final todoListProvider = FutureProvider>((ref) => []); - -void main() { -/* SNIPPET START */ - -test('override repositoryProvider', () async { - final container = ProviderContainer( - overrides: [ - // Переопределяем поведение repositoryProvider, чтобы он - // возвращал FakeRepository вместо Repository. - /* highlight-start */ - repositoryProvider.overrideWithValue(FakeRepository()) - /* highlight-end */ - // Нам не нужно переопределять `todoListProvider`. - // Он автоматически будет использовать - // переопределенный repositoryProvider - ], - ); - - // Первое получение значения - // Проверка: является ли состояние состоянием загрузки - expect( - container.read(todoListProvider), - const AsyncValue>.loading(), - ); - - // Ждем окончания запроса - await container.read(todoListProvider.future); - - // Читаем полученные данные - expect(container.read(todoListProvider).value, [ - isA() - .having((s) => s.id, 'id', '42') - .having((s) => s.label, 'label', 'Hello world') - .having((s) => s.completed, 'completed', false), - ]); -}); - -/* SNIPPET END */ -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_flutter.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_flutter.dart deleted file mode 100644 index 35b35a589..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_flutter.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class MyApp extends StatelessWidget { - // ignore: prefer_const_constructors_in_immutables - MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return Container(); - } -} - -final repositoryProvider = Provider((ref) => FakeRepository()); - -class FakeRepository {} - -void main() { -/* SNIPPET START */ - -testWidgets('override repositoryProvider', (tester) async { - await tester.pumpWidget( - ProviderScope( - overrides: [ - // Переопределяем поведение repositoryProvider, чтобы он - // возвращал FakeRepository вместо Repository. - /* highlight-start */ - repositoryProvider.overrideWithValue(FakeRepository()) - /* highlight-end */ - // Нам не нужно переопределять `todoListProvider`. - // Он автоматически будет использовать - // переопределенный repositoryProvider - ], - child: MyApp(), - ), - ); -}); - -/* SNIPPET END */ -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_full.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_full.dart deleted file mode 100644 index fdd7f1e04..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_full.dart +++ /dev/null @@ -1,100 +0,0 @@ - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -class Repository { - Future> fetchTodos() async => []; -} - -class Todo { - Todo({ - required this.id, - required this.label, - required this.completed, - }); - - final String id; - final String label; - final bool completed; -} - -// Храним экземпляр Repository в провайдере -final repositoryProvider = Provider((ref) => Repository()); - -/// Список задач. Мы просто получаем задачи с сервера, -/// используя [Repository]. -final todoListProvider = FutureProvider((ref) async { - // Получение экземпляра Repository - final repository = ref.read(repositoryProvider); - - // Получение задач и передача их в UI. - return repository.fetchTodos(); -}); - -/// Mock реализация Repository, которая возвращает предопределенный список задач -class FakeRepository implements Repository { - @override - Future> fetchTodos() async { - return [ - Todo(id: '42', label: 'Hello world', completed: false), - ]; - } -} - -class TodoItem extends StatelessWidget { - const TodoItem({super.key, required this.todo}); - final Todo todo; - @override - Widget build(BuildContext context) { - return Text(todo.label); - } -} - -void main() { - testWidgets('override repositoryProvider', (tester) async { - await tester.pumpWidget( - ProviderScope( - overrides: [ - repositoryProvider.overrideWithValue(FakeRepository()) - ], - // Наше приложение, которые читает значение todoListProvider - // для отображение списка задач. - // Вы можете вынести это в отдельный MyApp виджет - child: MaterialApp( - home: Scaffold( - body: Consumer(builder: (context, ref, _) { - final todos = ref.watch(todoListProvider); - // Список задач загружается, либо случилась ошибка - if (todos.asData == null) { - return const CircularProgressIndicator(); - } - return ListView( - children: [ - for (final todo in todos.asData!.value) TodoItem(todo: todo) - ], - ); - }), - ), - ), - ), - ); - - // Первый кадр - состояние загрузки - expect(find.byType(CircularProgressIndicator), findsOneWidget); - - // Перерисовка. TodoListProvider уже должен получить задачи - await tester.pump(); - - // Загрузка закончилась - expect(find.byType(CircularProgressIndicator), findsNothing); - - // Переотрисовка одного TodoItem с данными, пришедшими из FakeRepository - expect(tester.widgetList(find.byType(TodoItem)), [ - isA() - .having((s) => s.todo.id, 'todo.id', '42') - .having((s) => s.todo.label, 'todo.label', 'Hello world') - .having((s) => s.todo.completed, 'todo.completed', false), - ]); - }); -} \ No newline at end of file diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_dart.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_dart.dart deleted file mode 100644 index 7967027a3..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_dart.dart +++ /dev/null @@ -1,66 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ - -// Счетчик, реализованный и протестированный с использованием Dart (без Flutter) - -// Объявляем провайдер глобально. -// Используем этот провайдер в двух тестах, чтобы проверить, правильно ли -// состояние сбрасывается до нуля между тестами. - -final counterProvider = StateProvider((ref) => 0); - -// Используем mockito, чтобы отслеживать, когда провайдер уведомляет своих слушателей -class Listener extends Mock { - void call(int? previous, int value); -} - -void main() { - test('defaults to 0 and notify listeners when value changes', () { - // Объект, с помощью которого мы можем читать провайдеры - // Не используйте один и тот же экземпляр этого - // класса в разных тестах - final container = ProviderContainer(); - addTearDown(container.dispose); - final listener = Listener(); - - // Наблюдение за провайдером и его изменениями - container.listen( - counterProvider, - listener.call, - fireImmediately: true, - ); - - // listener мгновенно вызывается со значением 0 (значение по умолчанию) - verify(listener(null, 0)).called(1); - verifyNoMoreInteractions(listener); - - // Увеличиваем значение - container.read(counterProvider.notifier).state++; - - // listener был снова вызван, но в этот раз со значением 1 - verify(listener(0, 1)).called(1); - verifyNoMoreInteractions(listener); - }); - - test('the counter state is not shared between tests', () { - // Используем другой ProviderContainer для чтения наших провайдеров. - // Таким образом мы можем убедиться, что состояние не разделяется - // между тестами - final container = ProviderContainer(); - addTearDown(container.dispose); - final listener = Listener(); - - container.listen( - counterProvider, - listener.call, - fireImmediately: true, - ); - - // Новый тест верно использует значение по умолчанию: 0 - verify(listener(null, 0)).called(1); - verifyNoMoreInteractions(listener); - }); -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_flutter.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_flutter.dart deleted file mode 100644 index a7d623a5c..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_original_test_flutter.dart +++ /dev/null @@ -1,58 +0,0 @@ -// ignore_for_file: use_key_in_widget_constructors - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_test/flutter_test.dart'; - -/* SNIPPET START */ - -// Счетчик, реализованный и протестированный с использованием Flutter - -// Объявляем провайдер глобально. -// Используем этот провайдер в двух тестах, чтобы проверить, правильно ли -// состояние сбрасывается до нуля между тестами. - -final counterProvider = StateProvider((ref) => 0); - -// Отрисовывает текущее состояние и кнопку для увеличения счетчика -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - home: Consumer(builder: (context, ref, _) { - final counter = ref.watch(counterProvider); - return ElevatedButton( - onPressed: () => ref.read(counterProvider.notifier).state++, - child: Text('$counter'), - ); - }), - ); - } -} - -void main() { - testWidgets('update the UI when incrementing the state', (tester) async { - await tester.pumpWidget(ProviderScope(child: MyApp())); - - // `0` - значение по умолчанию, как это было объявлено в провайдере - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Увеличение счетчика и переотрисовка - await tester.tap(find.byType(ElevatedButton)); - await tester.pump(); - - // Состояние счетчика действительно увеличилось - expect(find.text('1'), findsOneWidget); - expect(find.text('0'), findsNothing); - }); - - testWidgets('the counter state is not shared between tests', (tester) async { - await tester.pumpWidget(ProviderScope(child: MyApp())); - - // Состояние счетчика снова стало равно `0` - // без использования tearDown/setUp - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - }); -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_override_info.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_override_info.dart deleted file mode 100644 index dbdc85b26..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_override_info.dart +++ /dev/null @@ -1,44 +0,0 @@ -// ignore_for_file: avoid_unused_constructor_parameters - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -extension on ProviderBase { - // ignore: unused_element - Override overrideWithValue(Object? value) => throw UnimplementedError(); -} - -class Todo { - Todo({ - required String id, - required String label, - required bool completed, - }); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return Container(); - } -} - -/* SNIPPET START */ - -final todoListProvider = FutureProvider((ref) async => []); -// ... -/* SKIP */ -final foo = -/* SKIP END */ - ProviderScope( - overrides: [ - /// Можно переопределить FutureProvider, чтобы он возвращал - /// определенное значение - todoListProvider.overrideWithValue( - AsyncValue.data([Todo(id: '42', label: 'Hello', completed: true)]), - ), - ], - child: const MyApp(), -); diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_repository.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_repository.dart deleted file mode 100644 index 4aa2368ab..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/cookbooks/testing_repository.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:hooks_riverpod/hooks_riverpod.dart'; - -class Todo {} - -/* SNIPPET START */ - -class Repository { - Future> fetchTodos() async => []; -} - -// Храним экземпляр Repository в провайдере -final repositoryProvider = Provider((ref) => Repository()); - -/// Список задач. Мы просто получаем задачи с сервера, -/// используя [Repository]. -final todoListProvider = FutureProvider((ref) async { - // Получение экземпляра Repository - final repository = ref.watch(repositoryProvider); - - // Получение задач и передача их в UI. - return repository.fetchTodos(); -}); diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/getting_started.mdx b/website/i18n/ru/docusaurus-plugin-content-docs/current/getting_started.mdx index 5febb2d89..e797dd5b6 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/getting_started.mdx +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/getting_started.mdx @@ -42,7 +42,7 @@ import { trimSnippet } from "../../../../src/components/CodeSnippet"; ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -59,7 +59,7 @@ dependencies: ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.12.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -75,7 +75,7 @@ dependencies: ```yaml title="pubspec.yaml" environment: - sdk: ">=2.12.0-0 <3.0.0" + sdk: ">=2.12.0-0 <4.0.0" dependencies: riverpod: ^2.1.3 diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider.mdx b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider.mdx index 03ac48f73..5b561c916 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider.mdx +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider.mdx @@ -5,8 +5,8 @@ title: ChangeNotifierProvider import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import todos from "!!raw-loader!./change_notifier_provider/todos.dart"; -import todosConsumer from "!!raw-loader!./change_notifier_provider/todos_consumer.dart"; +import todos from "!!raw-loader!/docs/providers/change_notifier_provider/todos.dart"; +import todosConsumer from "!!raw-loader!/docs/providers/change_notifier_provider/todos_consumer.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; `ChangeNotifierProvider` (есть только в flutter_riverpod/hooks_riverpod) - это diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider/todos.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider/todos.dart deleted file mode 100644 index 5745f2fde..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider/todos.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -class Todo { - Todo({ - required this.id, - required this.description, - required this.completed, - }); - - String id; - String description; - bool completed; -} - -class TodosNotifier extends ChangeNotifier { - final todos = []; - - // Добавление задач - void addTodo(Todo todo) { - todos.add(todo); - notifyListeners(); - } - - // Удаление задач - void removeTodo(String todoId) { - todos.remove(todos.firstWhere((element) => element.id == todoId)); - notifyListeners(); - } - - // Задача выполнена/не выполнена - void toggle(String todoId) { - for (final todo in todos) { - if (todo.id == todoId) { - todo.completed = !todo.completed; - notifyListeners(); - } - } - } -} - -// Используем ChangeNotifierProvider для взаимодействия с TodosNotifier -final todosProvider = ChangeNotifierProvider((ref) { - return TodosNotifier(); -}); diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider/todos_consumer.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider/todos_consumer.dart deleted file mode 100644 index e04cbd9e2..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/change_notifier_provider/todos_consumer.dart +++ /dev/null @@ -1,33 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'todos.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // перестройка виджета, когда список задач изменился - List todos = ref.watch(todosProvider).todos; - - // Отображение задач в прокручиваемом списке - return ListView( - children: [ - for (final todo in todos) - CheckboxListTile( - value: todo.completed, - // По клику меняем статус задачи - // выполнена/не выполнена - onChanged: (value) => - ref.read(todosProvider.notifier).toggle(todo.id), - title: Text(todo.description), - ), - ], - ); - } -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/provider.mdx b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/provider.mdx index caaf25392..56d5840d9 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/provider.mdx +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/provider.mdx @@ -7,7 +7,7 @@ import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; import todo from "!!raw-loader!./provider/todo.dart"; import completedTodos from "!!raw-loader!./provider/completed_todos.dart"; -import todosConsumer from "!!raw-loader!./provider/todos_consumer.dart"; +import todosConsumer from "!!raw-loader!/docs/providers/provider/todos_consumer.dart"; import unoptimizedPreviousButton from "!!raw-loader!./provider/unoptimized_previous_button.dart"; import optimizedPreviousButton from "!!raw-loader!./provider/optimized_previous_button.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart deleted file mode 100644 index d85ec14ef..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/provider/todos_consumer.dart +++ /dev/null @@ -1,18 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/widgets.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'completed_todos.dart'; - -Widget build() { -return -/* SNIPPET START */ -Consumer(builder: (context, ref, child) { - final completedTodos = ref.watch(completedTodosProvider); - // TODO: отобразить задачи с помощью ListView/GridView/.../* SKIP */ - return Container(); - /* SKIP END */ -}); -/* SNIPPET END */ -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx index 9008b6c42..395436576 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider.mdx @@ -5,8 +5,8 @@ title: StateNotifierProvider import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import todos from "!!raw-loader!./state_notifier_provider/todos.dart"; -import todosConsumer from "!!raw-loader!./state_notifier_provider/todos_consumer.dart"; +import todos from "!!raw-loader!/docs/providers/state_notifier_provider/todos.dart"; +import todosConsumer from "!!raw-loader!/docs/providers/state_notifier_provider/todos_consumer.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; `StateNotifierProvider` - провайдер, который можно слушать, а также он хранит в diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos.dart deleted file mode 100644 index a6d9c8652..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos.dart +++ /dev/null @@ -1,79 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -// Состояние StateNotifier должно быть неизменяемым. -// Для реализации этого мы можем воспользоваться пакетами как Freezed -@immutable -class Todo { - const Todo({required this.id, required this.description, required this.completed}); - - // В классе все поля должны быть `final`. - final String id; - final String description; - final bool completed; - - // Т. к. Todo неизменяемый, создадим метод клонирования - // с возможными изменениями - Todo copyWith({String? id, String? description, bool? completed}) { - return Todo( - id: id ?? this.id, - description: description ?? this.description, - completed: completed ?? this.completed, - ); - } -} - -// StateNotifier, который будет передан в наш StateNotifierProvider. -// Этот класс не должен предоставлять никаких способов получения своего состояния, -// хранящегося в поле "state", -// т.е. никаких публичных геттеров/полей не должно быть! -// Публичные методы описывают то, как UI может изменять состояние. -class TodosNotifier extends StateNotifier> { - // Инициализируем список задач пустым списком - TodosNotifier(): super([]); - - // Добавление задач - void addTodo(Todo todo) { - // Т. к. наше состояние неизменяемо, нельзя делать подобное: `state.add(todo)`. - // Вместо этого мы должны создать новый список задач, который будет - // содержать предыдущие задачи и новую. - // Тут нам поможет spread оператор - state = [...state, todo]; - // Не нужно вызывать "notifyListeners" или что-то подобное. - // Вызов "state =" автоматически перестраивает UI, когда это необходимо. - } - - // Удаление задач - void removeTodo(String todoId) { - // Не забываем, что наше состояние неизменяемо. - // Так что мы создаем новый список, а не изменяем существующий. - state = [ - for (final todo in state) - if (todo.id != todoId) todo, - ]; - } - - // Изменение статуса задачи: выполнена/не выполнена - void toggle(String todoId) { - state = [ - for (final todo in state) - // Изменяем статус только той задачи, - // у которой id равен todoId - if (todo.id == todoId) - // Еще раз вспомним, что наше состояние неизменяемо. Так что - // нам необходимо создавать копию списка задач. - // Воспользуемся методом `copyWith`, который мы реализовали ранее - todo.copyWith(completed: !todo.completed) - else - // Другие задачи не изменяем - todo, - ]; - } -} - -// Используем StateNotifierProvider для взаимодействия с TodosNotifier -final todosProvider = StateNotifierProvider>((ref) { - return TodosNotifier(); -}); \ No newline at end of file diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos_consumer.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos_consumer.dart deleted file mode 100644 index bc1163af4..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_notifier_provider/todos_consumer.dart +++ /dev/null @@ -1,32 +0,0 @@ -// ignore_for_file: omit_local_variable_types, prefer_final_locals - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'todos.dart'; - -/* SNIPPET START */ - -class TodoListView extends ConsumerWidget { - const TodoListView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - // перестройка виджета, когда список задач изменился - List todos = ref.watch(todosProvider); - - // Отображение задач в прокручиваемом списке - return ListView( - children: [ - for (final todo in todos) - CheckboxListTile( - value: todo.completed, - // По клику меняем статус задачи - // выполнена/не выполнена - onChanged: (value) => ref.read(todosProvider.notifier).toggle(todo.id), - title: Text(todo.description), - ), - ], - ); - } -} \ No newline at end of file diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider.mdx b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider.mdx index 12cda12ac..64fdf8253 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider.mdx +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider.mdx @@ -5,14 +5,14 @@ title: StateProvider import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; import CodeBlock from "@theme/CodeBlock"; -import product from "!!raw-loader!./state_provider/product.dart"; -import productListView from "!!raw-loader!./state_provider/product_list_view.dart"; -import dropdown from "!!raw-loader!./state_provider/dropdown.dart"; -import sortProvider from "!!raw-loader!./state_provider/sort_provider.dart"; -import connectedDropdown from "!!raw-loader!./state_provider/connected_dropdown.dart"; -import sortedProductProvider from "!!raw-loader!./state_provider/sorted_product_provider.dart"; -import updateReadTwice from "!!raw-loader!./state_provider/update_read_twice.dart"; -import updateReadOnce from "!!raw-loader!./state_provider/update_read_once.dart"; +import product from "!!raw-loader!/docs/providers/state_provider/product.dart"; +import productListView from "!!raw-loader!/docs/providers/state_provider/product_list_view.dart"; +import dropdown from "!!raw-loader!/docs/providers/state_provider/dropdown.dart"; +import sortProvider from "!!raw-loader!/docs/providers/state_provider/sort_provider.dart"; +import connectedDropdown from "!!raw-loader!/docs/providers/state_provider/connected_dropdown.dart"; +import sortedProductProvider from "!!raw-loader!/docs/providers/state_provider/sorted_product_provider.dart"; +import updateReadTwice from "!!raw-loader!/docs/providers/state_provider/update_read_twice.dart"; +import updateReadOnce from "!!raw-loader!/docs/providers/state_provider/update_read_once.dart"; import { trimSnippet } from "../../../../../src/components/CodeSnippet"; `StateProvider` - провайдер, который предоставляет способ модифицировать diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/connected_dropdown.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/connected_dropdown.dart deleted file mode 100644 index f1d7b6c0c..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/connected_dropdown.dart +++ /dev/null @@ -1,24 +0,0 @@ -// ignore_for_file: prefer_const_literals_to_create_immutables - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'dropdown.dart'; -import 'sort_provider.dart'; - -Widget build(BuildContext context, WidgetRef ref) { - return AppBar(actions: [ -/* SNIPPET START */ -DropdownButton( - // При изменении типа сортировки произойдет перестройка DropdownButton - value: ref.watch(productSortTypeProvider), - // Обновляем состояние провайдера при взаимодействии пользователя с DropdownButton - onChanged: (value) => - ref.read(productSortTypeProvider.notifier).state = value!, - items: [ - // ... - ], -), -/* SNIPPET END */ - ]); -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/dropdown.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/dropdown.dart deleted file mode 100644 index 3d38655ae..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/dropdown.dart +++ /dev/null @@ -1,43 +0,0 @@ -// ignore_for_file: unused_local_variable - -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'full.dart'; - -/* SNIPPET START */ - -// Перечисление типов сортировки -enum ProductSortType { - name, - price, -} - -Widget build(BuildContext context, WidgetRef ref) { - final products = ref.watch(productsProvider); - return Scaffold( - appBar: AppBar( - title: const Text('Products'), - actions: [ - DropdownButton( - value: ProductSortType.price, - onChanged: (value) {}, - items: const [ - DropdownMenuItem( - value: ProductSortType.name, - child: Icon(Icons.sort_by_alpha), - ), - DropdownMenuItem( - value: ProductSortType.price, - child: Icon(Icons.sort), - ), - ], - ), - ], - ), - body: ListView.builder( - // ... /* SKIP */ - itemBuilder: (c, i) => Container(), /* SKIP END */ - ), - ); -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/product.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/product.dart deleted file mode 100644 index 078def200..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/product.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:riverpod/riverpod.dart'; - -/* SNIPPET START */ - -class Product { - Product({required this.name, required this.price}); - - final String name; - final double price; -} - -final _products = [ - Product(name: 'iPhone', price: 999), - Product(name: 'cookie', price: 2), - Product(name: 'ps5', price: 500), -]; - -final productsProvider = Provider>((ref) { - return _products; -}); diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/product_list_view.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/product_list_view.dart deleted file mode 100644 index 17765aea8..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/product_list_view.dart +++ /dev/null @@ -1,22 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'product.dart'; - -/* SNIPPET START */ - -Widget build(BuildContext context, WidgetRef ref) { - final products = ref.watch(productsProvider); - return Scaffold( - body: ListView.builder( - itemCount: products.length, - itemBuilder: (context, index) { - final product = products[index]; - return ListTile( - title: Text(product.name), - subtitle: Text('${product.price} \$'), - ); - }, - ), - ); -} diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/sort_provider.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/sort_provider.dart deleted file mode 100644 index 695e000a9..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/sort_provider.dart +++ /dev/null @@ -1,10 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'dropdown.dart'; - -/* SNIPPET START */ - -final productSortTypeProvider = StateProvider( - // Возвращаем тип сортировки по умолчанию (name) - (ref) => ProductSortType.name, -); diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/sorted_product_provider.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/sorted_product_provider.dart deleted file mode 100644 index 6725d0282..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/sorted_product_provider.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:collection/collection.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import 'dropdown.dart'; -import 'product.dart'; -import 'sort_provider.dart'; - -final _products = [ - Product(name: 'iPhone', price: 999), - Product(name: 'cookie', price: 2), - Product(name: 'ps5', price: 500), -]; - -/* SNIPPET START */ - -final productsProvider = Provider>((ref) { - final sortType = ref.watch(productSortTypeProvider); - switch (sortType) { - case ProductSortType.name: - return _products.sorted((a, b) => a.name.compareTo(b.name)); - case ProductSortType.price: - return _products.sorted((a, b) => a.price.compareTo(b.price)); - } -}); \ No newline at end of file diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_once.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_once.dart deleted file mode 100644 index 825df6d0f..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_once.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - /* highlight-start */ - ref.read(counterProvider.notifier).update((state) => state + 1); - /* highlight-end */ - }, - ), - ); - } -} \ No newline at end of file diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_twice.dart b/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_twice.dart deleted file mode 100644 index 80c4b2505..000000000 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/providers/state_provider/update_read_twice.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -/* SNIPPET START */ - -final counterProvider = StateProvider((ref) => 0); - -class HomeView extends ConsumerWidget { - const HomeView({super.key}); - - @override - Widget build(BuildContext context, WidgetRef ref) { - return Scaffold( - floatingActionButton: FloatingActionButton( - onPressed: () { - // Обновляем состояние провайдера, основываясь на предыдущем состоянии - // И в итоге, мы дважды читаем значение провайдера! - ref.read(counterProvider.notifier).state = ref.read(counterProvider.notifier).state + 1; - }, - ), - ); - } -} \ No newline at end of file diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/advanced/select.mdx b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/advanced/select.mdx index d020b217b..ffe2e9b6f 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/advanced/select.mdx +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/advanced/select.mdx @@ -3,9 +3,9 @@ title: 性能优化 --- import { AutoSnippet } from "@site/src/components/CodeSnippet"; -import select from "./select/select"; +import select from "/docs/advanced/select/select"; -import selectAsync from "./select/select_async"; +import selectAsync from "/docs/advanced/select/select_async";