Skip to content

Commit

Permalink
fix: Change the execution location of MasamuneAdapter.onInitScope.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Jul 20, 2023
1 parent b3c1f91 commit 87e58ff
Show file tree
Hide file tree
Showing 21 changed files with 338 additions and 271 deletions.
12 changes: 1 addition & 11 deletions packages/masamune/lib/src/masamune_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class MasamuneAdapterScope<TAdapter extends MasamuneAdapter>
/// ```
const MasamuneAdapterScope({
super.key,
this.onInit,
required this.child,
required this.adapter,
});
Expand All @@ -176,15 +175,6 @@ class MasamuneAdapterScope<TAdapter extends MasamuneAdapter>
/// アプリ全体に設定する[MasamuneAdapter]
final TAdapter adapter;

/// Describe the process when this widget is initialized.
///
/// [MasamuneAdapter] is passed to [adapter].
///
/// このウィジェットが初期化されたときの処理を記述します。
///
/// [adapter][MasamuneAdapter]が渡されます。
final void Function(TAdapter adapter)? onInit;

/// By passing [context], the [MasamuneAdapter] set in [MasamuneAdapterScope] can be obtained.
///
/// If the ancestor does not have [MasamuneAdapterScope], an error will occur.
Expand All @@ -211,7 +201,7 @@ class _MasamuneAdapterScopeState<TAdapter extends MasamuneAdapter>
@override
void initState() {
super.initState();
widget.onInit?.call(widget.adapter);
widget.adapter.onInitScope(widget.adapter);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/masamune/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ packages:
path: "../katana_scoped"
relative: true
source: path
version: "2.0.11"
version: "2.0.16"
katana_shorten:
dependency: "direct main"
description:
Expand Down
12 changes: 10 additions & 2 deletions packages/masamune_agora/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.1.16"
version: "2.2.0"
masamune_annotation:
dependency: "direct overridden"
description:
Expand Down Expand Up @@ -720,6 +720,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.3"
pin_input_text_field:
dependency: transitive
description:
name: pin_input_text_field
sha256: "8d6fc670aa673a4df5976086f0e8039972a5b2bcb783c8db8dd3b9b4b072ca90"
url: "https://pub.dev"
source: hosted
version: "4.5.1"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -1039,4 +1047,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.0.0 <4.0.0"
flutter: ">=3.3.0"
flutter: ">=3.7.0"
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class AgoraMasamuneAdapter extends MasamuneAdapter {
Widget onBuildApp(BuildContext context, Widget app) {
return MasamuneAdapterScope<AgoraMasamuneAdapter>(
adapter: this,
onInit: onInitScope,
child: app,
);
}
Expand Down
22 changes: 15 additions & 7 deletions packages/masamune_agora/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ packages:
path: "../katana_form"
relative: true
source: path
version: "2.4.7"
version: "2.5.1"
katana_functions:
dependency: "direct overridden"
description:
Expand Down Expand Up @@ -364,21 +364,21 @@ packages:
path: "../katana_router"
relative: true
source: path
version: "2.0.15"
version: "2.0.16"
katana_router_annotation:
dependency: "direct overridden"
description:
path: "../katana_router_annotation"
relative: true
source: path
version: "2.0.13"
version: "2.0.14"
katana_scoped:
dependency: "direct overridden"
description:
path: "../katana_scoped"
relative: true
source: path
version: "2.0.11"
version: "2.0.16"
katana_shorten:
dependency: "direct overridden"
description:
Expand Down Expand Up @@ -413,7 +413,7 @@ packages:
path: "../katana_ui"
relative: true
source: path
version: "2.1.7"
version: "2.2.0"
lints:
dependency: transitive
description:
Expand All @@ -436,7 +436,7 @@ packages:
path: "../masamune"
relative: true
source: path
version: "2.2.8"
version: "2.2.16"
masamune_annotation:
dependency: "direct overridden"
description:
Expand Down Expand Up @@ -588,6 +588,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.3"
pin_input_text_field:
dependency: transitive
description:
name: pin_input_text_field
sha256: "8d6fc670aa673a4df5976086f0e8039972a5b2bcb783c8db8dd3b9b4b072ca90"
url: "https://pub.dev"
source: hosted
version: "4.5.1"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -931,4 +939,4 @@ packages:
version: "3.1.2"
sdks:
dart: ">=3.0.0 <3.2.0"
flutter: ">=3.3.0"
flutter: ">=3.7.0"
39 changes: 20 additions & 19 deletions packages/masamune_location/lib/src/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class Location
Timer? _timer;
Duration _updateInterval = const Duration(minutes: 1);
bool _updated = false;
Completer<void>? _completer;
Completer<void>? _listenCompleter;
Completer<void>? _initializeCompleter;
// ignore: cancel_subscriptions
StreamSubscription<Position>? _positionStreamSubscription;

Expand Down Expand Up @@ -102,10 +103,10 @@ class Location
Future<void> initialize({
Duration timeout = const Duration(seconds: 60),
}) async {
if (_completer != null) {
return _completer?.future;
if (_initializeCompleter != null) {
return _initializeCompleter?.future;
}
_completer = Completer<void>();
_initializeCompleter = Completer<void>();
try {
if (!await Geolocator.isLocationServiceEnabled().timeout(timeout)) {
throw Exception(
Expand All @@ -125,15 +126,15 @@ class Location
}
_initialized = true;
notifyListeners();
_completer?.complete();
_completer = null;
_initializeCompleter?.complete();
_initializeCompleter = null;
} catch (e) {
_completer?.completeError(e);
_completer = null;
_initializeCompleter?.completeError(e);
_initializeCompleter = null;
rethrow;
} finally {
_completer?.complete();
_completer = null;
_initializeCompleter?.complete();
_initializeCompleter = null;
}
}

Expand All @@ -158,13 +159,13 @@ class Location
Duration updateInterval = const Duration(minutes: 1),
Duration timeout = const Duration(seconds: 60),
}) async {
if (_completer != null) {
return _completer?.future;
if (_listenCompleter != null) {
return _listenCompleter?.future;
}
if (_updateInterval == updateInterval && listening) {
return;
}
_completer = Completer<void>();
_listenCompleter = Completer<void>();
_updateInterval = updateInterval;
try {
await initialize(timeout: timeout);
Expand Down Expand Up @@ -195,15 +196,15 @@ class Location
notifyListeners();
});
notifyListeners();
_completer?.complete();
_completer = null;
_listenCompleter?.complete();
_listenCompleter = null;
} catch (e) {
_completer?.completeError(e);
_completer = null;
_listenCompleter?.completeError(e);
_listenCompleter = null;
rethrow;
} finally {
_completer?.complete();
_completer = null;
_listenCompleter?.complete();
_listenCompleter = null;
}
}

Expand Down
Loading

0 comments on commit 87e58ff

Please sign in to comment.