0

I am new to Flutter. So sorry if my question is silly...

In Flutter is there a way to see which line throws an error?

E.g. I have this in console.

And this in the stimulator.

Can I understand from it which line throws it?

  • Is faterunner yours? It appears to be at story.dart, line 200. – user2740650 2 days ago
  • Also, if you run in the debugger, it should stop when the exception happens. Are you using VSCode or Android Studio BTW? – user2740650 2 days ago
  • Is faterunner yours? Yes, it's the name of the app. It appears to be at story.dart, line 200. So apparently it's #1 line in the section 'When the exception was thrown...' that tell you where it went wrong, did i get it? Also, if you run in the debugger... I am quite positive that I do actually. There is a banner that says 'debug' in the right up corner of the simulator._ Are you using VSCode or Android Studio BTW_ It's Android Studio. Do you have any recommendations in regards? – Shalugin 2 days ago
  • 1
    I asked because I've only used VSCode (at least with Flutter). In VSCode there's an option to stop on all exceptions (by default, it stops only on unhandled exceptions). Android Studio would have the same features but I'm not sure how to set them offhand. The "debug" in the corner doesn't mean you are debugging; it means your app is built in debug mode (not release mode, which is faster and optimized). And yes, when you see a stack trace, look for a line that mentions YOUR code. – user2740650 2 days ago
  • Come to think of it, you want to stop only on unhandled exceptions (meaning no try/catchError has handled it). In this case it's clearly unhandled since you have a crash. But I think if you ran it via the debugger (check docs for how), it would probably stop and make it obvious where the problem is. But the info in the stack trace is also enough to take a good guess where to look in your code. – user2740650 2 days ago
0

Using the console2020欧洲杯手机版注册See all the files in blue on the console? They represent all files (yours and those from the Flutter SDK and libraries) connected to the error message.

2020欧洲杯手机版注册There is a high chance that the line that throws an/the error is not from the libraries but from your own code. So, what do you have to do?

2020欧洲杯手机版注册Scan all files in blue that are from your own code and look for the one that has the strongest relationship with the error message.

For example, in your case, story.dart is your own code. Ctrl + click on story.dart files in blue to see the line that may have caused the error/exception. In your case, there is a high chance that you are trying to read or delete an element from an empty list.

You can also use the VSCode debugger to do this

0

2020欧洲杯手机版注册You can see the line of code that has error in your screenshot bro, all you need to do is read it and we can see that the error is in #1.

2020欧洲杯手机版注册it says that you story.dart has error on line 200

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.