Implemented getter to expose current url strategy for web plugins (#90708)
This commit is contained in:
parent
e32201235f
commit
01afd64bcc
1
AUTHORS
1
AUTHORS
@ -88,3 +88,4 @@ Casey Rogers <caseycrogers@berkeley.edu>
|
||||
Pradumna Saraf <pradumnasaraf@gmail.com>
|
||||
Kai Yu <yk3372@gmail.com>
|
||||
Denis Grafov <grafov.denis@gmail.com>
|
||||
TheOneWithTheBraid <the-one@with-the-braid.cf>
|
||||
|
@ -5,6 +5,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:html' as html;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
@ -27,6 +28,9 @@ void main() {
|
||||
app.main();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// checking whether the previously set strategy is properly preserved
|
||||
expect(urlStrategy, strategy);
|
||||
|
||||
expect(strategy.getPath(), '/');
|
||||
|
||||
final NavigatorState navigator = app.navKey.currentState!;
|
||||
@ -44,7 +48,8 @@ void main() {
|
||||
class TestUrlStrategy extends UrlStrategy {
|
||||
/// Creates a instance of [TestUrlStrategy] with an empty string as the
|
||||
/// path.
|
||||
factory TestUrlStrategy() => TestUrlStrategy.fromEntry(const TestHistoryEntry(null, null, ''));
|
||||
factory TestUrlStrategy() =>
|
||||
TestUrlStrategy.fromEntry(const TestHistoryEntry(null, null, ''));
|
||||
|
||||
/// Creates an instance of [TestUrlStrategy] and populates it with a list
|
||||
/// that has [initialEntry] as the only item.
|
||||
|
@ -23,7 +23,7 @@ typedef _JsSetUrlStrategy = void Function(JsUrlStrategy?);
|
||||
/// A JavaScript hook to customize the URL strategy of a Flutter app.
|
||||
//
|
||||
// Keep this in sync with the JS name in the web engine. Find it at:
|
||||
// https://github.com/flutter/engine/blob/custom_location_strategy/lib/web_ui/lib/src/engine/navigation/js_url_strategy.dart
|
||||
// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/src/engine/navigation/js_url_strategy.dart
|
||||
//
|
||||
// TODO(mdebbar): Add integration test https://github.com/flutter/flutter/issues/66852
|
||||
@JS('_flutter_web_set_location_strategy')
|
||||
@ -37,8 +37,7 @@ typedef _AddPopStateListener = ui.VoidCallback Function(html.EventListener);
|
||||
|
||||
typedef _StringToString = String Function(String);
|
||||
|
||||
typedef _StateOperation = void Function(
|
||||
Object state, String title, String url);
|
||||
typedef _StateOperation = void Function(Object state, String title, String url);
|
||||
|
||||
typedef _HistoryMove = Future<void> Function(int count);
|
||||
|
||||
|
@ -9,10 +9,30 @@ import 'dart:ui' as ui;
|
||||
import 'js_url_strategy.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
/// Saves the current [UrlStrategy] to be accessed by [urlStrategy] or
|
||||
/// [setUrlStrategy].
|
||||
///
|
||||
/// This is particularly required for web plugins relying on valid URL
|
||||
/// encoding.
|
||||
//
|
||||
// Keep this in sync with the default url strategy in the web engine.
|
||||
// Find it at:
|
||||
// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/src/engine/window.dart#L360
|
||||
//
|
||||
UrlStrategy? _urlStrategy = const HashUrlStrategy();
|
||||
|
||||
/// Returns the present [UrlStrategy] for handling the browser URL.
|
||||
///
|
||||
/// In case null is returned, the browser integration has been manually
|
||||
/// disabled by [setUrlStrategy].
|
||||
UrlStrategy? get urlStrategy => _urlStrategy;
|
||||
|
||||
/// Change the strategy to use for handling browser URL.
|
||||
///
|
||||
/// Setting this to null disables all integration with the browser history.
|
||||
void setUrlStrategy(UrlStrategy? strategy) {
|
||||
_urlStrategy = strategy;
|
||||
|
||||
JsUrlStrategy? jsUrlStrategy;
|
||||
if (strategy != null) {
|
||||
jsUrlStrategy = convertToJsUrlStrategy(strategy);
|
||||
@ -285,6 +305,7 @@ class BrowserPlatformLocation extends PlatformLocation {
|
||||
static const String _defaultSearch = '';
|
||||
|
||||
html.Location get _location => html.window.location;
|
||||
|
||||
html.History get _history => html.window.history;
|
||||
|
||||
@override
|
||||
|
Loading…
x
Reference in New Issue
Block a user