This commit is contained in:
Michael Goderbauer 2019-09-16 16:04:12 -07:00 committed by GitHub
parent 68c0c11bad
commit a94cccbeee
2 changed files with 17 additions and 18 deletions

View File

@ -8,10 +8,12 @@ part of engine;
// Some parts of this file were inspired/copied from the AngularDart router.
/// Ensures that [str] is prefixed with [leading]. If [str] is already prefixed,
/// it'll be returned unchanged. If it's not, this function will prefix it.
/// Ensures that `str` is prefixed with `leading`.
///
/// The [applyWhenEmpty] flag controls whether this function should prefix [str]
/// If `str` is already prefixed, it'll be returned unchanged. If it's not,
/// this function will prefix it.
///
/// The `applyWhenEmpty` flag controls whether this function should prefix `str`
/// or not when it's an empty string.
///
/// ```dart
@ -27,9 +29,10 @@ String ensureLeading(String str, String leading, {bool applyWhenEmpty = true}) {
return str.startsWith(leading) ? str : '$leading$str';
}
/// `LocationStrategy` is responsible for representing and reading route state
/// from the browser's URL. At the moment, only one strategy is implemented:
/// [HashLocationStrategy].
/// [LocationStrategy] is responsible for representing and reading route state
/// from the browser's URL.
///
/// At the moment, only one strategy is implemented: [HashLocationStrategy].
///
/// This is used by [BrowserHistory] to interact with browser history APIs.
abstract class LocationStrategy {
@ -61,14 +64,14 @@ abstract class LocationStrategy {
/// to represent its state.
///
/// In order to use this [LocationStrategy] for an app, it needs to be set in
/// [ui.window.webOnlyLocationStrategy]:
/// [ui.window.locationStrategy]:
///
/// ```dart
/// import 'package:flutter_web/material.dart';
/// import 'package:flutter_web/ui.dart' as ui;
///
/// void main() {
/// ui.window.webOnlyLocationStrategy = const ui.HashLocationStrategy();
/// ui.window.locationStrategy = const ui.HashLocationStrategy();
/// runApp(MyApp());
/// }
/// ```
@ -124,8 +127,10 @@ class HashLocationStrategy extends LocationStrategy {
return _waitForPopState();
}
/// Waits until the next popstate event is fired. This is useful for example
/// to wait until the browser has handled the `history.back` transition.
/// Waits until the next popstate event is fired.
///
/// This is useful for example to wait until the browser has handled the
/// `history.back` transition.
Future<void> _waitForPopState() {
final Completer<void> completer = Completer<void>();
ui.VoidCallback unsubscribe;
@ -137,10 +142,10 @@ class HashLocationStrategy extends LocationStrategy {
}
}
/// `PlatformLocation` encapsulates all calls to DOM apis, which allows the
/// [PlatformLocation] encapsulates all calls to DOM apis, which allows the
/// [LocationStrategy] classes to be platform agnostic and testable.
///
/// The `PlatformLocation` class is used directly by all implementations of
/// The [PlatformLocation] class is used directly by all implementations of
/// [LocationStrategy] when they need to interact with the DOM apis like
/// pushState, popState, etc...
abstract class PlatformLocation {

View File

@ -81,12 +81,6 @@ class EngineWindow extends ui.Window {
_browserHistory.locationStrategy = strategy;
}
/// This setter is used by [WebNavigatorObserver] to update the url to
/// reflect the [Navigator]'s current route name.
set webOnlyRouteName(String routeName) {
_browserHistory.setRouteName(routeName);
}
@override
void sendPlatformMessage(
String name,