mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Change router examples to use SynchronousFuture (#796)
This commit is contained in:
committed by
GitHub
parent
3f5ab56485
commit
252c6fcb57
@@ -6,6 +6,7 @@
|
||||
/// transition animations are shown. (For example, [when two routes are popped
|
||||
/// off the stack](https://github.com/flutter/flutter/issues/12146), however the
|
||||
/// default TransitionDelegate will handle this if you are using Router)
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
@@ -27,7 +28,7 @@ class BooksApp extends StatefulWidget {
|
||||
class _BooksAppState extends State<BooksApp> {
|
||||
BookRouterDelegate _routerDelegate = BookRouterDelegate();
|
||||
BookRouteInformationParser _routeInformationParser =
|
||||
BookRouteInformationParser();
|
||||
BookRouteInformationParser();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -42,14 +43,15 @@ class _BooksAppState extends State<BooksApp> {
|
||||
class BookRouteInformationParser extends RouteInformationParser<BookRoutePath> {
|
||||
@override
|
||||
Future<BookRoutePath> parseRouteInformation(
|
||||
RouteInformation routeInformation) async {
|
||||
RouteInformation routeInformation,
|
||||
) {
|
||||
final uri = Uri.parse(routeInformation.location);
|
||||
|
||||
if (uri.pathSegments.length >= 2) {
|
||||
var remaining = uri.pathSegments[1];
|
||||
return BookRoutePath.details(int.tryParse(remaining));
|
||||
return SynchronousFuture(BookRoutePath.details(int.tryParse(remaining)));
|
||||
} else {
|
||||
return BookRoutePath.home();
|
||||
return SynchronousFuture(BookRoutePath.home());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,10 +115,11 @@ class BookRouterDelegate extends RouterDelegate<BookRoutePath>
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setNewRoutePath(BookRoutePath path) async {
|
||||
Future<void> setNewRoutePath(BookRoutePath path) {
|
||||
if (path.isDetailsPage) {
|
||||
_selectedBook = books[path.id];
|
||||
}
|
||||
return SynchronousFuture<void>(null);
|
||||
}
|
||||
|
||||
void _handleBookTapped(Book book) {
|
||||
@@ -213,9 +216,9 @@ class NoAnimationTransitionDelegate extends TransitionDelegate<void> {
|
||||
Iterable<RouteTransitionRecord> resolve({
|
||||
List<RouteTransitionRecord> newPageRouteHistory,
|
||||
Map<RouteTransitionRecord, RouteTransitionRecord>
|
||||
locationToExitingPageRoute,
|
||||
locationToExitingPageRoute,
|
||||
Map<RouteTransitionRecord, List<RouteTransitionRecord>>
|
||||
pageRouteToPagelessRoutes,
|
||||
pageRouteToPagelessRoutes,
|
||||
}) {
|
||||
final results = <RouteTransitionRecord>[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user