Solvedflutter Introduction of characters package causes crash on flutter run for preexisting Flutter applications

After e0ed12c I get this error when building:

[        ] [ +566 ms] Error: Could not resolve the package 'characters' in 'package:characters/characters.dart'.
[        ] [ +215 ms] ../../flutter/packages/flutter/lib/src/material/text_field.dart:9:8: Error: Not found: 'package:characters/characters.dart'
[        ] [        ] import 'package:characters/characters.dart';
[        ] [        ]        ^
[        ] [ +261 ms] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:10:8: Error: Not found: 'package:characters/characters.dart'
[        ] [        ] import 'package:characters/characters.dart';
[        ] [        ]        ^
[  +37 ms] [  +96 ms] ../../flutter/packages/flutter/lib/src/services/text_formatter.dart:9:8: Error: Not found: 'package:characters/characters.dart'
[        ] [        ] import 'package:characters/characters.dart';
[        ] [        ]        ^
[+3398 ms] [+3415 ms] ../../flutter/packages/flutter/lib/src/material/text_field.dart:801:61: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]   int get _currentLength => _effectiveController.value.text.characters.length;
[        ] [        ]                                                             ^^^^^^^^^^
[        ] [   +2 ms] ../../flutter/packages/flutter/lib/src/material/text_field.dart:855:43: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]       if (_effectiveController.value.text.characters.length > widget.maxLength) {
[        ] [        ]                                           ^^^^^^^^^^
[+1698 ms] [+1665 ms] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:243:64: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]        assert(obscuringCharacter != null && obscuringCharacter.characters.length == 1),
[        ] [        ]                                                                ^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:358:35: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]     assert(value != null && value.characters.length == 1);
[        ] [        ]                                   ^^^^^^^^^^
[        ] [   +2 ms] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:564:11: Error: 'Characters' isn't a type.
[        ] [        ]     final Characters remaining = string.characters.skipWhile((String currentString) {
[        ] [        ]           ^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:564:41: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]     final Characters remaining = string.characters.skipWhile((String currentString) {
[        ] [        ]                                         ^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:572:42: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]       return _isWhitespace(currentString.characters.first.toString().codeUnitAt(0));
[        ] [        ]                                          ^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:597:47: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]     for (final String currentString in string.characters) {
[        ] [        ]                                               ^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/rendering/editable.dart:599:40: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]           !_isWhitespace(currentString.characters.first.toString().codeUnitAt(0))) {
[        ] [        ]                                        ^^^^^^^^^^
[ +495 ms] [ +466 ms] ../../flutter/packages/flutter/lib/src/services/text_formatter.dart:180:11: Error: 'CharacterRange' isn't a type.
[        ] [        ]     final CharacterRange iterator = CharacterRange(value.text);
[        ] [        ]           ^^^^^^^^^^^^^^
[        ] [   +2 ms] ../../flutter/packages/flutter/lib/src/services/text_formatter.dart:180:37: Error: Method not found: 'CharacterRange'.
[        ] [        ]     final CharacterRange iterator = CharacterRange(value.text);
[        ] [        ]                                     ^^^^^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/services/text_formatter.dart:181:20: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]     if (value.text.characters.length > maxLength) {
[        ] [        ]                    ^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/services/text_formatter.dart:200:61: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]     if (maxLength != null && maxLength > 0 && newValue.text.characters.length > maxLength) {
[        ] [        ]                                                             ^^^^^^^^^^
[        ] [        ] ../../flutter/packages/flutter/lib/src/services/text_formatter.dart:203:25: Error: The getter 'characters' isn't defined for the class 'String'.
[        ] [        ] Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
[        ] [        ]       if (oldValue.text.characters.length == maxLength) {
[        ] [        ]                         ^^^^^^^^^^

@justinmc

37 Answers

✔️Accepted Answer

In my case, I resolved the issue with flutter clean

Other Answers:

Installing https://pub.dev/packages/characters solved the problem for me.

This happened to me after upgrading flutter, running flutter clean solved it for me

I quickly tested this on a sample app and got the same issue. Here is my stack trace for my first flutter run.

First Stack Trace
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Error: Could not resolve the package 'characters' in 'package:characters/characters.dart'.
../../flutter/packages/flutter/lib/src/material/text_field.dart:9:8: Error: Not found: 'package:characters/characters.dart'
import 'package:characters/characters.dart';
       ^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:10:8: Error: Not found: 'package:characters/characters.dart'
import 'package:characters/characters.dart';
       ^
../../flutter/packages/flutter/lib/src/services/text_formatter.dart:9:8: Error: Not found: 'package:characters/characters.dart'
import 'package:characters/characters.dart';
       ^
../../flutter/packages/flutter/lib/src/material/text_field.dart:801:61: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
  int get _currentLength => _effectiveController.value.text.characters.length;
                                                            ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/material/text_field.dart:855:43: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
      if (_effectiveController.value.text.characters.length > widget.maxLength) {
                                          ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:243:64: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
       assert(obscuringCharacter != null && obscuringCharacter.characters.length == 1),
                                                               ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:358:35: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
    assert(value != null && value.characters.length == 1);
                                  ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:564:11: Error: 'Characters' isn't a type.
    final Characters remaining = string.characters.skipWhile((String currentString) {
          ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:564:41: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
    final Characters remaining = string.characters.skipWhile((String currentString) {
                                        ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:572:42: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
      return _isWhitespace(currentString.characters.first.toString().codeUnitAt(0));
                                         ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:597:47: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
    for (final String currentString in string.characters) {
                                              ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/rendering/editable.dart:599:40: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
          !_isWhitespace(currentString.characters.first.toString().codeUnitAt(0))) {
                                       ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/services/text_formatter.dart:180:11: Error: 'CharacterRange' isn't a type.
    final CharacterRange iterator = CharacterRange(value.text);
          ^^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/services/text_formatter.dart:180:37: Error: Method not found: 'CharacterRange'.
    final CharacterRange iterator = CharacterRange(value.text);
                                    ^^^^^^^^^^^^^^
../../flutter/packages/flutter/lib/src/services/text_formatter.dart:181:20: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
    if (value.text.characters.length > maxLength) {
                   ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/services/text_formatter.dart:200:61: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
    if (maxLength != null && maxLength > 0 && newValue.text.characters.length > maxLength) {
                                                            ^^^^^^^^^^
../../flutter/packages/flutter/lib/src/services/text_formatter.dart:203:25: Error: The getter 'characters' isn't defined for the class 'String'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'characters'.
      if (oldValue.text.characters.length == maxLength) {
                        ^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Acharacters%2Fcharacters.dart; message=StandardFileSystem only supports file:* and data:* URIs)
[38;5;248m#0      StandardFileSystem.entityForUri  (package:front_end/src/api_prototype/standard_file_system.dart:33:7)�[39;49m
[38;5;248m#1      asFileUri  (package:vm/kernel_front_end.dart:626:37)�[39;49m

[38;5;248m#2      writeDepfile  (package:vm/kernel_front_end.dart:820:21)�[39;49m
[38;5;244m<asynchronous suspension>[39;49m
[38;5;248m#3      FrontendCompiler.compile  (package:frontend_server/frontend_server.dart:566:15)�[39;49m
[38;5;244m<asynchronous suspension>[39;49m
[38;5;248m#4      _FlutterFrontendCompiler.compile  (package:flutter_frontend_server/server.dart:40:22)�[39;49m
[38;5;248m#5      starter  (package:flutter_frontend_server/server.dart:178:27)�[39;49m
[38;5;248m#6      main  (file:///b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:8:30)�[39;49m
[38;5;244m#7      _startIsolate.<anonymous closure>  (dart:isolate-patch/isolate_patch.dart:299:32)�[39;49m
[38;5;244m#8      _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:168:12)�[39;49m




FAILURE: Build failed with an exception.
* Where:
Script '/Users/shihaohong/dev/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 896

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/shihaohong/dev/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Exited (sigterm)
Exception: Gradle task assembleDebug failed with exit code 1

On a subsequent attempt to flutter run, I saw this at the beginning of the stack trace, followed by the contents of the first stack trace:

Invalid depfile: /Users/shihaohong/dev/apps/test_tab_animation/.dart_tool/flutter_build/2094b875432a5b46b5b5cc10f81d4205/kernel_snapshot.d
Invalid depfile: /Users/shihaohong/dev/apps/test_tab_animation/.dart_tool/flutter_build/2094b875432a5b46b5b5cc10f81d4205/kernel_snapshot.d

Based on a hunch, I deleted the .dart_tool directory from the sample Flutter application and tried flutter run again, and it ended up working. It might be an issue with how the app is caching packages? If that's the case, this crash will affect any Flutter application created before the characters package commit was introduced.

That being said, maybe we should revert the characters package PR until we figure out what's going on.

cc/ @justinmc @jonahwilliams

If you have updated to newest version, please run 'flutter clean'. It will resolve your issue.

Related Issues:

459
flutter Multiple commands produce '/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework
I was able to fix it by opening the Runner workspace project in Xcode 10 Then navigate to File ...
449
flutter App Store iOS submission fails: The bundle Runner.app/Frameworks/App.framework does not support the minimum OS Version specified in the Info.plist
After doing a flutter clean changing MinimumOSVersion (inside /ios/Flutter/AppframeworkInfo.plist) t...
418
flutter 'com.android.support:appcompat-v7' has different version for the compile (26.1.0) and runtime (27.0.1) classpath
is like this i receive an error when i run flutter run My gradle.build file is: flutter doctor: ...
409
flutter Why does my text not wrap?
You have to wrap Column in a flexible Without flexible the column's width is not constrained to the ...
383
flutter Unexpected top padding in ListView put inside scaffold with no appBar
Yeah this is intentional If you put a widget before the ListView you should wrap the ListView with a...
315
flutter Missing xcode dependency: Python module "six"
try python2.x -m pip install six by @humblerookie's suggest or brew reinstall python@2 pip install s...
285
flutter flutter messaging: set the notification icon
Hey guys I fought with this for the better part of a day For some strange reason there are no tutori...
281
flutter Issue with cloud_firestore - Cannot fit requested classes in a single dex file.
As a workaround you can try enabling mutlidex for Android App by following Enable multidex for apps ...
265
flutter D8: Program type already present: io.flutter.BuildConfig
@smrucv I received the same error but after flutter clean and flutter packages get everything works ...
250
238
flutter Introduction of characters package causes crash on flutter run for preexisting Flutter applications
In my case I resolved the issue with flutter clean After e0ed12c I get this error when building: @ju...
221
flutter Making Network http error SocketException: Failed host lookup
@hoc081098 Double-check / make sure you have <uses-permission android:name=android.permission.INTERN...
216
flutter Support inlining Android/iOS views
iOS view embedding support has landed on master This is still just a preview There are multiple open...
207
flutter ✗ Android license status unknown.
Hi everyone Steps to Reproduce Please tell us what you were doing and what went wrong If you are run...
185
flutter idevice_id cannot run on catalina
When you're developing on Catalina Steps to Reproduce Run flutter doctor on macOS Catalina I get the...
181
flutter type 'List<dynamic>' is not a subtype of type 'List<String>'
The problem is your fromMap constructor is reading from a Map<String dynamic> ...
178
flutter TextField is hidden by keyboard inside of a Modal Bottom Sheet
This may not work for all situations but I have a modalBottomSheet that contains only a TextField ...
160
flutter Dismissing keyboard programatically
This is a better way as it also clears the focus: FocusScope.of(context).requestFocus(new FocusNode(...
157
flutter How to solve: Android license status unknown and also Android sdkmanager tool not found? Tried everything(as i think)
The answer is here Uncheck Hide Obsolete Packages and you'll see Android SDK Tools (Obsolete) 26.1.1...
156
flutter MissingPluginException: No implementation found for method
@mravn-google Yeah turned out I had to quit the flutter run process and start it up again Just a ful...
156
flutter firebase_auth: ^0.8.0+1 crashes on Android
Here i put this in file: android/gradle.properties: and changed targetSdkVersion to 28 and it worked...
153
flutter Android sdkmanager tool not found (C:...\Local\Android\sdk\tools\bin\sdkmanager)
This worked for me: open Android Studio's SDK Manager go to the Android SDK tab under SDK Tools ...
149
flutter 1.22.2 - Flutter plugin not installed; this adds Flutter specific functionality.
Hey @bhanuka96 try this line of code How do I fix this android plugin error? This error is being com...
139
flutter [ios][release] GeneratedPluginRegistrant.m Module not found
I may have found the answer from this comment: #21989 (comment) Seems like by opening up the project...
137
flutter [App.framework] Linked and embedded framework 'App.framework' was built for iOS/iOS Simulator
Does rm -rf ios/Flutter/App.framework get you unstuck? SOLUTION @jmagman has written an article on h...
134
flutter Bad state: Future already completed
I had the same issue.. The problem was the same that @soaresgabriel said but I was not navigating di...
129
flutter Execution failed for task ':app:compileFlutterBuildDebug' Issue
Hi @Ramihtet your logs show a different flutter version; could you please run flutter channel stable...
124
flutter Unable to load Asset - wrong indentation in pubspec.yaml
Is your assets key underneath a flutter: key as well? https://flutter.io/assets-and-images/ ...
124
flutter Flutter 1.12.13+hotfix.5: Flutter Run: The shrinker may have failed to optimize the Java bytecode.
The plugin seems to work correctly after adding minifyEnabled true as shown above in app-level build...
121
flutter Create iOS IPA from command line
This is what I ended up using as a complete release script ready for uploading to the Play Store/App...
118
flutter FutureBuilder rebuilds unnecessarily when we long press on FAB button or appBar UI.
Hello I believe the problem here is that didUpdateWidget of the FutureBuilder state is being called ...
112
flutter LinearGradient stops/colors properties as named parameters fail
Ah nice I'm on master but also had to flutter clean and then restart VS Code and now it has gone awa...
109
flutter gradle initializing taking forever
MacOS Android Studio 3.0.1 Try to install gradle manually (https://services.gradle.org/distributions...
102
flutter invalid text selection: TextSelection with TextEditingController
Can also confirm clearing text in single textfield throws exactly same exception FocusScope.of(conte...
102
flutter Bad state: Unexpected diagnostics:
Was able to fixed After add this in pubspec.yaml the error gone Thanks #62996 and #62240 ...
98
flutter [cloud_firestore 0.12.6] CloudFirestorePlugin.m:6:9: fatal error: 'UserAgent.h' file not found
I tried this • flutter clean • Clean Build Folder from Xcode • delete Podfile.lock But this didn't w...
95
flutter How to run on iOS simulator?
Make sure you have run sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer sudo xc...
92
flutter flutter run failed due to 'Permission denied' when replacing signature of 'Flutter.framework'
After investigating i think the root cause was the xcode_backend.sh will mark the files under Flutte...
91
flutter [firebase_crashlytics] Gradle build failed
@TheVinhLuong Had the same issue your workaround worked thanks! @livingstonex If you've followed ins...
91
flutter "Minimum supported Gradle version is 5.4.1. Current version is 4.10.2."
Ran across this problem myself If anyone comes across this from google Steps to Reproduce Not much i...
91
flutter Analyzer 0.39.15 seems to break build_runner or json_serializable
For anyone searching here you can set the override for now inside your pubspec.yaml: As explained in...
89
flutter Execution failed for task ':firebase_auth:compileDebugJavaWithJavac'.
This is what helped me: Go to android/app/build.gradle file and change compileSdkVersion and targetS...
88
flutter flutter doctor returns [Unhandled exception: Exception: idevice_id returned an error]
running sudo pkill usbmuxd worked for me on Mac OSX I ran the flutter doctor there were some brew in...
88
flutter "-bash: webdev: command not found"
This worked for me: I am trying to get the web flutter running Updated the bash_profile with export ...
86
flutter [Error: Could not resolve the package 'characters' in 'package:characters/characters.dart'.] after enabling web
Hi @gamepro110 new project follow steps on this link for the SETUP only trying to build for android ...
85
flutter type 'Color' is not a subtype of type 'MaterialColor' of 'primarySwatch' where Color is from dart:ui
Looks like this is working as intended: primarySwatch takes a ColorSwatch [which MaterialColor exten...
83
flutter TextFormField Android "Failed assertion: 'initialValue == null || controller == null': is not true." Despite controller being null in debug.
I just had this problem For anyone else coming along check if you have passed both initialValue and ...
82
flutter AAPT: error: resource android:attr/fontVariationSettings not found after Flutter Upgrade
Setting compileSdkVersion 28 in app/build.gradle fixed the issue for me. My flutter application used...