Метод restoreRouteInformation
Метод restoreRouteInformation класса RouteInformationParser router вызывает его, когда нужно обновить адрес в браузере или сообщить платформе новый URI.
Синтаксис
@override
RouteInformation restoreRouteInformation(AppConfig configuration) {
return RouteInformation(uri: Uri.parse(configuration.path));
}
Параметры
| Параметр | Описание |
|---|---|
configuration |
Текущая конфигурация из RouterDelegate.
|
Пример
Давайте восстановим URI с path:
import 'package:flutter/material.dart';
class PathConfig
{
PathConfig(this.path);
final String path;
}
class PathParser extends RouteInformationParser<PathConfig>
{
@override
Future<PathConfig> parseRouteInformation(
RouteInformation routeInformation,
) async {
return PathConfig(routeInformation.uri.path);
}
@override
RouteInformation restoreRouteInformation(PathConfig configuration) {
return RouteInformation(
uri: Uri.parse(configuration.path),
);
}
}
void main()
{
var parser = PathParser();
var info = parser.restoreRouteInformation(PathConfig('/detail'));
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: Text('${info.uri}'),
),
),
),
);
}
На экране по центру URI с путём '/detail'.
Пример
Давайте положим state в RouteInformation:
import 'package:flutter/material.dart';
class TagConfig
{
TagConfig(this.tag);
final String tag;
}
class TagParser extends RouteInformationParser<TagConfig>
{
@override
Future<TagConfig> parseRouteInformation(
RouteInformation routeInformation,
) async {
return TagConfig(routeInformation.state as String? ?? 'abcde');
}
@override
RouteInformation restoreRouteInformation(TagConfig configuration) {
return RouteInformation(
uri: Uri.parse('/tag'),
state: configuration.tag,
);
}
}
void main()
{
var info = TagParser().restoreRouteInformation(TagConfig('12345'));
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: Text('${info.state}'),
),
),
),
);
}
На экране по центру '12345' из state восстановленного RouteInformation.
Смотрите также
-
метод
parseRouteInformation,
читаетRouteInformation -
класс
RouteInformation,
результатrestoreRouteInformation -
класс
RouterDelegate,
источник configuration -
виджет
Router,
синхронизирует URI с delegate