Skip to content

Commit

Permalink
Correctly handle null case in ProcessText.queryTextActions (#141205)
Browse files Browse the repository at this point in the history
Replace `as Map<Object?, Object?>` to handle nullable case
Fixes runtime issue in Wasm

*Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.*

*List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.*

*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
  • Loading branch information
kevmoo authored Jan 9, 2024
1 parent 988d1a0 commit 0cef3f1
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions packages/flutter/lib/src/services/process_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,27 @@ class DefaultProcessTextService implements ProcessTextService {

@override
Future<List<ProcessTextAction>> queryTextActions() async {
final List<ProcessTextAction> textActions = <ProcessTextAction>[];
final Map<Object?, Object?>? rawResults;
final Map<Object?, Object?> rawResults;

try {
rawResults = await _processTextChannel.invokeMethod(
final Map<Object?, Object?>? result =
await _processTextChannel.invokeMethod(
'ProcessText.queryTextActions',
) as Map<Object?, Object?>;
} catch (e) {
return textActions;
}
) as Map<Object?, Object?>?;

for (final Object? id in rawResults.keys) {
textActions.add(ProcessTextAction(id! as String, rawResults[id]! as String));
if (result == null) {
return <ProcessTextAction>[];
}

rawResults = result;
} catch (e) {
return <ProcessTextAction>[];
}

return textActions;
return <ProcessTextAction>[
for (final Object? id in rawResults.keys)
ProcessTextAction(id! as String, rawResults[id]! as String),
];
}

@override
Expand Down

0 comments on commit 0cef3f1

Please sign in to comment.