Skip to content

Commit

Permalink
Change API names for GoRouter proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpryan committed May 24, 2022
1 parent 8a299ce commit 5d40ed7
Show file tree
Hide file tree
Showing 28 changed files with 123 additions and 129 deletions.
8 changes: 4 additions & 4 deletions example/lib/basics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import 'package:flutter/material.dart' hide Route;
import 'package:tree_router/tree_router.dart';

void main() {
runApp(TreeRouterDemo());
runApp(ExampleApp());
}

class TreeRouterDemo extends StatelessWidget {
TreeRouterDemo({Key? key}) : super(key: key);
class ExampleApp extends StatelessWidget {
ExampleApp({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
StackedRoute(
path: '/',
Expand Down
5 changes: 3 additions & 2 deletions example/lib/bottom_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ void main() {
class BottomNavigationBarDemo extends StatelessWidget {
BottomNavigationBarDemo({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
ShellRoute(
path: '/',
builder: (context, child) => AppScaffold(child: child),
// preserveState: true,
routes: [
StackedRoute(
path: 'a',
Expand All @@ -31,7 +32,7 @@ class BottomNavigationBarDemo extends StatelessWidget {
),
],
),
StackedRoute(
NestedStackRoute(
path: 'b',
builder: (context) => const Screen(
title: 'Screen B',
Expand Down
6 changes: 3 additions & 3 deletions example/lib/bottom_nav_with_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ void main() {
class BottomNavigationBarDemo extends StatelessWidget {
BottomNavigationBarDemo({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
ShellRoute(
path: '/',
defaultRoute: 'a',
builder: (context, child) => AppScaffold(child: child),
routes: [
NavigatorRoute(
NestedStackRoute(
path: 'a',
builder: (context) => const Screen(
title: 'Screen A',
Expand All @@ -32,7 +32,7 @@ class BottomNavigationBarDemo extends StatelessWidget {
),
],
),
NavigatorRoute(
NestedStackRoute(
path: 'b',
builder: (context) => const Screen(
title: 'Screen B',
Expand Down
2 changes: 1 addition & 1 deletion example/lib/bottom_nav_with_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
class BottomNavWithTabsDemo extends StatelessWidget {
BottomNavWithTabsDemo({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
ShellRoute(
path: '/',
Expand Down
24 changes: 8 additions & 16 deletions example/lib/cupertino.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:tree_router/tree_router.dart' hide Route;
import 'package:flutter/cupertino.dart' hide Route;
import 'package:flutter/cupertino.dart' as cupertino show Route;
import 'package:tree_router/tree_router.dart' hide RouteBase;

void main() {
runApp(const CupertinoTabBarDemo());
Expand All @@ -18,7 +19,7 @@ class _TabInfo {
final IconData icon;
}

final _router = TreeRouter(
final _router = GoRouter(
routes: [
ShellRoute(
path: '/',
Expand All @@ -28,7 +29,7 @@ final _router = TreeRouter(
child: child,
),
routes: [
NavigatorRoute(
NestedStackRoute(
path: 'home',
builder: (context) => const HomeScreen(),
routes: [
Expand All @@ -38,7 +39,7 @@ final _router = TreeRouter(
),
],
),
NavigatorRoute(
NestedStackRoute(
path: 'chat',
builder: (context) => const ChatScreen(),
routes: [
Expand All @@ -48,16 +49,6 @@ final _router = TreeRouter(
),
],
),
NavigatorRoute(
path: 'profile',
builder: (context) => const ProfileScreen(),
routes: [
StackedRoute(
path: 'details/:id',
builder: (context) => const DetailsScreen(),
),
],
),
],
),
],
Expand Down Expand Up @@ -262,7 +253,8 @@ class DetailsScreen extends StatefulWidget {
return navigator.restorablePush<void>(_routeBuilder, arguments: id);
}

static Route<void> _routeBuilder(BuildContext context, Object? arguments) {
static cupertino.Route<void> _routeBuilder(
BuildContext context, Object? arguments) {
final id = arguments as int?;
return CupertinoPageRoute(
builder: (context) => DetailsScreen(id: id, restorationId: 'details'),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/feature_splitting/listen_now.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:tree_router/tree_router.dart';
import 'song.dart';

class ListenNowFeature extends StatelessWidget {
static Route route = StackedRoute(
static RouteBase route = StackedRoute(
path: 'listen-now',
builder: (context) => const ListenNowFeature(),
routes: [
Expand Down
4 changes: 2 additions & 2 deletions example/lib/feature_splitting/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
}

class Feature {
final Route route;
final RouteBase route;
final AdaptiveScaffoldDestination destination;

Feature(this.route, this.destination);
Expand All @@ -24,7 +24,7 @@ final List<Feature> features = [
class FeatureSplittingDemo extends StatelessWidget {
FeatureSplittingDemo({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
ShellRoute(
path: '/',
Expand Down
2 changes: 1 addition & 1 deletion example/lib/feature_splitting/radio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/material.dart' hide Route;
import 'package:tree_router/tree_router.dart';

class RadioFeature extends StatelessWidget {
static Route route = NavigatorRoute(
static RouteBase route = NestedStackRoute(
path: 'radio',
builder: (context) => const RadioFeature(),
routes: [
Expand Down
4 changes: 2 additions & 2 deletions example/lib/links.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide Route;
import 'package:tree_router/tree_router.dart';
import 'package:url_launcher/link.dart';

Expand All @@ -9,7 +9,7 @@ void main() {
class LinkWidgetDemo extends StatelessWidget {
LinkWidgetDemo({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
StackedRoute(
path: '/',
Expand Down
2 changes: 1 addition & 1 deletion example/lib/path_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PathParametersDemo extends StatelessWidget {
return params['id']!;
}

final _router = TreeRouter(
final _router = GoRouter(
routes: [
StackedRoute(
path: '/',
Expand Down
4 changes: 2 additions & 2 deletions example/lib/recursive_shell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Map<String, dynamic> routeMap = {
},
};

List<Route> _buildRoutesRecursive(Map routeMap) {
List<RouteBase> _buildRoutesRecursive(Map routeMap) {
final children = <ShellRoute>[];
for (var key in routeMap.keys) {
final childMap = routeMap[key] as Map;
Expand All @@ -62,7 +62,7 @@ List<Route> _buildRoutesRecursive(Map routeMap) {
class ShellDemo extends StatelessWidget {
ShellDemo({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
ShellRoute(
path: '/',
Expand Down
4 changes: 2 additions & 2 deletions example/lib/stacked_nested_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
class BottomNavigationBarDemo extends StatelessWidget {
BottomNavigationBarDemo({Key? key}) : super(key: key);

final _router = TreeRouter(
final _router = GoRouter(
routes: [
StackedRoute(
path: '/',
Expand All @@ -22,7 +22,7 @@ class BottomNavigationBarDemo extends StatelessWidget {
path: 'a',
builder: (context, child) => AScreen(child: child),
routes: [
NavigatorRoute(
NestedStackRoute(
path: 'b',
builder: (context) => const BScreen(),
routes: [
Expand Down
25 changes: 9 additions & 16 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -70,7 +70,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -99,7 +99,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
version: "0.6.4"
lints:
dependency: transitive
description:
Expand All @@ -120,7 +120,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
Expand All @@ -134,7 +134,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
path_to_regexp:
dependency: transitive
description:
Expand Down Expand Up @@ -167,7 +167,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -202,21 +202,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
version: "0.4.9"
tree_router:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.0.1"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
url_launcher:
dependency: "direct main"
description:
Expand Down Expand Up @@ -279,7 +272,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
sdks:
dart: ">=2.16.1 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.10.0"
16 changes: 9 additions & 7 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ _RecursiveBuildResult _buildMatchRecursive(BuildContext context,
final child = result.widget;
pages.add(_pageForPlatform(child: child));
i = result.newIndex;
} else if (route is r.NavigatorRoute) {
} else if (route is r.NestedStackRoute) {
// Build the first page to display
final page = _buildPage(context, route, routeMatch);
// Build the inner Navigator it by recursively calling this method and
Expand Down Expand Up @@ -76,7 +76,7 @@ class _RecursiveBuildResult {
_RecursiveBuildResult _buildShellRecursive(
BuildContext context, RouteMatch routeMatch, int i, VoidCallback pop) {
final parent = routeMatch.routes[i] as r.ShellRoute;
late final r.Route? child;
late final r.RouteBase? child;

if (i + 1 < routeMatch.routes.length) {
child = routeMatch.routes[i + 1];
Expand All @@ -92,7 +92,7 @@ _RecursiveBuildResult _buildShellRecursive(
final result = _buildShellRecursive(context, routeMatch, i + 1, pop);
childWidget = result.widget;
i = result.newIndex;
} else if (child is r.NavigatorRoute) {
} else if (child is r.NestedStackRoute) {
final key = ValueKey(child);
final result = _buildMatchRecursive(context, routeMatch, i + 1, pop, key);
childWidget = result.widget;
Expand All @@ -111,9 +111,10 @@ Page _pageForPlatform({required Widget child}) {
return MaterialPage(child: child);
}

Widget _callRouteBuilder(BuildContext context, r.Route route, {Widget? child}) {
Widget _callRouteBuilder(BuildContext context, r.RouteBase route,
{Widget? child}) {
late final StackedRouteBuilder builder;
if (route is r.NavigatorRoute) {
if (route is r.NestedStackRoute) {
builder = route.builder;
} else if (route is r.StackedRoute) {
builder = route.builder;
Expand All @@ -130,12 +131,13 @@ Widget _callRouteBuilder(BuildContext context, r.Route route, {Widget? child}) {
context, route, Builder(builder: (context) => builder(context)));
}

Page _buildPage(BuildContext context, r.Route route, RouteMatch routeMatch) {
Page _buildPage(
BuildContext context, r.RouteBase route, RouteMatch routeMatch) {
return _pageForPlatform(child: _callRouteBuilder(context, route));
}

Widget _wrapWithRouteStateScope(
BuildContext context, r.Route route, Widget child) {
BuildContext context, r.RouteBase route, Widget child) {
final globalState = GlobalRouteState.of(context);
if (globalState == null) {
throw Exception('No GlobalRouteState found during route build phase');
Expand Down
Loading

0 comments on commit 5d40ed7

Please sign in to comment.