From 7bf3b96fad075dc4f01972783dc2955cefa61582 Mon Sep 17 00:00:00 2001 From: Stan Persoons Date: Mon, 18 Nov 2024 00:46:33 +0100 Subject: [PATCH 1/2] General Improvements --- package/lib/src/beam_page.dart | 2 - package/lib/src/beamer_delegate.dart | 59 ++++++------------- website/lib/app.dart | 2 +- website/lib/presentation/core/header.dart | 2 +- .../presentation/core/navigation_sidebar.dart | 8 +-- website/lib/presentation/core/paragraph.dart | 4 +- website/lib/presentation/core/wip_screen.dart | 2 +- .../quick_start/accessing_screen.dart | 6 +- .../quick_start/beaming_screen.dart | 6 +- .../quick_start/routes_screen.dart | 6 +- 10 files changed, 35 insertions(+), 62 deletions(-) diff --git a/package/lib/src/beam_page.dart b/package/lib/src/beam_page.dart index e1eca3be..9e5581ba 100644 --- a/package/lib/src/beam_page.dart +++ b/package/lib/src/beam_page.dart @@ -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( diff --git a/package/lib/src/beamer_delegate.dart b/package/lib/src/beamer_delegate.dart index 68fdb4f4..a3d777d0 100644 --- a/package/lib/src/beamer_delegate.dart +++ b/package/lib/src/beamer_delegate.dart @@ -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'; @@ -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 - 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. @@ -246,8 +243,7 @@ class BeamerDelegate extends RouterDelegate /// 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. @@ -308,8 +304,7 @@ class BeamerDelegate extends RouterDelegate /// Beamer.of(context).currentBeamStack /// ``` /// {@endtemplate} - BeamStack get currentBeamStack => - beamingHistory.isEmpty ? EmptyBeamStack() : beamingHistory.last; + BeamStack get currentBeamStack => beamingHistory.isEmpty ? EmptyBeamStack() : beamingHistory.last; List _currentPages = []; @@ -416,13 +411,9 @@ class BeamerDelegate extends RouterDelegate 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; @@ -585,9 +576,7 @@ class BeamerDelegate extends RouterDelegate 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, @@ -650,8 +639,7 @@ class BeamerDelegate extends RouterDelegate beamingHistory.removeLast(); continue; } else { - beamingHistory.last.history - .removeRange(index, beamingHistory.last.history.length); + beamingHistory.last.history.removeRange(index, beamingHistory.last.history.length); break; } } @@ -756,8 +744,7 @@ class BeamerDelegate extends RouterDelegate @override RouteInformation? get currentConfiguration { - final response = - _parent == null && _initialConfigurationReady ? configuration : null; + final response = _parent == null && _initialConfigurationReady ? configuration : null; if (response != null) { _lastReportedRouteInformation = response.copyWith(); } @@ -798,8 +785,7 @@ class BeamerDelegate extends RouterDelegate 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), ); @@ -863,11 +849,7 @@ class BeamerDelegate extends RouterDelegate } 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)) { @@ -926,8 +908,7 @@ class BeamerDelegate extends RouterDelegate 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); @@ -938,8 +919,7 @@ class BeamerDelegate extends RouterDelegate } 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( @@ -1023,16 +1003,13 @@ class BeamerDelegate extends RouterDelegate 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); } } @@ -1089,14 +1066,12 @@ class BeamerDelegate extends RouterDelegate 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/website/lib/app.dart b/website/lib/app.dart index 1e225231..3498b67c 100644 --- a/website/lib/app.dart +++ b/website/lib/app.dart @@ -18,7 +18,7 @@ class _AppState extends State { void initState() { super.initState(); _isDarkTheme = - WidgetsBinding.instance!.window.platformBrightness == Brightness.dark; + WidgetsBinding.instance.window.platformBrightness == Brightness.dark; } @override diff --git a/website/lib/presentation/core/header.dart b/website/lib/presentation/core/header.dart index 76d704a1..d138e0d8 100644 --- a/website/lib/presentation/core/header.dart +++ b/website/lib/presentation/core/header.dart @@ -52,7 +52,7 @@ class _HeaderState extends State
{ ), Text( 'Beamer', - style: theme.textTheme.headline6!.copyWith(color: Colors.white), + style: theme.textTheme.titleLarge!.copyWith(color: Colors.white), ), const Spacer(), IconButton( diff --git a/website/lib/presentation/core/navigation_sidebar.dart b/website/lib/presentation/core/navigation_sidebar.dart index 76033b3b..6f9ead9b 100644 --- a/website/lib/presentation/core/navigation_sidebar.dart +++ b/website/lib/presentation/core/navigation_sidebar.dart @@ -28,14 +28,14 @@ class _NavigationSidebarState extends State { 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), @@ -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, ), ), @@ -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, ), ), diff --git a/website/lib/presentation/core/paragraph.dart b/website/lib/presentation/core/paragraph.dart index c06ac2ec..5eff5da2 100644 --- a/website/lib/presentation/core/paragraph.dart +++ b/website/lib/presentation/core/paragraph.dart @@ -24,7 +24,7 @@ class ParagraphTitle extends Paragraph { @override TextStyle? getTextStyle(BuildContext context) => Theme.of(context) .textTheme - .headline5! + .headlineSmall! .copyWith(fontWeight: FontWeight.bold); } @@ -34,7 +34,7 @@ class ParagraphSubtitle extends Paragraph { @override TextStyle? getTextStyle(BuildContext context) => Theme.of(context) .textTheme - .headline6! + .titleLarge! .copyWith(fontWeight: FontWeight.normal); } diff --git a/website/lib/presentation/core/wip_screen.dart b/website/lib/presentation/core/wip_screen.dart index 15a8ddb9..aa7ea370 100644 --- a/website/lib/presentation/core/wip_screen.dart +++ b/website/lib/presentation/core/wip_screen.dart @@ -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, ), ), diff --git a/website/lib/presentation/quick_start/accessing_screen.dart b/website/lib/presentation/quick_start/accessing_screen.dart index de1b90bd..cce227d6 100644 --- a/website/lib/presentation/quick_start/accessing_screen.dart +++ b/website/lib/presentation/quick_start/accessing_screen.dart @@ -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", diff --git a/website/lib/presentation/quick_start/beaming_screen.dart b/website/lib/presentation/quick_start/beaming_screen.dart index d8341253..48855538 100644 --- a/website/lib/presentation/quick_start/beaming_screen.dart +++ b/website/lib/presentation/quick_start/beaming_screen.dart @@ -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.", diff --git a/website/lib/presentation/quick_start/routes_screen.dart b/website/lib/presentation/quick_start/routes_screen.dart index be44e5ba..3570d38f 100644 --- a/website/lib/presentation/quick_start/routes_screen.dart +++ b/website/lib/presentation/quick_start/routes_screen.dart @@ -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.', From b65a06e4379aaa84c2062784ff7dcf867a12064f Mon Sep 17 00:00:00 2001 From: Stan Persoons Date: Mon, 18 Nov 2024 00:47:29 +0100 Subject: [PATCH 2/2] Added todoon deprecated parameter --- package/lib/src/beamer_delegate.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/lib/src/beamer_delegate.dart b/package/lib/src/beamer_delegate.dart index a3d777d0..9371915b 100644 --- a/package/lib/src/beamer_delegate.dart +++ b/package/lib/src/beamer_delegate.dart @@ -787,7 +787,7 @@ class BeamerDelegate extends RouterDelegate with ChangeNotifie observers: navigatorObservers, 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 ); }, );