Repository: flutter
Issue: Hot restart does not stop code execution
Labels: framework,dependency: dart,a: debugging,has reproducible steps,P3,found in release: 3.3,found in release: 3.4,team-framework,triaged-framework

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->
First of all I'd like to say that I've looked everywhere, on StackOverflow, among the closed and open issues of GitHub, in the documentation, and nobody talks about it!
I hope I have not created a duplicate, (if so I apologize in advance)

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->
1. Create a button with a callback inside onPressed
2. create a code like this:
 `int i = 0;
i++;
// some dangerous code`
4. if I debug my application and put a breakpoint on the "i++" line and I realize that the row afterwards would execute accidentally created dangerous code (e.g., a database query that would delete a table) and I realize that the condition for which this statement is executed is wrong, I normally apply the correction and click Hot restart without having to recompile the application
5. Unexpected behavior appears here, because flutter before performing a Hot restart tries to complete the function it is in and would cause the wrong code to execute 

**Expected results:** Immediate code termination during debugging and application restart

**Actual results:** Executing the wrong code

<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->
Small piece of code to insert into a button callback:
```dart
int i = 0;
print("a loop is incoming!!");
// Dangerous code
do{
print("Bad code :(");
i--;
}while(i <10);
```

</details>
This problem happens with any application, and one consequence of this behavior is:
if I am in a while loop and the output condition is wrong, even if I press Hot restart, it will not respond since it will try to terminate the code execution (impossible being in a loop)

N.B. this misbehavior runs with both VS Code and Android Studio and other IDEs
<details>
  <summary>Logs</summary>



<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 3.3.5, on Microsoft Windows [Versione 10.0.22621.674], locale it-IT)
    • Flutter version 3.3.5 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d9111f6402 (7 days ago), 2022-10-19 12:27:13 -0700
    • Engine revision 3ad69d7be3
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at C:\Users\Ddany\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Professional 2022 17.2.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional
    • Visual Studio Professional 2022 version 17.2.32616.157
    • Windows 10 SDK version 10.0.22000.0

[✓] Android Studio (version 2021.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)

[✓] VS Code (version 1.72.2)
    • VS Code at C:\Users\Ddany\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.50.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Versione 10.0.22621.674]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 106.0.5249.119
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 106.0.1370.52

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
```
I do not attach the other commands since this behavior is not given by the individual application
</details>

Thank you for listening and I hope I haven't violated any rules and that my request will be heard and perhaps adjusted in the future
<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->