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>
|
Pradumna Saraf <pradumnasaraf@gmail.com>
|
||||||
Kai Yu <yk3372@gmail.com>
|
Kai Yu <yk3372@gmail.com>
|
||||||
Denis Grafov <grafov.denis@gmail.com>
|
Denis Grafov <grafov.denis@gmail.com>
|
||||||
|
TheOneWithTheBraid <the-one@with-the-braid.cf>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:html' as html;
|
import 'dart:html' as html;
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||||
@ -27,6 +28,9 @@ void main() {
|
|||||||
app.main();
|
app.main();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// checking whether the previously set strategy is properly preserved
|
||||||
|
expect(urlStrategy, strategy);
|
||||||
|
|
||||||
expect(strategy.getPath(), '/');
|
expect(strategy.getPath(), '/');
|
||||||
|
|
||||||
final NavigatorState navigator = app.navKey.currentState!;
|
final NavigatorState navigator = app.navKey.currentState!;
|
||||||
@ -44,7 +48,8 @@ void main() {
|
|||||||
class TestUrlStrategy extends UrlStrategy {
|
class TestUrlStrategy extends UrlStrategy {
|
||||||
/// Creates a instance of [TestUrlStrategy] with an empty string as the
|
/// Creates a instance of [TestUrlStrategy] with an empty string as the
|
||||||
/// path.
|
/// 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
|
/// Creates an instance of [TestUrlStrategy] and populates it with a list
|
||||||
/// that has [initialEntry] as the only item.
|
/// 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.
|
/// 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:
|
// 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
|
// TODO(mdebbar): Add integration test https://github.com/flutter/flutter/issues/66852
|
||||||
@JS('_flutter_web_set_location_strategy')
|
@JS('_flutter_web_set_location_strategy')
|
||||||
@ -37,8 +37,7 @@ typedef _AddPopStateListener = ui.VoidCallback Function(html.EventListener);
|
|||||||
|
|
||||||
typedef _StringToString = String Function(String);
|
typedef _StringToString = String Function(String);
|
||||||
|
|
||||||
typedef _StateOperation = void Function(
|
typedef _StateOperation = void Function(Object state, String title, String url);
|
||||||
Object state, String title, String url);
|
|
||||||
|
|
||||||
typedef _HistoryMove = Future<void> Function(int count);
|
typedef _HistoryMove = Future<void> Function(int count);
|
||||||
|
|
||||||
|
@ -9,10 +9,30 @@ import 'dart:ui' as ui;
|
|||||||
import 'js_url_strategy.dart';
|
import 'js_url_strategy.dart';
|
||||||
import 'utils.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.
|
/// Change the strategy to use for handling browser URL.
|
||||||
///
|
///
|
||||||
/// Setting this to null disables all integration with the browser history.
|
/// Setting this to null disables all integration with the browser history.
|
||||||
void setUrlStrategy(UrlStrategy? strategy) {
|
void setUrlStrategy(UrlStrategy? strategy) {
|
||||||
|
_urlStrategy = strategy;
|
||||||
|
|
||||||
JsUrlStrategy? jsUrlStrategy;
|
JsUrlStrategy? jsUrlStrategy;
|
||||||
if (strategy != null) {
|
if (strategy != null) {
|
||||||
jsUrlStrategy = convertToJsUrlStrategy(strategy);
|
jsUrlStrategy = convertToJsUrlStrategy(strategy);
|
||||||
@ -285,6 +305,7 @@ class BrowserPlatformLocation extends PlatformLocation {
|
|||||||
static const String _defaultSearch = '';
|
static const String _defaultSearch = '';
|
||||||
|
|
||||||
html.Location get _location => html.window.location;
|
html.Location get _location => html.window.location;
|
||||||
|
|
||||||
html.History get _history => html.window.history;
|
html.History get _history => html.window.history;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user