From 0cef3f162964e555d92a244fb9b2df3af618674e Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Tue, 9 Jan 2024 14:25:54 -0800 Subject: [PATCH] Correctly handle null case in ProcessText.queryTextActions (#141205) Replace `as Map` 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].* --- .../lib/src/services/process_text.dart | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/packages/flutter/lib/src/services/process_text.dart b/packages/flutter/lib/src/services/process_text.dart index 98abd9d27871..88b1180128bf 100644 --- a/packages/flutter/lib/src/services/process_text.dart +++ b/packages/flutter/lib/src/services/process_text.dart @@ -113,22 +113,27 @@ class DefaultProcessTextService implements ProcessTextService { @override Future> queryTextActions() async { - final List textActions = []; - final Map? rawResults; + final Map rawResults; try { - rawResults = await _processTextChannel.invokeMethod( + final Map? result = + await _processTextChannel.invokeMethod( 'ProcessText.queryTextActions', - ) as Map; - } catch (e) { - return textActions; - } + ) as Map?; - for (final Object? id in rawResults.keys) { - textActions.add(ProcessTextAction(id! as String, rawResults[id]! as String)); + if (result == null) { + return []; + } + + rawResults = result; + } catch (e) { + return []; } - return textActions; + return [ + for (final Object? id in rawResults.keys) + ProcessTextAction(id! as String, rawResults[id]! as String), + ]; } @override