Skip to content

Commit c635c59

Browse files
committed
chore: appease analyzer
1 parent 087f402 commit c635c59

14 files changed

+71
-10
lines changed

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ plugins:
1111
base_class:
1212
ignorable: true
1313
enabled: true
14+
domain_factory_from_di: true
15+
prefer_domain_di_factory: true
1416
analyzer:
1517
exclude:
1618
- "**/*.g.dart"

lib/src/domain/services/analytics_service.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,14 @@ abstract class AnalyticsService extends Service {
142142
Future<void> groupUser(String groupId, {Map<String, dynamic>? traits});
143143
@override
144144
String get group => '${super.group}.AnalyticsService';
145+
146+
/// Internal constructor for subclasses.
147+
AnalyticsService.internal();
148+
149+
/// Returns the DI-registered implementation of [AnalyticsService].
150+
///
151+
/// Shorthand for [Service.get].
152+
factory AnalyticsService() {
153+
return Service.get<AnalyticsService>();
154+
}
145155
}

lib/src/domain/services/routing_service.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:grumpy/grumpy.dart';
4+
import 'package:meta/meta.dart';
45

56
/// A service responsible for managing application routing.
67
/// Note: This router is only responsible for marking routes as active and
@@ -12,14 +13,21 @@ abstract class RoutingService<T, Config extends Object> extends Service {
1213
/// Returns the root route of the application with all its nested routes expanded.
1314
Route<T, Config> get root;
1415

16+
/// Required for the factory pattern to work.
17+
@internal
18+
RoutingService.internal();
19+
1520
/// Navigates to the specified [path] and invokes the [callback] with the built presentation.
1621
/// If [skipPreview] is true, the preview phase is skipped and [callback] is called only after the final build phase.
1722
Future<void> navigate(
1823
String path, {
1924
bool skipPreview = false,
20-
required void Function(T, bool) callback,
25+
void Function(T, bool) callback = noopCallback,
2126
});
2227

28+
/// Default callback for [navigate].
29+
static void noopCallback(dynamic _, bool _) {}
30+
2331
/// Checks if the specified [path] is currently active.
2432
///
2533
/// If [exact] is true (default), checks for an exact match; otherwise, checks for a partial match.
@@ -56,6 +64,16 @@ abstract class RoutingService<T, Config extends Object> extends Service {
5664
StreamSubscription<ViewChangedEvent<T, Config>> onViewChanged(
5765
void Function(ViewChangedEvent<T, Config>) callback,
5866
);
67+
68+
/// A stream of all view change events.
69+
Stream<ViewChangedEvent<T, Config>> get viewStream;
70+
71+
/// Returns the DI-registered implementation of [RoutingService].
72+
///
73+
/// Shorthand for [Service.get].
74+
factory RoutingService() {
75+
return Service.get<RoutingService<T, Config>>();
76+
}
5977
}
6078

6179
/// An event representing a change in the view rendered by the [RoutingService].

lib/src/domain/services/telemetry_service.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,14 @@ abstract class TelemetryService extends Service {
122122
void addSpanAttribute(String key, String value);
123123
@override
124124
String get group => '${super.group}.TelemetryService';
125+
126+
/// Internal constructor for subclasses.
127+
TelemetryService.internal();
128+
129+
/// Returns the DI-registered implementation of [TelemetryService].
130+
///
131+
/// Shorthand for [Service.get].
132+
factory TelemetryService() {
133+
return Service.get<TelemetryService>();
134+
}
125135
}

lib/src/infra/services/noop_analytics_service.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import 'package:grumpy/grumpy.dart';
22

33
/// A no-operation implementation of [AnalyticsService].
44
class NoopAnalyticsService extends AnalyticsService {
5+
/// A no-operation implementation of [AnalyticsService].
6+
NoopAnalyticsService() : super.internal();
7+
58
@override
69
noSuchMethod(Invocation invocation) {
710
log('NoopAnalyticsService: ${invocation.memberName} called.');

lib/src/infra/services/noop_telemetry_service.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import 'package:grumpy/grumpy.dart';
44

55
/// A no-operation implementation of [TelemetryService].
66
class NoopTelemetryService extends TelemetryService {
7+
/// A no-operation implementation of [TelemetryService].
8+
NoopTelemetryService() : super.internal();
9+
710
@override
811
noSuchMethod(Invocation invocation) {
912
log('NoopTelemetryService: ${invocation.memberName} called.');

lib/src/infra/services/routing_kit_routing_service.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class RoutingKitRoutingService<T, Config extends Object>
2727
StreamController<ViewChangedEvent<T, Config>>.broadcast();
2828

2929
/// [RoutingService] impementation that uses RoutingKit for route parsing and matching.
30-
RoutingKitRoutingService(this.rootModule, {this.caseSensitive = false}) {
30+
RoutingKitRoutingService(this.rootModule, {this.caseSensitive = false})
31+
: super.internal() {
3132
initialize();
3233
}
3334

@@ -127,12 +128,10 @@ class RoutingKitRoutingService<T, Config extends Object>
127128
Future<void> navigate(
128129
String path, {
129130
bool skipPreview = false,
130-
required void Function(T, bool) callback,
131+
void Function(T, bool) callback = RoutingService.noopCallback,
131132
}) async {
132133
void handler(T view, bool isPreview) {
133-
log(
134-
'View changed: isPreview=$isPreview, view=${view.runtimeType} for path: $path',
135-
);
134+
log('View changed: isPreview=$isPreview, view=$view for path: $path');
136135

137136
_viewChangeController.add((
138137
view: view,
@@ -291,4 +290,8 @@ class RoutingKitRoutingService<T, Config extends Object>
291290
StreamSubscription<ViewChangedEvent<T, Config>> onViewChanged(
292291
void Function(ViewChangedEvent<T, Config>) callback,
293292
) => _viewChangeController.stream.listen(callback);
293+
294+
@override
295+
Stream<ViewChangedEvent<T, Config>> get viewStream =>
296+
_viewChangeController.stream.asBroadcastStream();
294297
}

lib/src/utils/mutation_mixins.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mixin MutationMixins<T> on Repo<T>, RepoLifecycleHooksMixin<T>, TelemetryMixin {
5959

6060
final stateVersion = _stateVersion;
6161

62-
final analytics = Service.get<AnalyticsService>();
62+
final analytics = AnalyticsService();
6363

6464
try {
6565
log('Starting mutation $name');
@@ -117,7 +117,7 @@ mixin MutationMixins<T> on Repo<T>, RepoLifecycleHooksMixin<T>, TelemetryMixin {
117117
final snapshot = state;
118118
_applyOptimistics(optimisticPolicy);
119119
final stateVersion = _stateVersion;
120-
final analytics = Service.get<AnalyticsService>();
120+
final analytics = AnalyticsService();
121121

122122
try {
123123
log('Starting action $name');

lib/src/utils/query_mixins.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ mixin QueryMixin<T> on Repo<T>, RepoLifecycleHooksMixin<T>, TelemetryMixin {
113113
);
114114
}
115115

116-
final analytics = Service.get<AnalyticsService>();
116+
final analytics = AnalyticsService();
117117
if (analyticsAction != null) {
118118
await analytics.trackEvent(
119119
analyticsAction,

lib/src/utils/telemetry_mixin.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mixin TelemetryMixin {
1212
FutureOr<T> Function() function, {
1313
Map<String, dynamic>? attributes,
1414
}) async {
15-
final telemetry = Service.get<TelemetryService>();
15+
final telemetry = TelemetryService();
1616

1717
return telemetry.runSpan(name, function, attributes: attributes);
1818
}

0 commit comments

Comments
 (0)