Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions lib/web_ui/lib/src/engine/browser_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
/// }
/// ```
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down