mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
48 lines
1.2 KiB
Dart
48 lines
1.2 KiB
Dart
// Copyright 2021, the Flutter project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'parsed_route.dart';
|
|
import 'route_state.dart';
|
|
|
|
class SimpleRouterDelegate extends RouterDelegate<ParsedRoute>
|
|
with ChangeNotifier, PopNavigatorRouterDelegateMixin<ParsedRoute> {
|
|
final RouteState routeState;
|
|
final WidgetBuilder builder;
|
|
|
|
@override
|
|
final GlobalKey<NavigatorState> navigatorKey;
|
|
|
|
SimpleRouterDelegate({
|
|
required this.routeState,
|
|
required this.builder,
|
|
required this.navigatorKey,
|
|
}) {
|
|
routeState.addListener(notifyListeners);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => builder(context);
|
|
|
|
@override
|
|
Future<void> setNewRoutePath(ParsedRoute configuration) async {
|
|
routeState.route = configuration;
|
|
return SynchronousFuture(null);
|
|
}
|
|
|
|
@override
|
|
ParsedRoute get currentConfiguration => routeState.route;
|
|
|
|
@override
|
|
void dispose() {
|
|
routeState.removeListener(notifyListeners);
|
|
routeState.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|