diff --git a/package/lib/src/beam_guard.dart b/package/lib/src/beam_guard.dart index c910fac..67facb7 100644 --- a/package/lib/src/beam_guard.dart +++ b/package/lib/src/beam_guard.dart @@ -122,7 +122,8 @@ class BeamGuard { onCheckFailed?.call(context, target); if (showPage != null) { - final redirectBeamStack = GuardShowPage(target.state.routeInformation, showPage!); + final redirectBeamStack = + GuardShowPage(target.state.routeInformation, showPage!); if (replaceCurrentStack) { delegate.beamToReplacement(redirectBeamStack); } else { @@ -140,11 +141,13 @@ class BeamGuard { if (beamTo != null) { final redirectBeamStack = beamTo!(context, origin, target, deepLink); - if (redirectBeamStack.state.routeInformation.uri == target.state.routeInformation.uri) { + if (redirectBeamStack.state.routeInformation.uri == + target.state.routeInformation.uri) { // just block if this will produce an immediate infinite loop return true; } - if (redirectBeamStack.state.routeInformation.uri == origin.state.routeInformation.uri) { + if (redirectBeamStack.state.routeInformation.uri == + origin.state.routeInformation.uri) { // just block if redirect is the current route return true; } diff --git a/package/lib/src/beam_interceptor_pop_scope.dart b/package/lib/src/beam_interceptor_pop_scope.dart index f58a3f9..2965948 100644 --- a/package/lib/src/beam_interceptor_pop_scope.dart +++ b/package/lib/src/beam_interceptor_pop_scope.dart @@ -37,7 +37,8 @@ class BeamInterceptorPopScope extends StatefulWidget { final BeamerDelegate? beamerDelegate; @override - State createState() => _BeamInterceptorPopScopeState(); + State createState() => + _BeamInterceptorPopScopeState(); } class _BeamInterceptorPopScopeState extends State { diff --git a/package/lib/src/beam_page.dart b/package/lib/src/beam_page.dart index df2213a..9e5581b 100644 --- a/package/lib/src/beam_page.dart +++ b/package/lib/src/beam_page.dart @@ -85,11 +85,15 @@ class BeamPage extends Page { // Take the history element that is being popped and the one before // as they will be compared later on to fine-tune the pop experience. final poppedHistoryElement = delegate.removeLastHistoryElement()!; - final previousHistoryElement = delegate.beamingHistory.isNotEmpty ? delegate.beamingHistory.last.history.last : null; + final previousHistoryElement = delegate.beamingHistory.isNotEmpty + ? delegate.beamingHistory.last.history.last + : null; // Convert both to Uri as their path and query will be compared. final poppedUri = poppedHistoryElement.routeInformation.uri; - final previousUri = previousHistoryElement != null ? previousHistoryElement.routeInformation.uri : Uri.parse(delegate.initialPath); + final previousUri = previousHistoryElement != null + ? previousHistoryElement.routeInformation.uri + : Uri.parse(delegate.initialPath); final poppedPathSegments = poppedUri.pathSegments; final poppedQueryParameters = poppedUri.queryParameters; @@ -120,7 +124,8 @@ class BeamPage extends Page { // Otherwise, find the route information with popPath in history. RouteInformation? lastRouteInformation; if (popPath == previousUri.path) { - lastRouteInformation = delegate.removeLastHistoryElement()?.routeInformation; + lastRouteInformation = + delegate.removeLastHistoryElement()?.routeInformation; } else { // find the last var found = false; @@ -222,7 +227,8 @@ class BeamPage extends Page { /// `context` is the build context. /// `child` is the child of this [BeamPage] /// `settings` will be passed to [PageRoute] constructor. - final Route Function(BuildContext context, RouteSettings settings, Widget child)? routeBuilder; + final Route Function( + BuildContext context, RouteSettings settings, Widget child)? routeBuilder; /// Whether to present current [BeamPage] as a fullscreen dialog /// @@ -260,7 +266,8 @@ class BeamPage extends Page { settings: this, pageBuilder: (_, __, ___) => child, transitionDuration: transitionDuration ?? Duration(milliseconds: 300), - reverseTransitionDuration: reverseTransitionDuration ?? Duration(milliseconds: 300), + reverseTransitionDuration: + reverseTransitionDuration ?? Duration(milliseconds: 300), transitionsBuilder: (_, animation, __, child) => FadeTransition( opacity: animation, child: child, @@ -273,9 +280,12 @@ class BeamPage extends Page { settings: this, pageBuilder: (_, __, ___) => child, transitionDuration: transitionDuration ?? Duration(milliseconds: 300), - reverseTransitionDuration: reverseTransitionDuration ?? Duration(milliseconds: 300), + reverseTransitionDuration: + reverseTransitionDuration ?? Duration(milliseconds: 300), transitionsBuilder: (_, animation, __, child) => SlideTransition( - position: animation.drive(Tween(begin: const Offset(0, 1), end: const Offset(0, 0)).chain(CurveTween(curve: Curves.ease))), + position: animation.drive( + Tween(begin: const Offset(0, 1), end: const Offset(0, 0)) + .chain(CurveTween(curve: Curves.ease))), child: child, ), ); @@ -286,9 +296,12 @@ class BeamPage extends Page { settings: this, pageBuilder: (_, __, ___) => child, transitionDuration: transitionDuration ?? Duration(milliseconds: 300), - reverseTransitionDuration: reverseTransitionDuration ?? Duration(milliseconds: 300), + reverseTransitionDuration: + reverseTransitionDuration ?? Duration(milliseconds: 300), transitionsBuilder: (_, animation, __, child) => SlideTransition( - position: animation.drive(Tween(begin: const Offset(1, 0), end: const Offset(0, 0)).chain(CurveTween(curve: Curves.ease))), + position: animation.drive( + Tween(begin: const Offset(1, 0), end: const Offset(0, 0)) + .chain(CurveTween(curve: Curves.ease))), child: child, ), ); @@ -299,9 +312,12 @@ class BeamPage extends Page { settings: this, pageBuilder: (_, __, ___) => child, transitionDuration: transitionDuration ?? Duration(milliseconds: 300), - reverseTransitionDuration: reverseTransitionDuration ?? Duration(milliseconds: 300), + reverseTransitionDuration: + reverseTransitionDuration ?? Duration(milliseconds: 300), transitionsBuilder: (_, animation, __, child) => SlideTransition( - position: animation.drive(Tween(begin: const Offset(-1, 0), end: const Offset(0, 0)).chain(CurveTween(curve: Curves.ease))), + position: animation.drive( + Tween(begin: const Offset(-1, 0), end: const Offset(0, 0)) + .chain(CurveTween(curve: Curves.ease))), child: child, ), ); @@ -312,9 +328,12 @@ class BeamPage extends Page { settings: this, pageBuilder: (_, __, ___) => child, transitionDuration: transitionDuration ?? Duration(milliseconds: 300), - reverseTransitionDuration: reverseTransitionDuration ?? Duration(milliseconds: 300), + reverseTransitionDuration: + reverseTransitionDuration ?? Duration(milliseconds: 300), transitionsBuilder: (_, animation, __, child) => SlideTransition( - position: animation.drive(Tween(begin: const Offset(0, -1), end: const Offset(0, 0)).chain(CurveTween(curve: Curves.ease))), + position: animation.drive( + Tween(begin: const Offset(0, -1), end: const Offset(0, 0)) + .chain(CurveTween(curve: Curves.ease))), child: child, ), ); @@ -325,7 +344,8 @@ class BeamPage extends Page { settings: this, pageBuilder: (_, __, ___) => child, transitionDuration: transitionDuration ?? Duration(milliseconds: 300), - reverseTransitionDuration: reverseTransitionDuration ?? Duration(milliseconds: 300), + reverseTransitionDuration: + reverseTransitionDuration ?? Duration(milliseconds: 300), transitionsBuilder: (_, animation, __, child) => ScaleTransition( scale: animation, child: child, diff --git a/package/lib/src/beam_stack.dart b/package/lib/src/beam_stack.dart index 65bda08..acf60bb 100644 --- a/package/lib/src/beam_stack.dart +++ b/package/lib/src/beam_stack.dart @@ -45,7 +45,9 @@ class BeamParameters { }) { return BeamParameters( transitionDelegate: transitionDelegate ?? this.transitionDelegate, - popConfiguration: resetPopConfiguration ? null : popConfiguration ?? this.popConfiguration, + popConfiguration: resetPopConfiguration + ? null + : popConfiguration ?? this.popConfiguration, beamBackOnPop: beamBackOnPop ?? this.beamBackOnPop, popBeamStackOnPop: popBeamStackOnPop ?? this.popBeamStackOnPop, stacked: stacked ?? this.stacked, @@ -81,7 +83,8 @@ class HistoryElement { /// * keeping a [state] that provides the link between the first 2 /// /// Extend this class to define your stacks to which you can then beam to. -abstract class BeamStack extends ChangeNotifier { +abstract class BeamStack + extends ChangeNotifier { /// Creates a [BeamStack] with specified properties. /// /// All attributes can be null. @@ -166,7 +169,8 @@ abstract class BeamStack extends ChangeN /// One should override this if using a custom state class. /// /// See [create]. - T createState(RouteInformation routeInformation) => BeamState.fromRouteInformation( + T createState(RouteInformation routeInformation) => + BeamState.fromRouteInformation( routeInformation, beamStack: this, ) as T; @@ -279,7 +283,8 @@ abstract class BeamStack extends ChangeN history.removeRange(sameStateIndex, history.length); } } - if (history.isEmpty || routeInformation.uri != history.last.routeInformation.uri) { + if (history.isEmpty || + routeInformation.uri != history.last.routeInformation.uri) { history.add(HistoryElement(routeInformation, beamParameters)); } } @@ -317,7 +322,9 @@ abstract class BeamStack extends ChangeN for (final pathPattern in pathPatterns) { if (pathPattern is String) { // If it is an exact match or asterisk pattern - if (pathPattern == uri.path || pathPattern == '/*' || pathPattern == '*') { + if (pathPattern == uri.path || + pathPattern == '/*' || + pathPattern == '*') { return true; } @@ -331,13 +338,16 @@ abstract class BeamStack extends ChangeN // If we're in strict mode and URI has fewer segments than pattern, // we don't have a match so can continue. - if (strictPathPatterns && uriPathSegments.length < pathPatternSegments.length) { + if (strictPathPatterns && + uriPathSegments.length < pathPatternSegments.length) { continue; } // If URI has more segments and pattern doesn't end with asterisk, // we don't have a match so can continue. - if (uriPathSegments.length > pathPatternSegments.length && (pathPatternSegments.isEmpty || !pathPatternSegments.last.endsWith('*'))) { + if (uriPathSegments.length > pathPatternSegments.length && + (pathPatternSegments.isEmpty || + !pathPatternSegments.last.endsWith('*'))) { continue; } @@ -347,7 +357,8 @@ abstract class BeamStack extends ChangeN // If all checks have passed up to i, // if pattern has no more segments to traverse and it ended with asterisk, // it is a match and we can break, - if (pathPatternSegments.length < i + 1 && pathPatternSegments.last.endsWith('*')) { + if (pathPatternSegments.length < i + 1 && + pathPatternSegments.last.endsWith('*')) { checksPassed = true; break; } @@ -359,7 +370,8 @@ abstract class BeamStack extends ChangeN } // If they are not the same and pattern doesn't expects path parameter, // there's no match and we can break. - if (uriPathSegments[i] != pathPatternSegments[i] && !pathPatternSegments[i].startsWith(':')) { + if (uriPathSegments[i] != pathPatternSegments[i] && + !pathPatternSegments[i].startsWith(':')) { checksPassed = false; break; } @@ -408,7 +420,9 @@ abstract class BeamStack extends ChangeN if (asteriskIndex == -1) return guardPathPattern == path; - return uri.toString().contains(guardPathPattern.substring(0, asteriskIndex)); + return uri + .toString() + .contains(guardPathPattern.substring(0, asteriskIndex)); } return false; @@ -526,7 +540,8 @@ class GuardShowPage extends BeamStack { final BeamPage beamPage; @override - List buildPages(BuildContext context, BeamState state) => [beamPage]; + List buildPages(BuildContext context, BeamState state) => + [beamPage]; @override List get pathPatterns => [routeInformation.uri.path]; @@ -580,8 +595,10 @@ class RoutesBeamStack extends BeamStack { @override List buildPages(BuildContext context, BeamState state) { final filteredRoutes = chooseRoutes(state.routeInformation, routes.keys); - final routeBuilders = Map.of(routes)..removeWhere((key, value) => !filteredRoutes.containsKey(key)); - final sortedRoutes = routeBuilders.keys.toList()..sort((a, b) => _compareKeys(a, b)); + final routeBuilders = Map.of(routes) + ..removeWhere((key, value) => !filteredRoutes.containsKey(key)); + final sortedRoutes = routeBuilders.keys.toList() + ..sort((a, b) => _compareKeys(a, b)); final pages = sortedRoutes.map((route) { final routeElement = routes[route]!(context, state, data); if (routeElement is BeamPage) { diff --git a/package/lib/src/beamer.dart b/package/lib/src/beamer.dart index f8cd9a8..84d5ba6 100644 --- a/package/lib/src/beamer.dart +++ b/package/lib/src/beamer.dart @@ -1,5 +1,6 @@ import 'package:beamer/beamer.dart'; -import 'package:beamer/src/path_url_strategy_nonweb.dart' if (dart.library.html) 'path_url_strategy_web.dart' as url_strategy; +import 'package:beamer/src/path_url_strategy_nonweb.dart' + if (dart.library.html) 'path_url_strategy_web.dart' as url_strategy; import 'package:flutter/widgets.dart'; /// Represents a navigation area and is a wrapper for [Router]. @@ -40,7 +41,8 @@ class Beamer extends StatefulWidget { final delegate = Router.of(context).routerDelegate as BeamerDelegate; return root ? delegate.root : delegate; } catch (e) { - assert(BeamerProvider.of(context) != null, 'There was no Router nor BeamerProvider in current context. If using MaterialApp.builder, wrap the MaterialApp.router in BeamerProvider to which you pass the same routerDelegate as to MaterialApp.router.'); + assert(BeamerProvider.of(context) != null, + 'There was no Router nor BeamerProvider in current context. If using MaterialApp.builder, wrap the MaterialApp.router in BeamerProvider to which you pass the same routerDelegate as to MaterialApp.router.'); return BeamerProvider.of(context)!.routerDelegate; } } @@ -91,9 +93,11 @@ class BeamerState extends State { // The parent will only be null, if this state is disposed and therefore // `build` cannot be called on it any more. final backButtonDispatcher = widget.backButtonDispatcher ?? - ((parent!.backButtonDispatcher is BeamerBackButtonDispatcher && widget.createBackButtonDispatcher) + ((parent!.backButtonDispatcher is BeamerBackButtonDispatcher && + widget.createBackButtonDispatcher) ? BeamerChildBackButtonDispatcher( - parent: parent!.backButtonDispatcher! as BeamerBackButtonDispatcher, + parent: + parent!.backButtonDispatcher! as BeamerBackButtonDispatcher, delegate: routerDelegate, ) : null); diff --git a/package/lib/src/beamer_delegate.dart b/package/lib/src/beamer_delegate.dart index a3d777d..68fdb4f 100644 --- a/package/lib/src/beamer_delegate.dart +++ b/package/lib/src/beamer_delegate.dart @@ -1,7 +1,9 @@ import 'dart:async'; import 'package:beamer/beamer.dart'; -import 'package:beamer/src/browser_tab_title_util_non_web.dart' if (dart.library.html) 'package:beamer/src/browser_tab_title_util_web.dart' as browser_tab_title_util; +import 'package:beamer/src/browser_tab_title_util_non_web.dart' + if (dart.library.html) 'package:beamer/src/browser_tab_title_util_web.dart' + as browser_tab_title_util; import 'package:beamer/src/utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -10,7 +12,8 @@ import 'package:flutter/services.dart'; /// A delegate that is used by the [Router] to build the [Navigator]. /// /// This is "the beamer", the one that does the actual beaming. -class BeamerDelegate extends RouterDelegate with ChangeNotifier, PopNavigatorRouterDelegateMixin { +class BeamerDelegate extends RouterDelegate + with ChangeNotifier, PopNavigatorRouterDelegateMixin { /// Creates a [BeamerDelegate] with specified properties. /// /// [stackBuilder] is required to process the incoming navigation request. @@ -243,7 +246,8 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie /// Return `false` if beamer should finish handling the pop. /// /// See [build] for details on how beamer handles [Navigator.onPopPage]. - bool Function(BuildContext context, Route route, dynamic result)? onPopPage; + bool Function(BuildContext context, Route route, dynamic result)? + onPopPage; /// Whether the title attribute of [BeamPage] should /// be used to set and update the browser tab title. @@ -304,7 +308,8 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie /// Beamer.of(context).currentBeamStack /// ``` /// {@endtemplate} - BeamStack get currentBeamStack => beamingHistory.isEmpty ? EmptyBeamStack() : beamingHistory.last; + BeamStack get currentBeamStack => + beamingHistory.isEmpty ? EmptyBeamStack() : beamingHistory.last; List _currentPages = []; @@ -411,9 +416,13 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie rebuild = false; } - replaceRouteInformation ? SystemNavigator.selectSingleEntryHistory() : SystemNavigator.selectMultiEntryHistory(); + replaceRouteInformation + ? SystemNavigator.selectSingleEntryHistory() + : SystemNavigator.selectMultiEntryHistory(); - this.configuration = configuration != null ? Utils.createNewConfiguration(this.configuration, configuration) : currentBeamStack.state.routeInformation.copyWith(); + this.configuration = configuration != null + ? Utils.createNewConfiguration(this.configuration, configuration) + : currentBeamStack.state.routeInformation.copyWith(); // update beam parameters _currentBeamParameters = beamParameters ?? _currentBeamParameters; @@ -576,7 +585,9 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie update( configuration: RouteInformation(uri: Uri.parse(uri), state: routeState), beamParameters: _currentBeamParameters.copyWith( - popConfiguration: popToNamed != null ? RouteInformation(uri: Uri.parse(popToNamed)) : null, + popConfiguration: popToNamed != null + ? RouteInformation(uri: Uri.parse(popToNamed)) + : null, transitionDelegate: transitionDelegate ?? this.transitionDelegate, beamBackOnPop: beamBackOnPop, popBeamStackOnPop: popBeamStackOnPop, @@ -639,7 +650,8 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie beamingHistory.removeLast(); continue; } else { - beamingHistory.last.history.removeRange(index, beamingHistory.last.history.length); + beamingHistory.last.history + .removeRange(index, beamingHistory.last.history.length); break; } } @@ -744,7 +756,8 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie @override RouteInformation? get currentConfiguration { - final response = _parent == null && _initialConfigurationReady ? configuration : null; + final response = + _parent == null && _initialConfigurationReady ? configuration : null; if (response != null) { _lastReportedRouteInformation = response.copyWith(); } @@ -785,7 +798,8 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie return Navigator( key: navigatorKey, observers: navigatorObservers, - transitionDelegate: currentBeamStack.transitionDelegate ?? _currentBeamParameters.transitionDelegate, + transitionDelegate: currentBeamStack.transitionDelegate ?? + _currentBeamParameters.transitionDelegate, pages: _currentPages, onPopPage: (route, result) => _onPopPage(context, route, result), ); @@ -849,7 +863,11 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie } bool _runGuards(BuildContext context, BeamStack targetBeamStack) { - final allGuards = [...?parent?.guards, ...guards, ...targetBeamStack.guards]; + final allGuards = [ + ...?parent?.guards, + ...guards, + ...targetBeamStack.guards + ]; for (final guard in allGuards) { if (guard.shouldGuard(targetBeamStack)) { @@ -908,7 +926,8 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie void _addToBeamingHistory(BeamStack beamStack) { _disposeBeamStack(currentBeamStack); if (removeDuplicateHistory) { - final index = beamingHistory.indexWhere((historyStack) => historyStack.runtimeType == beamStack.runtimeType); + final index = beamingHistory.indexWhere( + (historyStack) => historyStack.runtimeType == beamStack.runtimeType); if (index != -1) { _disposeBeamStack(beamingHistory[index]); beamingHistory.removeAt(index); @@ -919,7 +938,8 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie } void _updateBeamingHistory(BeamStack beamStack) { - if (beamingHistory.isEmpty || beamStack.runtimeType != beamingHistory.last.runtimeType) { + if (beamingHistory.isEmpty || + beamStack.runtimeType != beamingHistory.last.runtimeType) { _addToBeamingHistory(beamStack); } else { beamingHistory.last.update( @@ -1003,13 +1023,16 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie if (currentBeamStack is NotFound) { _currentPages = [notFoundPage]; } else { - _currentPages = _currentBeamParameters.stacked ? currentBeamStack.buildPages(context, currentBeamStack.state) : [currentBeamStack.buildPages(context, currentBeamStack.state).last]; + _currentPages = _currentBeamParameters.stacked + ? currentBeamStack.buildPages(context, currentBeamStack.state) + : [currentBeamStack.buildPages(context, currentBeamStack.state).last]; } } void _setBrowserTitle(BuildContext context) { if (active && setBrowserTabTitle) { - final String title = _currentPages.last.title ?? currentBeamStack.state.routeInformation.uri.path; + final String title = _currentPages.last.title ?? + currentBeamStack.state.routeInformation.uri.path; browser_tab_title_util.setTabTitle(title); } } @@ -1066,12 +1089,14 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie void _initializeChild() { final parentConfiguration = _parent!.configuration.copyWith(); if (initializeFromParent) { - _beamStackCandidate = stackBuilder(parentConfiguration, _currentBeamParameters); + _beamStackCandidate = + stackBuilder(parentConfiguration, _currentBeamParameters); } // If this couldn't handle parents configuration, // it will update itself to initialPath and declare itself inactive. - if (_beamStackCandidate is EmptyBeamStack || _beamStackCandidate is NotFound) { + if (_beamStackCandidate is EmptyBeamStack || + _beamStackCandidate is NotFound) { update( configuration: RouteInformation(uri: Uri.parse(initialPath)), rebuild: false, diff --git a/package/lib/src/beamer_provider.dart b/package/lib/src/beamer_provider.dart index 2ec9b1e..f4d97fe 100644 --- a/package/lib/src/beamer_provider.dart +++ b/package/lib/src/beamer_provider.dart @@ -39,7 +39,8 @@ class BeamerProvider extends InheritedWidget { /// Obtain the nearest [BeamerProvider]. /// /// See [BuildContext.dependOnInheritedWidgetOfExactType]. - static BeamerProvider? of(BuildContext context) => context.dependOnInheritedWidgetOfExactType(); + static BeamerProvider? of(BuildContext context) => + context.dependOnInheritedWidgetOfExactType(); @override bool updateShouldNotify(covariant InheritedWidget oldWidget) => false; diff --git a/package/lib/src/transition_delegates.dart b/package/lib/src/transition_delegates.dart index 88fa8dd..ec9b193 100644 --- a/package/lib/src/transition_delegates.dart +++ b/package/lib/src/transition_delegates.dart @@ -29,8 +29,9 @@ class NoAnimationTransitionDelegate extends TransitionDelegate { final pagelessRoutes = pageRouteToPagelessRoutes[exitingPageRoute]; if (pagelessRoutes != null) { for (final pagelessRoute in pagelessRoutes) { - if (pagelessRoute.isWaitingForExitingDecision) + if (pagelessRoute.isWaitingForExitingDecision) { pagelessRoute.markForRemove(); + } } } } diff --git a/package/lib/src/utils.dart b/package/lib/src/utils.dart index 014a73f..454e0f0 100644 --- a/package/lib/src/utils.dart +++ b/package/lib/src/utils.dart @@ -66,12 +66,16 @@ abstract class Utils { } final uriPathSegments = uri.pathSegments.toList(); - if (uriPathSegments.length > 1 && uriPathSegments.last == '') uriPathSegments.removeLast(); + if (uriPathSegments.length > 1 && uriPathSegments.last == '') { + uriPathSegments.removeLast(); + } - final beamStackPathBlueprintSegments = Uri.parse(pathPattern).pathSegments; + final beamStackPathBlueprintSegments = + Uri.parse(pathPattern).pathSegments; var pathSegments = []; - if (uriPathSegments.length > beamStackPathBlueprintSegments.length && !beamStackPathBlueprintSegments.contains('*')) continue; + if (uriPathSegments.length > beamStackPathBlueprintSegments.length && + !beamStackPathBlueprintSegments.contains('*')) continue; var checksPassed = true; @@ -82,11 +86,13 @@ abstract class Utils { break; } - if (uriPathSegments[i] != beamStackPathBlueprintSegments[i] && beamStackPathBlueprintSegments[i][0] != ':') { + if (uriPathSegments[i] != beamStackPathBlueprintSegments[i] && + beamStackPathBlueprintSegments[i][0] != ':') { checksPassed = false; break; } else if (beamStackPathBlueprintSegments[i][0] == ':') { - pathParameters[beamStackPathBlueprintSegments[i].substring(1)] = uriPathSegments[i]; + pathParameters[beamStackPathBlueprintSegments[i].substring(1)] = + uriPathSegments[i]; pathSegments.add(beamStackPathBlueprintSegments[i]); } else { pathSegments.add(uriPathSegments[i]); @@ -150,7 +156,8 @@ abstract class Utils { /// Else, return incoming URI. static Uri maybeAppend(Uri current, Uri incoming) { if (!incoming.hasAbsolutePath && !incoming.hasEmptyPath) { - String currentPath = current.path.endsWith('/') ? current.path : '${current.path}/'; + String currentPath = + current.path.endsWith('/') ? current.path : '${current.path}/'; return current.replace( path: currentPath + incoming.path, query: incoming.hasQuery ? incoming.query : null, @@ -218,7 +225,12 @@ extension PatternExtension on Pattern { try { return this as RegExp; } on TypeError catch (_) { - throw FlutterError.fromParts([DiagnosticsNode.message('Path blueprint can either be:', level: DiagnosticLevel.summary), DiagnosticsNode.message('1. String'), DiagnosticsNode.message('2. RegExp instance')]); + throw FlutterError.fromParts([ + DiagnosticsNode.message('Path blueprint can either be:', + level: DiagnosticLevel.summary), + DiagnosticsNode.message('1. String'), + DiagnosticsNode.message('2. RegExp instance') + ]); } } } diff --git a/package/test/beamer_delegate_test.dart b/package/test/beamer_delegate_test.dart index 4b5faa0..9b74360 100644 --- a/package/test/beamer_delegate_test.dart +++ b/package/test/beamer_delegate_test.dart @@ -64,7 +64,8 @@ void main() { expect(stack.data, {'x': 'y'}); }); - test('popBeamStack leads to previous stack and all helpers are correct', () { + test('popBeamStack leads to previous stack and all helpers are correct', + () { delegate.beamToNamed('/l1'); delegate.beamToNamed('/l2'); @@ -78,7 +79,8 @@ void main() { }); }); - testWidgets('stacked beam takes just last page for currentPages', (tester) async { + testWidgets('stacked beam takes just last page for currentPages', + (tester) async { await tester.pumpWidget( MaterialApp.router( routeInformationParser: BeamerParser(), @@ -109,9 +111,12 @@ void main() { test('custom state can be updated', () { delegate.beamToNamed('/custom/test'); - expect((delegate.currentBeamStack as CustomStateStack).state.customVar, 'test'); - (delegate.currentBeamStack as CustomStateStack).update((state) => CustomState(customVar: 'test-ok')); - expect((delegate.currentBeamStack as CustomStateStack).state.customVar, 'test-ok'); + expect((delegate.currentBeamStack as CustomStateStack).state.customVar, + 'test'); + (delegate.currentBeamStack as CustomStateStack) + .update((state) => CustomState(customVar: 'test-ok')); + expect((delegate.currentBeamStack as CustomStateStack).state.customVar, + 'test-ok'); }); test('beamTo works without setting the BeamState explicitly', () { @@ -175,21 +180,24 @@ void main() { delegate.beamToNamed('/l2'); expect(delegate.beamBack(), true); - expect(delegate.configuration.uri, delegate.currentBeamStack.state.routeInformation.uri); + expect(delegate.configuration.uri, + delegate.currentBeamStack.state.routeInformation.uri); expect(delegate.configuration.uri.path, '/l1'); expect(delegate.currentBeamStack.data, {'x': 'y'}); delegate.beamToNamed('/l2'); expect(delegate.beamBack(), true); - expect(delegate.configuration.uri, delegate.currentBeamStack.state.routeInformation.uri); + expect(delegate.configuration.uri, + delegate.currentBeamStack.state.routeInformation.uri); expect(delegate.configuration.uri.path, '/l1'); expect(delegate.currentBeamStack.data, {'x': 'y'}); delegate.beamToNamed('/l2'); expect(delegate.beamBack(data: {'xx': 'yy'}), true); - expect(delegate.configuration.uri, delegate.currentBeamStack.state.routeInformation.uri); + expect(delegate.configuration.uri, + delegate.currentBeamStack.state.routeInformation.uri); expect(delegate.configuration.uri.path, '/l1'); expect(delegate.currentBeamStack.data, {'xx': 'yy'}); }); @@ -307,7 +315,8 @@ void main() { ); delegate.beamToNamed('/l1/one', data: {'x': 'y'}); await tester.pump(); - expect((delegate.currentBeamStack.state as BeamState).uri.path, '/l1/one'); + expect( + (delegate.currentBeamStack.state as BeamState).uri.path, '/l1/one'); expect(delegate.currentBeamStack.data, {'x': 'y'}); delegate.navigatorKey.currentState!.pop(); @@ -391,7 +400,8 @@ void main() { expect(childDelegate.beamingHistory.last.history.length, 3); }); - testWidgets("navigation on parent doesn't update nested Beamer", (tester) async { + testWidgets("navigation on parent doesn't update nested Beamer", + (tester) async { final childDelegate = BeamerDelegate( initializeFromParent: false, updateFromParent: false, @@ -438,7 +448,8 @@ void main() { }); group('update without rebuild', () { - test('no rebuild updates route information (configuration) to anything', () { + test('no rebuild updates route information (configuration) to anything', + () { final delegate = BeamerDelegate( stackBuilder: RoutesStackBuilder( routes: { @@ -463,7 +474,9 @@ void main() { expect(delegate.configuration.uri.path, '/any'); }); - testWidgets('updating route information without updating parent or rebuilding', (tester) async { + testWidgets( + 'updating route information without updating parent or rebuilding', + (tester) async { final childDelegate = BeamerDelegate( updateParent: false, stackBuilder: RoutesStackBuilder( @@ -579,7 +592,8 @@ void main() { expect(delegate.beamingHistory.last.history.length, 1); }); - testWidgets('history is cleared regardless, if option is set', (tester) async { + testWidgets('history is cleared regardless, if option is set', + (tester) async { final delegate = BeamerDelegate( clearBeamingHistoryOn: {'/'}, stackBuilder: RoutesStackBuilder( @@ -623,7 +637,8 @@ void main() { expect(delegate.beamingHistory.last.history.length, 1); }); - testWidgets('history is cleared regardless, if option is set', (tester) async { + testWidgets('history is cleared regardless, if option is set', + (tester) async { final delegate = BeamerDelegate( clearBeamingHistoryOn: {'/test'}, stackBuilder: RoutesStackBuilder( @@ -701,7 +716,8 @@ void main() { }); group('Relative beaming', () { - test('incoming configuration is appended when it does not start with /', () { + test('incoming configuration is appended when it does not start with /', + () { final delegate = BeamerDelegate( stackBuilder: RoutesStackBuilder( routes: { @@ -718,7 +734,8 @@ void main() { delegate.beamToNamed('t2'); expect(delegate.configuration.uri.path, '/t1/t2'); - expect(delegate.currentBeamStack.state.routeInformation.uri.path, '/t1/t2'); + expect( + delegate.currentBeamStack.state.routeInformation.uri.path, '/t1/t2'); }); }); @@ -738,11 +755,15 @@ void main() { delegate.beamToNamed('/t3'); delegate.popToNamed('/t2'); - expect(delegate.currentBeamStack.history.map((HistoryElement e) => e.routeInformation.uri.path), orderedEquals(['/t1', '/t2'])); + expect( + delegate.currentBeamStack.history + .map((HistoryElement e) => e.routeInformation.uri.path), + orderedEquals(['/t1', '/t2'])); }); group('Deep Link', () { - testWidgets('Deep link is preserved throughout guarding flow', (tester) async { + testWidgets('Deep link is preserved throughout guarding flow', + (tester) async { var isLoading = true; var isAuthenticated = false; final delegate = BeamerDelegate( @@ -758,18 +779,21 @@ void main() { BeamGuard( pathPatterns: ['/splash'], check: (_, __) => isLoading, - beamToNamed: (context, _, __, deepLink) => isAuthenticated ? (deepLink ?? '/home') : '/login', + beamToNamed: (context, _, __, deepLink) => + isAuthenticated ? (deepLink ?? '/home') : '/login', ), BeamGuard( pathPatterns: ['/login'], check: (_, __) => !isAuthenticated && !isLoading, - beamToNamed: (context, _, __, deepLink) => isAuthenticated ? (deepLink ?? '/home') : '/splash', + beamToNamed: (context, _, __, deepLink) => + isAuthenticated ? (deepLink ?? '/home') : '/splash', ), BeamGuard( pathPatterns: ['/splash', '/login'], guardNonMatching: true, check: (_, __) => isAuthenticated, - beamToNamed: (context, _, __, ___) => isLoading ? '/splash' : '/login', + beamToNamed: (context, _, __, ___) => + isLoading ? '/splash' : '/login', ), ], ); diff --git a/package/test/beaming_history_test.dart b/package/test/beaming_history_test.dart index a9d8d1f..0bd2fc8 100644 --- a/package/test/beaming_history_test.dart +++ b/package/test/beaming_history_test.dart @@ -9,7 +9,8 @@ class StackA extends BeamStack { List get pathPatterns => ['/a']; @override - List buildPages(BuildContext context, BeamState state) => [BeamPage(key: const ValueKey('a'), child: Container())]; + List buildPages(BuildContext context, BeamState state) => + [BeamPage(key: const ValueKey('a'), child: Container())]; } class StackB extends BeamStack { @@ -18,8 +19,10 @@ class StackB extends BeamStack { @override List buildPages(BuildContext context, BeamState state) => [ - if (state.pathPatternSegments.contains('b1')) BeamPage(key: const ValueKey('b1'), child: Container()), - if (state.pathPatternSegments.contains('b2')) BeamPage(key: const ValueKey('b2'), child: Container()), + if (state.pathPatternSegments.contains('b1')) + BeamPage(key: const ValueKey('b1'), child: Container()), + if (state.pathPatternSegments.contains('b2')) + BeamPage(key: const ValueKey('b2'), child: Container()), ]; } @@ -68,7 +71,9 @@ void main() { expect(delegate.beamingHistory[0], isA()); }); - test('beamToReplacement removes currentBeamStack from history before appending new', () { + test( + 'beamToReplacement removes currentBeamStack from history before appending new', + () { delegate.beamToNamed('/l2'); delegate.beamToNamed('/l1'); @@ -108,11 +113,14 @@ void main() { expect(delegate.beamingHistory[0], isA()); expect(delegate.currentBeamStack, isA()); expect(delegate.beamingHistory.last.history.length, 2); - expect(delegate.beamingHistory.last.history.last.routeInformation.uri.path, '/l2/y'); + expect( + delegate.beamingHistory.last.history.last.routeInformation.uri.path, + '/l2/y'); expect(delegate.beamingHistoryCompleteLength, 3); }); - test('beamBack leads to previous beam state and all helpers are correct', () { + test('beamBack leads to previous beam state and all helpers are correct', + () { delegate.beamToNamed('/l1'); delegate.beamToNamed('/l2'); @@ -131,7 +139,8 @@ void main() { expect(delegate.beamBack(), true); expect(delegate.currentBeamStack, isA()); - expect((delegate.currentBeamStack.state as BeamState).uri.path, equals('/l1/one')); + expect((delegate.currentBeamStack.state as BeamState).uri.path, + equals('/l1/one')); expect(delegate.beamingHistoryCompleteLength, 2); expect(delegate.beamBack(), true); diff --git a/package/test/utils_test.dart b/package/test/utils_test.dart index 2377733..788b8aa 100644 --- a/package/test/utils_test.dart +++ b/package/test/utils_test.dart @@ -204,15 +204,21 @@ void main() { test('Merging with new routeState', () { final current = RouteInformation(uri: Uri.parse('/current')); expect( - Utils.mergeConfiguration(current, RouteInformation(uri: Uri(), state: 42)).state, + Utils.mergeConfiguration( + current, RouteInformation(uri: Uri(), state: 42)) + .state, 42, ); expect( - Utils.mergeConfiguration(current, RouteInformation(uri: Uri.parse('incoming'), state: 42)).state, + Utils.mergeConfiguration(current, + RouteInformation(uri: Uri.parse('incoming'), state: 42)) + .state, 42, ); expect( - Utils.mergeConfiguration(current, RouteInformation(uri: Uri.parse('/incoming'), state: 42)).state, + Utils.mergeConfiguration(current, + RouteInformation(uri: Uri.parse('/incoming'), state: 42)) + .state, 42, ); expect(