Skip to content

Commit

Permalink
fix: Fixed a bug in internal appRef.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Oct 30, 2023
1 parent 54fcea1 commit 5299d98
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
7 changes: 7 additions & 0 deletions packages/katana_scoped/lib/src/scoped.dart
Expand Up @@ -53,18 +53,22 @@ class _ScopedState extends State<Scoped> {
void initState() {
super.initState();
_container = ScopedValueContainer();
final appRef = _AppScopedScope.of(context).widget.appRef;
_appListener = AppScopedValueListener._(
context: context,
appRef: appRef,
callback: _handledOnRebuild,
scope: ScopedLoggerScope.app,
);
_pageListener = PageScopedValueListener._(
context: context,
appRef: appRef,
callback: _handledOnRebuild,
scope: ScopedLoggerScope.page,
);
_widgetListener = _ScopedValueListenerOnWidget._(
context: context,
appRef: appRef,
callback: _handledOnRebuild,
container: _container,
scope: ScopedLoggerScope.widget,
Expand Down Expand Up @@ -209,14 +213,17 @@ class _PageScopedWidgetState extends State<PageScopedWidget> {
@override
void initState() {
super.initState();
final appRef = _AppScopedScope.of(context).widget.appRef;
_container = ScopedValueContainer();
_appListener = AppScopedValueListener._(
context: context,
appRef: appRef,
callback: _handledOnRebuild,
scope: ScopedLoggerScope.app,
);
_pageListener = _ScopedValueListenerOnPage._(
context: context,
appRef: appRef,
callback: _handledOnRebuild,
container: _container,
scope: ScopedLoggerScope.page,
Expand Down
30 changes: 23 additions & 7 deletions packages/katana_scoped/lib/src/scoped_value_listener.dart
Expand Up @@ -7,16 +7,20 @@ class AppScopedValueListener extends ScopedValueListener {
AppScopedValueListener._({
required BuildContext context,
required VoidCallback callback,
required AppRef appRef,
required super.scope,
}) : super._(context: context, callback: callback);
}) : super._(
context: context,
callback: callback,
appRef: appRef,
);

@override
ScopedValueContainer get container {
if (_containerCache != null) {
return _containerCache!;
}
final appRef = _AppScopedScope.of(_context).widget.appRef;
return _containerCache = appRef._scopedValueContainer;
return _containerCache = _appRef._scopedValueContainer;
}

@override
Expand All @@ -33,8 +37,13 @@ class PageScopedValueListener extends _ScopedValueListenerOnPage {
PageScopedValueListener._({
required BuildContext context,
required VoidCallback callback,
required AppRef appRef,
required super.scope,
}) : super._(context: context, callback: callback);
}) : super._(
context: context,
callback: callback,
appRef: appRef,
);

@override
ScopedValueContainer get container {
Expand All @@ -55,11 +64,13 @@ class _ScopedValueListenerOnPage extends ScopedValueListener {
_ScopedValueListenerOnPage._({
required BuildContext context,
required VoidCallback callback,
required AppRef appRef,
ScopedValueContainer? container,
ScopedLoggerScope scope = ScopedLoggerScope.page,
}) : super._(
context: context,
callback: callback,
appRef: appRef,
container: container,
scope: scope,
);
Expand Down Expand Up @@ -91,12 +102,14 @@ class _ScopedValueListenerOnWidget extends ScopedValueListener {
_ScopedValueListenerOnWidget._({
required BuildContext context,
required VoidCallback callback,
required AppRef appRef,
ScopedValueContainer? container,
ScopedLoggerScope scope = ScopedLoggerScope.widget,
}) : super._(
context: context,
callback: callback,
container: container,
appRef: appRef,
scope: scope,
);

Expand Down Expand Up @@ -138,9 +151,11 @@ abstract class ScopedValueListener {
ScopedValueListener._({
required BuildContext context,
required VoidCallback callback,
required AppRef appRef,
ScopedValueContainer? container,
ScopedLoggerScope scope = ScopedLoggerScope.widget,
}) : _scope = scope,
_appRef = appRef,
_context = context,
_callback = callback,
_container = container;
Expand All @@ -151,9 +166,10 @@ abstract class ScopedValueListener {
ScopedValueContainer? _containerCache;
final Set<ScopedValueState> _watched = {};

AppRef get _appRef {
return _AppScopedScope.of(_context).widget.appRef;
}
late final AppRef _appRef;
// AppRef get _appRef {
// return _AppScopedScope.of(_context).widget.appRef;
// }

@protected
final ScopedLoggerScope _scope;
Expand Down

0 comments on commit 5299d98

Please sign in to comment.