Skip to content

Commit

Permalink
fix: Add dispose to AppRef.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Nov 19, 2022
1 parent 08b22be commit 890bf70
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
15 changes: 8 additions & 7 deletions packages/katana_scoped/example/pubspec.lock
Expand Up @@ -28,7 +28,7 @@ packages:
name: asn1lib
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.4.0"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -299,19 +299,19 @@ packages:
source: hosted
version: "6.5.4"
katana:
dependency: "direct overridden"
dependency: transitive
description:
path: "../../katana"
relative: true
source: path
version: "0.15.8+2"
name: katana
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.10"
katana_scoped:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.3.3"
version: "1.5.2"
lints:
dependency: transitive
description:
Expand Down Expand Up @@ -543,3 +543,4 @@ packages:
version: "3.1.1"
sdks:
dart: ">=2.18.1 <3.0.0"
flutter: ">=2.0.0"
13 changes: 7 additions & 6 deletions packages/katana_scoped/lib/src/scoped.dart
Expand Up @@ -284,7 +284,8 @@ abstract class ScopedWidgetBase extends Widget {
/// [widget][PageScopedWidget][ScopedWidget]を継承したクラスを渡します。
///
/// [ScopedWidgetScope.of]で先祖にあるウィジェットを取り出すことができます。
class ScopedWidgetScope extends InheritedWidget {
class ScopedWidgetScope<TWidget extends ScopedWidgetBase>
extends InheritedWidget {
/// [InheritedWidget] for making [ScopedWidgetBase] retrievable from descendant widgets.
///
/// Pass a class inheriting from [PageScopedWidget] or [ScopedWidget] to [widget].
Expand All @@ -305,7 +306,7 @@ class ScopedWidgetScope extends InheritedWidget {
/// Widgets that inherit from [ScopedWidgetBase].
///
/// [ScopedWidgetBase]を継承したウィジェット。
final Widget widget;
final TWidget widget;

/// O(1) out [TWidget] in ancestor by passing [context].
///
Expand All @@ -316,13 +317,13 @@ class ScopedWidgetScope extends InheritedWidget {
/// 祖先に[TWidget]が存在しない場合はエラーが出力されます。
static TWidget of<TWidget extends ScopedWidgetBase>(BuildContext context) {
final scope = context
.getElementForInheritedWidgetOfExactType<ScopedWidgetScope>()
?.widget as ScopedWidgetScope?;
.getElementForInheritedWidgetOfExactType<ScopedWidgetScope<TWidget>>()
?.widget as ScopedWidgetScope<TWidget>?;
assert(
scope != null && scope.widget is TWidget,
scope != null,
"Could not find $TWidget. Please define $TWidget in the element above.",
);
return scope!.widget as TWidget;
return scope!.widget;
}

@override
Expand Down
11 changes: 11 additions & 0 deletions packages/katana_scoped/lib/src/scoped_ref.dart
Expand Up @@ -68,6 +68,17 @@ class AppRef implements Ref {
)
?.build();
}

/// Discard and clear all appscope states.
///
/// Please use this function to reset the application once, such as when logging out.
///
/// すべてのアプリスコープの状態を破棄してクリアします。
///
/// ログアウト時など一旦アプリをリセットする場合にご利用ください。
void dispose() {
_scopedValueContainer.dispose();
}
}

/// A page-scoped reference passed from [PageScopedWidget.build].
Expand Down
10 changes: 5 additions & 5 deletions packages/katana_scoped/pubspec.lock
Expand Up @@ -14,7 +14,7 @@ packages:
name: asn1lib
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.4.0"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -119,10 +119,10 @@ packages:
katana:
dependency: "direct main"
description:
path: "../katana"
relative: true
source: path
version: "0.15.8+2"
name: katana
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.10"
matcher:
dependency: transitive
description:
Expand Down

0 comments on commit 890bf70

Please sign in to comment.