Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parameters for transitionDuration and reverseTransitionDuration and dart fix'es #682

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package/lib/src/beam_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,6 @@ class BeamPage extends Page {
transitionDuration: transitionDuration ?? Duration.zero,
reverseTransitionDuration: reverseTransitionDuration ?? Duration.zero,
pageBuilder: (context, animation, secondaryAnimation) => child,
transitionDuration: Duration.zero,
reverseTransitionDuration: Duration.zero,
);
default:
return MaterialPageRoute(
Expand Down
61 changes: 18 additions & 43 deletions package/lib/src/beamer_delegate.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
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';
Expand All @@ -12,8 +10,7 @@ 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<RouteInformation>
with ChangeNotifier, PopNavigatorRouterDelegateMixin<RouteInformation> {
class BeamerDelegate extends RouterDelegate<RouteInformation> with ChangeNotifier, PopNavigatorRouterDelegateMixin<RouteInformation> {
/// Creates a [BeamerDelegate] with specified properties.
///
/// [stackBuilder] is required to process the incoming navigation request.
Expand Down Expand Up @@ -246,8 +243,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
/// Return `false` if beamer should finish handling the pop.
///
/// See [build] for details on how beamer handles [Navigator.onPopPage].
bool Function(BuildContext context, Route<dynamic> route, dynamic result)?
onPopPage;
bool Function(BuildContext context, Route<dynamic> route, dynamic result)? onPopPage;

/// Whether the title attribute of [BeamPage] should
/// be used to set and update the browser tab title.
Expand Down Expand Up @@ -308,8 +304,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
/// Beamer.of(context).currentBeamStack
/// ```
/// {@endtemplate}
BeamStack get currentBeamStack =>
beamingHistory.isEmpty ? EmptyBeamStack() : beamingHistory.last;
BeamStack get currentBeamStack => beamingHistory.isEmpty ? EmptyBeamStack() : beamingHistory.last;

List<BeamPage> _currentPages = [];

Expand Down Expand Up @@ -416,13 +411,9 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
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;
Expand Down Expand Up @@ -585,9 +576,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
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,
Expand Down Expand Up @@ -650,8 +639,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
beamingHistory.removeLast();
continue;
} else {
beamingHistory.last.history
.removeRange(index, beamingHistory.last.history.length);
beamingHistory.last.history.removeRange(index, beamingHistory.last.history.length);
break;
}
}
Expand Down Expand Up @@ -756,8 +744,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>

@override
RouteInformation? get currentConfiguration {
final response =
_parent == null && _initialConfigurationReady ? configuration : null;
final response = _parent == null && _initialConfigurationReady ? configuration : null;
if (response != null) {
_lastReportedRouteInformation = response.copyWith();
}
Expand Down Expand Up @@ -798,10 +785,9 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
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),
onPopPage: (route, result) => _onPopPage(context, route, result), // TODO(): THIS NEEDS TO BE LOOKED AT
);
},
);
Expand Down Expand Up @@ -863,11 +849,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
}

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)) {
Expand Down Expand Up @@ -926,8 +908,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
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);
Expand All @@ -938,8 +919,7 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
}

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(
Expand Down Expand Up @@ -1023,16 +1003,13 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
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);
}
}
Expand Down Expand Up @@ -1089,14 +1066,12 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
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,
Expand Down
2 changes: 1 addition & 1 deletion website/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class _AppState extends State<App> {
void initState() {
super.initState();
_isDarkTheme =
WidgetsBinding.instance!.window.platformBrightness == Brightness.dark;
WidgetsBinding.instance.window.platformBrightness == Brightness.dark;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion website/lib/presentation/core/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _HeaderState extends State<Header> {
),
Text(
'Beamer',
style: theme.textTheme.headline6!.copyWith(color: Colors.white),
style: theme.textTheme.titleLarge!.copyWith(color: Colors.white),
),
const Spacer(),
IconButton(
Expand Down
8 changes: 4 additions & 4 deletions website/lib/presentation/core/navigation_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class _NavigationSidebarState extends State<NavigationSidebar> {
super.didChangeDependencies();
_beamer = Beamer.of(context);
_beamer.removeListener(_setStateListener);
WidgetsBinding.instance!.addPostFrameCallback(
WidgetsBinding.instance.addPostFrameCallback(
(_) => _beamer.addListener(_setStateListener),
);
}

@override
Widget build(BuildContext context) {
final path = _beamer.configuration.location!;
final path = _beamer.configuration.location;
final size = MediaQuery.of(context).size;
return Padding(
padding: EdgeInsets.only(top: _isDrawer ? kToolbarHeight : 0.0),
Expand Down Expand Up @@ -176,7 +176,7 @@ class ExpandableNavigationButton extends StatelessWidget {
padding: const EdgeInsets.all(16.0),
child: Text(
text,
style: Theme.of(context).textTheme.button!.copyWith(
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: isSelected ? Colors.blue : null,
),
),
Expand Down Expand Up @@ -215,7 +215,7 @@ class NavigationButton extends StatelessWidget {
EdgeInsets.only(left: padLeft ? 16.0 : 0.0),
child: Text(
text,
style: Theme.of(context).textTheme.button!.copyWith(
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: isSelected ? Colors.blue : null,
),
),
Expand Down
4 changes: 2 additions & 2 deletions website/lib/presentation/core/paragraph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ParagraphTitle extends Paragraph {
@override
TextStyle? getTextStyle(BuildContext context) => Theme.of(context)
.textTheme
.headline5!
.headlineSmall!
.copyWith(fontWeight: FontWeight.bold);
}

Expand All @@ -34,7 +34,7 @@ class ParagraphSubtitle extends Paragraph {
@override
TextStyle? getTextStyle(BuildContext context) => Theme.of(context)
.textTheme
.headline6!
.titleLarge!
.copyWith(fontWeight: FontWeight.normal);
}

Expand Down
2 changes: 1 addition & 1 deletion website/lib/presentation/core/wip_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class WIPScreen extends StatelessWidget {
padding: const EdgeInsets.all(32.0),
child: SelectableText(
'Coming soon...',
style: Theme.of(context).textTheme.headline6,
style: Theme.of(context).textTheme.titleLarge,
textAlign: TextAlign.center,
),
),
Expand Down
6 changes: 3 additions & 3 deletions website/lib/presentation/quick_start/accessing_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class AccessingScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Scaffold(
return const Scaffold(
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(32.0),
padding: EdgeInsets.all(32.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
children: [
ParagraphTitle('Accessing nearest Beamer'),
ParagraphText(
"Accessing route attributes in Widgets (for example, bookId for building BookDetailsScreen) can be done with",
Expand Down
6 changes: 3 additions & 3 deletions website/lib/presentation/quick_start/beaming_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class BeamingScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Scaffold(
return const Scaffold(
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(32.0),
padding: EdgeInsets.all(32.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
children: [
ParagraphTitle('Beaming > Navigating'),
ParagraphText(
"Navigation is done by \"beaming\". One can think of it as teleporting (beaming) to another place in your app. Similar to Navigator.of(context).pushReplacementNamed('/my-route'), but Beamer is not limited to a single page, nor to a push per se. BeamLocations produce a stack of pages that get built when you beam there. Beaming can feel like using many of Navigator's push/pop methods at once.",
Expand Down
6 changes: 3 additions & 3 deletions website/lib/presentation/quick_start/routes_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class RoutesScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Scaffold(
return const Scaffold(
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(32.0),
padding: EdgeInsets.all(32.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
children: [
ParagraphTitle('Defining simple routes'),
ParagraphText(
'The simplest setup is achieved by using the RoutesLocationBuilder which yields the least amount of code. This is a great choice for applications with fewer navigation scenarios or with shallow page stacks, i.e. when pages are rarely stacked on top of each other.',
Expand Down
Loading