Skip to content

Commit 6a555c0

Browse files
fix: make telemetry attributes a Map<String, dynamic>
Co-authored-by: MasterMarcoHD <MasterMarcoHD@users.noreply.github.com>
1 parent 9976d72 commit 6a555c0

22 files changed

+455
-66
lines changed

.fvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"flutter": "3.35.7"
2+
"flutter": "stable"
33
}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"dart.flutterSdkPath": ".fvm/versions/3.35.7",
2+
"dart.flutterSdkPath": ".fvm/versions/stable",
33
"dart.sdkPath": ".fvm/flutter_sdk/bin/cache/dart-sdk"
44
}

example/routing.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class _TestView extends Leaf<String> {
4242
}
4343

4444
@override
45-
FutureOr<String> build(RouteContext ctx) {
45+
FutureOr<String> content(RouteContext ctx) {
4646
return 'Built View';
4747
}
4848
}

lib/src/domain/models/model.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
import 'package:meta/meta.dart';
2-
31
// this is the base class.
42
// ignore: models_must_extend_model
53
/// Marker class for all models used in the grumpy.
64
abstract class Model {
75
/// Marker class for all models used in the grumpy.
86
const Model();
9-
10-
@override
11-
@mustBeOverridden
12-
String toString();
137
}

lib/src/domain/models/optimistic_policy.freezed.dart

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/domain/models/retry_policy.freezed.dart

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/domain/models/route.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Route<T, Config extends Object> extends Model {
2121
///
2222
/// If any [Middleware.canActivate] returns `false`, the route is considered
2323
/// not accessible and the navigation should be aborted or redirected if [Middleware.redirectTo] is set.
24-
final List<Middleware> middleware;
24+
final List<Middleware<T, Config>> middleware;
2525

2626
/// Child routes that are matched relative to this route's [path].
2727
///
Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
import 'package:meta/meta.dart';
1+
import 'package:freezed_annotation/freezed_annotation.dart';
22
import 'package:grumpy/grumpy.dart';
33

4+
part 'route_context.freezed.dart';
5+
part 'route_context.g.dart';
6+
47
/// Contextual information about the current routing state.
5-
@immutable
6-
class RouteContext extends Model {
7-
/// The full path of the current route.
8-
final String fullPath;
8+
@freezed
9+
abstract class RouteContext extends Model with _$RouteContext {
10+
const RouteContext._();
911

10-
/// The path parameters extracted from the route.
11-
final Map<String, String> pathParams;
12+
/// Contextual information about the current routing state.
13+
const factory RouteContext({
14+
/// The full path of the current route.
15+
required String fullPath,
1216

13-
/// The query parameters extracted from the route.
14-
final Map<String, String> queryParams;
17+
/// The path parameters extracted from the route.
18+
@Default({}) Map<String, String> pathParams,
1519

16-
/// The query parameters extracted from the route, allowing multiple values per key.
17-
final Map<String, List<String>> queryParamsAll;
20+
/// The query parameters extracted from the route.
21+
@Default({}) Map<String, String> queryParams,
1822

19-
/// The fragment identifier from the URL, if any.
20-
final String fragment;
23+
/// The query parameters extracted from the route, allowing multiple values per key.
24+
@Default({}) Map<String, List<String>> queryParamsAll,
2125

22-
/// Contextual information about the current routing state.
23-
const RouteContext({
24-
required this.fullPath,
25-
this.pathParams = const {},
26-
this.queryParams = const {},
27-
this.queryParamsAll = const {},
28-
this.fragment = '',
29-
});
26+
/// The fragment identifier from the URL, if any.
27+
@Default('') String fragment,
28+
}) = _RouteContext;
3029

3130
/// Parses the [fullPath] into a [Uri] object.
3231
Uri get uri => Uri.parse(fullPath);
@@ -52,8 +51,24 @@ class RouteContext extends Model {
5251
/// Checks if a parameter with the given [key] exists in either path or query parameters.
5352
bool has(String key) => hasPathParam(key) || hasQueryParam(key);
5453

55-
@override
56-
String toString() {
57-
return 'RoutingContext(fullPath: $fullPath, pathParams: $pathParams, queryParams: $queryParams , fragment: $fragment, queryParamsAll: $queryParamsAll)';
54+
/// Creates a new [RouteContext] from a JSON map.
55+
factory RouteContext.fromJson(Map<String, dynamic> json) =>
56+
_$RouteContextFromJson(json);
57+
58+
/// Creates a new [RouteContext] from a [Uri] object.
59+
factory RouteContext.fromUri(Uri uri) {
60+
return RouteContext(
61+
fullPath: uri.toString(),
62+
pathParams: {},
63+
queryParams: uri.queryParameters,
64+
queryParamsAll: uri.queryParametersAll,
65+
fragment: uri.fragment,
66+
);
67+
}
68+
69+
/// Parses a URI string into a [RouteContext].
70+
factory RouteContext.parse(String uriString) {
71+
final uri = Uri.parse(uriString);
72+
return RouteContext.fromUri(uri);
5873
}
5974
}

0 commit comments

Comments
 (0)