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