Skip to content

Commit 05c1cbc

Browse files
committed
chore: dart format
1 parent 6221028 commit 05c1cbc

File tree

5 files changed

+867
-674
lines changed

5 files changed

+867
-674
lines changed

packages/go_router/lib/src/configuration.dart

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import 'router.dart';
1818
import 'state.dart';
1919

2020
/// The signature of the redirect callback.
21-
typedef GoRouterRedirect = FutureOr<String?> Function(
22-
BuildContext context, GoRouterState state);
21+
typedef GoRouterRedirect =
22+
FutureOr<String?> Function(BuildContext context, GoRouterState state);
2323

2424
typedef _NamedPath = ({String path, bool caseSensitive});
2525

@@ -448,18 +448,28 @@ class RouteConfiguration {
448448
return routeLevelRedirectResult
449449
.then<RouteMatchList>(processRouteLevelRedirect)
450450
.catchError((Object error) {
451-
final GoException goException = error is GoException
452-
? error
453-
: GoException('Exception during route redirect: $error');
454-
return _errorRouteMatchList(prevMatchList.uri, goException,
455-
extra: prevMatchList.extra);
456-
});
451+
final GoException goException =
452+
error is GoException
453+
? error
454+
: GoException(
455+
'Exception during route redirect: $error',
456+
);
457+
return _errorRouteMatchList(
458+
prevMatchList.uri,
459+
goException,
460+
extra: prevMatchList.extra,
461+
);
462+
});
457463
} catch (exception) {
458-
final GoException goException = exception is GoException
459-
? exception
460-
: GoException('Exception during route redirect: $exception');
461-
return _errorRouteMatchList(prevMatchList.uri, goException,
462-
extra: prevMatchList.extra);
464+
final GoException goException =
465+
exception is GoException
466+
? exception
467+
: GoException('Exception during route redirect: $exception');
468+
return _errorRouteMatchList(
469+
prevMatchList.uri,
470+
goException,
471+
extra: prevMatchList.extra,
472+
);
463473
}
464474
}
465475

@@ -505,29 +515,28 @@ class RouteConfiguration {
505515
final RouteBase route = match.route;
506516
try {
507517
final FutureOr<String?> routeRedirectResult = _runInRouterZone(() {
508-
return route.redirect!.call(
509-
context,
510-
match.buildState(this, matchList),
511-
);
518+
return route.redirect!.call(context, match.buildState(this, matchList));
512519
});
513520
if (routeRedirectResult is String?) {
514521
return processRouteRedirect(routeRedirectResult);
515522
}
516-
return routeRedirectResult
517-
.then<String?>(processRouteRedirect)
518-
.catchError((Object error) {
519-
// Convert any exception during async route redirect to a GoException
520-
final GoException goException = error is GoException
521-
? error
522-
: GoException('Exception during route redirect: $error');
523-
// Throw the GoException to be caught by the redirect handling chain
524-
throw goException;
525-
});
523+
return routeRedirectResult.then<String?>(processRouteRedirect).catchError(
524+
(Object error) {
525+
// Convert any exception during async route redirect to a GoException
526+
final GoException goException =
527+
error is GoException
528+
? error
529+
: GoException('Exception during route redirect: $error');
530+
// Throw the GoException to be caught by the redirect handling chain
531+
throw goException;
532+
},
533+
);
526534
} catch (exception) {
527535
// Convert any exception during route redirect to a GoException
528-
final GoException goException = exception is GoException
529-
? exception
530-
: GoException('Exception during route redirect: $exception');
536+
final GoException goException =
537+
exception is GoException
538+
? exception
539+
: GoException('Exception during route redirect: $exception');
531540
// Throw the GoException to be caught by the redirect handling chain
532541
throw goException;
533542
}
@@ -543,9 +552,10 @@ class RouteConfiguration {
543552
_addRedirect(redirectHistory, newMatch, previousLocation);
544553
return newMatch;
545554
} catch (exception) {
546-
final GoException goException = exception is GoException
547-
? exception
548-
: GoException('Exception during redirect: $exception');
555+
final GoException goException =
556+
exception is GoException
557+
? exception
558+
: GoException('Exception during redirect: $exception');
549559
log('Redirection exception: ${goException.message}');
550560
return _errorRouteMatchList(previousLocation, goException);
551561
}
@@ -561,18 +571,12 @@ class RouteConfiguration {
561571
) {
562572
if (redirects.contains(newMatch)) {
563573
throw GoException(
564-
'redirect loop detected ${_formatRedirectionHistory(<RouteMatchList>[
565-
...redirects,
566-
newMatch
567-
])}',
574+
'redirect loop detected ${_formatRedirectionHistory(<RouteMatchList>[...redirects, newMatch])}',
568575
);
569576
}
570577
if (redirects.length > _routingConfig.value.redirectLimit) {
571578
throw GoException(
572-
'too many redirects ${_formatRedirectionHistory(<RouteMatchList>[
573-
...redirects,
574-
newMatch
575-
])}',
579+
'too many redirects ${_formatRedirectionHistory(<RouteMatchList>[...redirects, newMatch])}',
576580
);
577581
}
578582

@@ -605,14 +609,13 @@ class RouteConfiguration {
605609
(Object error, StackTrace stack) {
606610
errorOccurred = true;
607611
// Convert any exception during redirect to a GoException and rethrow
608-
final GoException goException = error is GoException
609-
? error
610-
: GoException('Exception during redirect: $error');
612+
final GoException goException =
613+
error is GoException
614+
? error
615+
: GoException('Exception during redirect: $error');
611616
throw goException;
612617
},
613-
zoneValues: <Object?, Object?>{
614-
currentRouterKey: router,
615-
},
618+
zoneValues: <Object?, Object?>{currentRouterKey: router},
616619
);
617620

618621
if (errorOccurred) {

packages/go_router/lib/src/parser.dart

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import 'router.dart';
2222
///
2323
/// The returned [RouteMatchList] is used as parsed result for the
2424
/// [GoRouterDelegate].
25-
typedef ParserExceptionHandler = RouteMatchList Function(
26-
BuildContext context,
27-
RouteMatchList routeMatchList,
28-
);
25+
typedef ParserExceptionHandler =
26+
RouteMatchList Function(
27+
BuildContext context,
28+
RouteMatchList routeMatchList,
29+
);
2930

3031
/// Converts between incoming URLs and a [RouteMatchList] using [RouteMatcher].
3132
/// Also performs redirection using [RouteRedirector].
@@ -181,9 +182,10 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
181182
}
182183
return redirectedFuture.catchError((Object error) {
183184
// Convert any exception during redirect to a GoException
184-
final GoException goException = error is GoException
185-
? error
186-
: GoException('Exception during redirect: $error');
185+
final GoException goException =
186+
error is GoException
187+
? error
188+
: GoException('Exception during redirect: $error');
187189
// Return an error match list instead of throwing
188190
return RouteMatchList(
189191
matches: const <RouteMatch>[],
@@ -195,17 +197,20 @@ class GoRouteInformationParser extends RouteInformationParser<RouteMatchList> {
195197
});
196198
} catch (exception) {
197199
// Convert any exception during redirect to a GoException
198-
final GoException goException = exception is GoException
199-
? exception
200-
: GoException('Exception during redirect: $exception');
200+
final GoException goException =
201+
exception is GoException
202+
? exception
203+
: GoException('Exception during redirect: $exception');
201204
// Return an error match list instead of throwing
202-
return SynchronousFuture<RouteMatchList>(RouteMatchList(
203-
matches: const <RouteMatch>[],
204-
extra: routeMatch.extra,
205-
error: goException,
206-
uri: routeMatch.uri,
207-
pathParameters: const <String, String>{},
208-
));
205+
return SynchronousFuture<RouteMatchList>(
206+
RouteMatchList(
207+
matches: const <RouteMatch>[],
208+
extra: routeMatch.extra,
209+
error: goException,
210+
uri: routeMatch.uri,
211+
pathParameters: const <String, String>{},
212+
),
213+
);
209214
}
210215
}
211216

packages/go_router/lib/src/router.dart

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import 'state.dart';
2222
/// The function signature of [GoRouter.onException].
2323
///
2424
/// Use `state.error` to access the exception.
25-
typedef GoExceptionHandler = void Function(
26-
BuildContext context, GoRouterState state, GoRouter router);
25+
typedef GoExceptionHandler =
26+
void Function(BuildContext context, GoRouterState state, GoRouter router);
2727

2828
/// A set of parameters that defines routing in GoRouter.
2929
///
@@ -46,8 +46,7 @@ class RoutingConfig {
4646
static FutureOr<String?> _defaultRedirect(
4747
BuildContext context,
4848
GoRouterState state,
49-
) =>
50-
null;
49+
) => null;
5150

5251
/// The supported routes.
5352
///
@@ -184,23 +183,23 @@ class GoRouter implements RouterConfig<RouteMatchList> {
184183
GlobalKey<NavigatorState>? navigatorKey,
185184
String? restorationScopeId,
186185
bool requestFocus = true,
187-
}) : _routingConfig = routingConfig,
188-
backButtonDispatcher = RootBackButtonDispatcher(),
189-
assert(
190-
initialExtra == null || initialLocation != null,
191-
'initialLocation must be set in order to use initialExtra',
192-
),
193-
assert(
194-
!overridePlatformDefaultLocation || initialLocation != null,
195-
'Initial location must be set to override platform default',
196-
),
197-
assert(
198-
(onException == null ? 0 : 1) +
199-
(errorPageBuilder == null ? 0 : 1) +
200-
(errorBuilder == null ? 0 : 1) <
201-
2,
202-
'Only one of onException, errorPageBuilder, or errorBuilder can be provided.',
203-
) {
186+
}) : _routingConfig = routingConfig,
187+
backButtonDispatcher = RootBackButtonDispatcher(),
188+
assert(
189+
initialExtra == null || initialLocation != null,
190+
'initialLocation must be set in order to use initialExtra',
191+
),
192+
assert(
193+
!overridePlatformDefaultLocation || initialLocation != null,
194+
'Initial location must be set to override platform default',
195+
),
196+
assert(
197+
(onException == null ? 0 : 1) +
198+
(errorPageBuilder == null ? 0 : 1) +
199+
(errorBuilder == null ? 0 : 1) <
200+
2,
201+
'Only one of onException, errorPageBuilder, or errorBuilder can be provided.',
202+
) {
204203
setLogging(enabled: debugLogDiagnostics);
205204
WidgetsFlutterBinding.ensureInitialized();
206205

@@ -254,8 +253,9 @@ class GoRouter implements RouterConfig<RouteMatchList> {
254253
requestFocus: requestFocus,
255254
// wrap the returned Navigator to enable GoRouter.of(context).go() et al,
256255
// allowing the caller to wrap the navigator themselves
257-
builderWithNav: (BuildContext context, Widget child) =>
258-
InheritedGoRouter(goRouter: this, child: child),
256+
builderWithNav:
257+
(BuildContext context, Widget child) =>
258+
InheritedGoRouter(goRouter: this, child: child),
259259
);
260260

261261
assert(() {
@@ -345,13 +345,12 @@ class GoRouter implements RouterConfig<RouteMatchList> {
345345
Map<String, String> pathParameters = const <String, String>{},
346346
Map<String, dynamic> queryParameters = const <String, dynamic>{},
347347
String? fragment,
348-
}) =>
349-
configuration.namedLocation(
350-
name,
351-
pathParameters: pathParameters,
352-
queryParameters: queryParameters,
353-
fragment: fragment,
354-
);
348+
}) => configuration.namedLocation(
349+
name,
350+
pathParameters: pathParameters,
351+
queryParameters: queryParameters,
352+
fragment: fragment,
353+
);
355354

356355
/// Navigate to a URI location w/ optional query parameters, e.g.
357356
/// `/family/f2/person/p1?color=blue`
@@ -379,17 +378,16 @@ class GoRouter implements RouterConfig<RouteMatchList> {
379378
Object? extra,
380379
String? fragment,
381380
}) =>
382-
383-
/// Construct location with optional fragment, using null-safe navigation
384-
go(
385-
namedLocation(
386-
name,
387-
pathParameters: pathParameters,
388-
queryParameters: queryParameters,
389-
fragment: fragment,
390-
),
391-
extra: extra,
392-
);
381+
/// Construct location with optional fragment, using null-safe navigation
382+
go(
383+
namedLocation(
384+
name,
385+
pathParameters: pathParameters,
386+
queryParameters: queryParameters,
387+
fragment: fragment,
388+
),
389+
extra: extra,
390+
);
393391

394392
/// Push a URI location onto the page stack w/ optional query parameters, e.g.
395393
/// `/family/f2/person/p1?color=blue`.
@@ -416,15 +414,14 @@ class GoRouter implements RouterConfig<RouteMatchList> {
416414
Map<String, String> pathParameters = const <String, String>{},
417415
Map<String, dynamic> queryParameters = const <String, dynamic>{},
418416
Object? extra,
419-
}) =>
420-
push<T>(
421-
namedLocation(
422-
name,
423-
pathParameters: pathParameters,
424-
queryParameters: queryParameters,
425-
),
426-
extra: extra,
427-
);
417+
}) => push<T>(
418+
namedLocation(
419+
name,
420+
pathParameters: pathParameters,
421+
queryParameters: queryParameters,
422+
),
423+
extra: extra,
424+
);
428425

429426
/// Replaces the top-most page of the page stack with the given URL location
430427
/// w/ optional query parameters, e.g. `/family/f2/person/p1?color=blue`.
@@ -552,9 +549,11 @@ class GoRouter implements RouterConfig<RouteMatchList> {
552549

553550
/// The current GoRouter in the widget tree, if any.
554551
static GoRouter? maybeOf(BuildContext context) {
555-
final InheritedGoRouter? inherited = context
556-
.getElementForInheritedWidgetOfExactType<InheritedGoRouter>()
557-
?.widget as InheritedGoRouter?;
552+
final InheritedGoRouter? inherited =
553+
context
554+
.getElementForInheritedWidgetOfExactType<InheritedGoRouter>()
555+
?.widget
556+
as InheritedGoRouter?;
558557
if (inherited != null) {
559558
return inherited.goRouter;
560559
}

0 commit comments

Comments
 (0)