How do I resolve 'Id does not exist' error? - flutter

So I am building a calculator with flutter and after changing some of my code, I have been getting this error whenever I hot restart, I get this error:
======== Exception caught by Flutter framework =====================================================
The following assertion was thrown during a service extension callback for "ext.flutter.inspector.setSelectionById":
Id does not exist.
When the exception was thrown, this was the stack:
#0 WidgetInspectorService.toObject (package:flutter/src/widgets/widget_inspector.dart:1283:7)
#1 WidgetInspectorService.setSelectionById (package:flutter/src/widgets/widget_inspector.dart:1345:25)
#2 WidgetInspectorService._registerServiceExtensionWithArg.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:864:35)
#3 WidgetInspectorService._registerServiceExtensionWithArg.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:861:17)
#4 BindingBase.registerServiceExtension.<anonymous closure> (package:flutter/src/foundation/binding.dart:597:32)
...
====================================================================================================
I have no clue what the error means and I cant find and answer to it anywhere.
The only thing I can infer is that it is possibly something with the inspector due to
"ext.flutter.inspector.setSelectionById"
but I honestly have no idea. I also believe it might not be to do with my code since it doesn't reference anything in there.
I would extremely appreciate if anyone could at least help me understand the error.
If you need more details, just ask me.

The error was probably due to Flutter Dev Tools being open.

I cannot explain why is this happening? But I solved the problem without restarting the whole app.
My Solution:
I just ran the following command:
flutter pub global activate devtools
It downloaded and compiled the dependencies needed for the devtools and reactivated the devtools.
Thank you !

I got this error when I tried to show a CupertinoTimerPicker inside a SimpleDialog. I solved it by wrapping the CupertinoTimerPicker in a sized box with a defined height and width:
Center(
child: SizedBox(
height: 200,
width: 200,
child: CupertinoTimerPicker(
initialTimerDuration: tempDuration,
onTimerDurationChanged: (value) {
print(value.toString());
tempDuration = value;
},
),
),
),

This seems to be a bug. See this Github issue:
I don't know if it's a Dart-Code, DevTools or Flutter bug...

What helped me:
Stop flutter app on device
Delete .dart_tool and build folders from project tree.
Run fresh flutter app installation on device.

For me, cleaning the project and rebuilding again solved the problem.
Clean Command:
flutter clean
Pub Get Command:
flutter pub get

After restarting the app it failed to build showing an error in app level build.gradle so
commented multidex true at default config // multiDexEnable true
multidex xommenting
2. commented its implementation in the dependencies // implementation 'com.android.support:multidex:1.0.3'
dependency commenting

If you're trying to use DevTools and came up with these outputs in Debug Console, the suggested answers might not do good for you. Simply because some show you "how to avoid" it rather than solving. So, here's my 2 cents about solving this if you want to open up DevTools or Widget Inspector to debug your app.
This bug may have been fixed on newer versions (of devtools?) (or of Dart?) but I couldn't manage to solve it by simply "activating devtools globally". So I had to do some ugly stuff but eventually, I've managed to solve it.
My fixpaghetti steps are as below:
Stop debugging the app
Uninstall the app from device
Delete <project-dir>/build folder
run flutter clean from terminal
run cd android && .\gradlew clean (cd android ; .\gradlew clean if you're on powershell)
run flutter pub global activate devtools
run flutter pub get and wait for IDE to resolve errors (if it automatically does not, restart the IDE)
run the app
and add some prayers along the way. Hope you'll fix it!

I just closed widget inspector. Restarted my app and then oppened widget inspector again, the error is gone.
Before I tryed restarting app without closing widget inspector, then after reading this psot I undertand that the infractor was the inspector s I decided to close and reopen it, and it worked.

You should close your compiler and open it again!!!
(maybe you've changed the ui so much)

Related

Error: Target of URI doesn't exist: 'package:flutter/material.dart'. (uri_does_not_exist at [myapp] test/widget_test.dart:8)

I made an app in Flutter and there are no errors on its Dart file but I suddenly end up with errors on widget_test.dart. can you guys help me out. Thanks
Run flutter clean, and then flutter pub get in the terminal respectively.
If that doesn't work, try running flutter upgrade, and then repeating the initial steps.
Finally, if it still isn't working, you can run flutter doctor to see if there's anything glaringly wrong with your project.

How to debug what's wrong if app crashes only in release mode

I upgraded Flutter to 2.0.0 recently and am stuck with this issue. flutter run and flutter run --profile work perfectly well, but flutter run --release makes app crash after startup. There is no stacktrace, there is no error or warning, there is no build issue or verbose warning, no hint really. I googled a lot, but similar questions were answered like "try to remove this line" or "try to add that line". I couldn't find any clear steps on how to debug what's wrong.
What steps should I take to debug this issue and find the root cause instead of trying meaningless changes on code hoping some of them will eventually fix the issue?
Use adb logcat
OR
Enable debugging in release build, by modifying your android/app/build.gradle
like this
buildTypes {
release {
debuggable true
shrinkResources false
minifyEnabled false
...
}
}
When the error is code related and not in flutter itself sentry should help.
Sentry's Flutter SDK enables automatic reporting of errors, messages,
and exceptions.
You can import it just as any other package
dependencies:
sentry_flutter: ^4.0.6
and configure it as early as possible in you app
import 'package:flutter/widgets.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Future<void> main() async {
await SentryFlutter.init(
(options) => options.dsn = 'put_your_public_key_here',
appRunner: () => runApp(MyApp()),
);
}
To get your public key you just have to sign up on sentry.io and create a flutter project, no need to search for your key your it should be in the example code, it wont let you pass that point without initialiting it so you can't miss it.
The docs regarding flutter can be found here.
You can Use Firebase Analytics to see error logs from your released devices from firebase. Previously it was named as Fabric.
Or you can create your own log tracker, write the logs in a file and upload the log to your server.
You can give options to user to capture log and send to server within "Advanced Settings" or something like that.
try this flutter run --release --no-shrink
Check if you have given correct permission to the app in AndroidManifest.xml, in my case I simply fixed this issue by giving camera permission
<uses-permission android:name="android.permission.CAMERA" />
before the tag
In my case, after two day of confusion because app crashes only in release mode without any error on console, and errors shown in adb logcat not clear (unknown errors), after that I switching Flutter channel from stable to master, after run release on master channel errors started shown as clear messages, I solved these errors then crashes problem solved.
So my steps is:
1- Switching Flutter channel to master by run this command in terminal:
flutter channel master
2- Run upgrade command in terminal:
flutter upgrade
3- Run app as release:
flutter run --release
4- Watch console to see errors...

Flutter Gradle build with error exception

i just setup my android studio and vs code and flutter SDK installed but any time i try running the project i get this Gradle error, i cant figure out what the problem is please help me out.
After running the flutter doctor everything seems to be okay.
the problem might be caused by many factors so lets try some solutions
after each one rebuild your app if the error message changed or the problem solved please keep us informed
run these commands one by one
flutter channel stable
flutter upgrade --force
flutter pub cache repair
cd your app folder
flutter clean
edit app/build.gradle in your host app such as it includes the local repo
like in here
repositories {
maven {
url 'https://storage.googleapis.com/download.flutter.io'
}
}
use VPN and rebuild your app

Flutter Web crashes with Cannot open file client.js

May I ask your help about this error
It's happen when I'm trying for the first time running my flutter web which using flutter run -d chrome
Launching lib\main.dart on Chrome in debug mode...
Syncing files to device Chrome...
25,220ms (!)
GET /dwds/src/injected/client.js
Error thrown by handler.
FileSystemException: Cannot open file, path = 'C:\Users\Acer\flutter\.pub-cache\hosted\pub.dartlang.org\dwds-2.0.1\lib\src\injected\client.js' (OS Error: The system cannot find the path specified.
, errno = 3)
dart:isolate _RawReceivePortImpl._handleMessage
And if I trying run using
flutter run -d web
It's doesn't thrown any error but on the website it goes blank white nothing shown up.
Anyway thanks for your help
adding the following in the pubspec.yaml worked for me. I am using beta channel.
dependencies:
dwds: ^16.0.1
then run command:
flutter update-packages
I was also facing the same issue, I don't know the exact root cause of the problem but I have a hack to make it work.
I was facing the issue after I deleted .pub-cache folder, so from my recycler bin I picked dwds-2.0.1 folder and reverted back. This hack working
add dwds package in your dependencies and run flutter update-packages. It will work :)

new flutter project in vscode has error

when i create a new flutter project in vscode it will immediately shows an error in the main.dart file and gives a gradle error when trying to debug.
shown here: main.dart error
"compiler message: lib/main.dart:68:19: Error: Too few positional arguments: 1 required, 0 given."
I've reinstalled dart and flutter plugins. updated the java install.
in debug console i get this:
debug console
added output of flutter doctor -v
enter image description here
I was also facing the same error, but it was always on my test folder.
This is what I did:
On your terminal, make sure you are in your project repository.
Run the flutter pub get command, it worked for me, may be you
should try it too.
Do you possibly have two different versions of the Flutter SDK on your machine? I wonder if one is being used by flutter create and the other for analysis.
If you're sure you only have one, please open an issue on GitHub and attach a log file for me to investigate.