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
28 changes: 16 additions & 12 deletions lib/web_ui/lib/src/engine/history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ class BrowserHistory {
_setupFlutterEntry(_locationStrategy);

// 2. Send a 'popRoute' platform message so the app can handle it accordingly.
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(_popRouteMethodCall),
(_) {},
);
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(_popRouteMethodCall),
(_) {},
);
}
} else if (_isFlutterEntry(event.state)) {
// We get into this scenario when the user changes the url manually. It
// causes a new entry to be pushed on top of our "flutter" one. When this
Expand All @@ -111,13 +113,15 @@ class BrowserHistory {
_userProvidedRouteName = null;

// Send a 'pushRoute' platform message so the app handles it accordingly.
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(
MethodCall('pushRoute', newRouteName),
),
(_) {},
);
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(
MethodCall('pushRoute', newRouteName),
),
(_) {},
);
}
} else {
// The user has pushed a new entry on top of our flutter entry. This could
// happen when the user modifies the hash part of the url directly, for
Expand Down
4 changes: 4 additions & 0 deletions lib/web_ui/lib/src/engine/keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class Keyboard {
static const JSONMessageCodec _messageCodec = JSONMessageCodec();

void _handleHtmlEvent(html.KeyboardEvent event) {
if (ui.window.onPlatformMessage == null) {
return;
}

if (_shouldIgnoreEvent(event)) {
return;
}
Expand Down
62 changes: 34 additions & 28 deletions lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -819,44 +819,50 @@ class TextEditingChannel {

/// Sends the 'TextInputClient.updateEditingState' message to the framework.
void updateEditingState(int clientId, EditingState editingState) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall('TextInputClient.updateEditingState', <dynamic>[
clientId,
editingState.toFlutter(),
]),
),
_emptyCallback,
);
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall('TextInputClient.updateEditingState', <dynamic>[
clientId,
editingState.toFlutter(),
]),
),
_emptyCallback,
);
}
}

/// Sends the 'TextInputClient.performAction' message to the framework.
void performAction(int clientId, String inputAction) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.performAction',
<dynamic>[clientId, inputAction],
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.performAction',
<dynamic>[clientId, inputAction],
),
),
),
_emptyCallback,
);
_emptyCallback,
);
}
}

/// Sends the 'TextInputClient.onConnectionClosed' message to the framework.
void onConnectionClosed(int clientId) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.onConnectionClosed',
<dynamic>[clientId],
if (ui.window.onPlatformMessage != null) {
ui.window.onPlatformMessage(
'flutter/textinput',
const JSONMethodCodec().encodeMethodCall(
MethodCall(
'TextInputClient.onConnectionClosed',
<dynamic>[clientId],
),
),
),
_emptyCallback,
);
_emptyCallback,
);
}
}
}

Expand Down