Skip to content

Commit

Permalink
Formatted files nad dart fixed analyze errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-at-work committed Aug 6, 2024
1 parent 2432fbd commit 80617d0
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 92 deletions.
9 changes: 6 additions & 3 deletions package/lib/src/beam_guard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion package/lib/src/beam_interceptor_pop_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class BeamInterceptorPopScope extends StatefulWidget {
final BeamerDelegate? beamerDelegate;

@override
State<BeamInterceptorPopScope> createState() => _BeamInterceptorPopScopeState();
State<BeamInterceptorPopScope> createState() =>
_BeamInterceptorPopScopeState();
}

class _BeamInterceptorPopScopeState extends State<BeamInterceptorPopScope> {
Expand Down
48 changes: 34 additions & 14 deletions package/lib/src/beam_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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,
Expand All @@ -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,
),
);
Expand All @@ -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,
),
);
Expand All @@ -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,
),
);
Expand All @@ -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,
),
);
Expand All @@ -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,
Expand Down
43 changes: 30 additions & 13 deletions package/lib/src/beam_stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<T extends RouteInformationSerializable> extends ChangeNotifier {
abstract class BeamStack<T extends RouteInformationSerializable>
extends ChangeNotifier {
/// Creates a [BeamStack] with specified properties.
///
/// All attributes can be null.
Expand Down Expand Up @@ -166,7 +169,8 @@ abstract class BeamStack<T extends RouteInformationSerializable> 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;
Expand Down Expand Up @@ -279,7 +283,8 @@ abstract class BeamStack<T extends RouteInformationSerializable> 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));
}
}
Expand Down Expand Up @@ -317,7 +322,9 @@ abstract class BeamStack<T extends RouteInformationSerializable> 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;
}

Expand All @@ -331,13 +338,16 @@ abstract class BeamStack<T extends RouteInformationSerializable> 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;
}

Expand All @@ -347,7 +357,8 @@ abstract class BeamStack<T extends RouteInformationSerializable> 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;
}
Expand All @@ -359,7 +370,8 @@ abstract class BeamStack<T extends RouteInformationSerializable> 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;
}
Expand Down Expand Up @@ -408,7 +420,9 @@ abstract class BeamStack<T extends RouteInformationSerializable> 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;
Expand Down Expand Up @@ -526,7 +540,8 @@ class GuardShowPage extends BeamStack<BeamState> {
final BeamPage beamPage;

@override
List<BeamPage> buildPages(BuildContext context, BeamState state) => [beamPage];
List<BeamPage> buildPages(BuildContext context, BeamState state) =>
[beamPage];

@override
List<String> get pathPatterns => [routeInformation.uri.path];
Expand Down Expand Up @@ -580,8 +595,10 @@ class RoutesBeamStack extends BeamStack<BeamState> {
@override
List<BeamPage> 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<BeamPage>((route) {
final routeElement = routes[route]!(context, state, data);
if (routeElement is BeamPage) {
Expand Down
12 changes: 8 additions & 4 deletions package/lib/src/beamer.dart
Original file line number Diff line number Diff line change
@@ -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].
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -91,9 +93,11 @@ class BeamerState extends State<Beamer> {
// 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);
Expand Down
Loading

0 comments on commit 80617d0

Please sign in to comment.