Repository: flutter
Issue: [tool_crash] _TypeError: (#0      IOSDevice.stopApp (package:flutter_tools/src/ios/devices.dart)) type 'Null' is not a subtype of type 'IOSApp' of 'app'
Labels: c: crash,platform-ios,tool,P2,team-ios,triaged-ios

Similar to https://github.com/flutter/flutter/issues/111877

## Command
```
flutter attach --app-id io.flutter.examples.gallery
```

## Steps to Reproduce
1. `flutter run` app on iPhone, then `d` to detach without quitting.
2. `flutter attach` to running app.
3. `q` to quit

## Logs
_TypeError: (#0      IOSDevice.stopApp (package:flutter_tools/src/ios/devices.dart))
```
#0      IOSDevice.stopApp (package:flutter_tools/src/ios/devices.dart)
#1      FlutterDevice.exitApps (package:flutter_tools/src/resident_runner.dart:358:19)
#2      ResidentRunner.exitApp (package:flutter_tools/src/resident_runner.dart:1431:67)
#3      ResidentRunner.exit (package:flutter_tools/src/resident_runner.dart:1276:11)
<asynchronous suspension>
#4      TerminalHandler._commonTerminalInputHandler (package:flutter_tools/src/resident_runner.dart:1701:9)
<asynchronous suspension>
#5      TerminalHandler.processTerminalInput (package:flutter_tools/src/resident_runner.dart:1760:7)
<asynchronous suspension>
```
```
[!] Flutter (Channel main, 3.4.0-19.0.pre.370, on macOS 12.6 21G115 darwin-x64, locale en-US)
    • Flutter version 3.4.0-19.0.pre.370 on channel main at /Users/magder/Projects/flutter
    ! Upstream repository git@github.com:jmagman/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to git@github.com:jmagman/flutter.git to dismiss this error.
    • Framework revision 29943e5f73 (26 hours ago), 2022-09-19 19:40:06 -0400
    • Engine revision 5956aa6f38
    • Dart version 2.19.0 (build 2.19.0-217.0.dev)
    • DevTools version 2.17.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/magder/Library/Android/sdk
    • Platform android-31, build-tools 30.0.3
    • ANDROID_SDK_ROOT = /Users/magder/Library/Android/sdk
    • Java binary at: /Applications/Android Studio with Blaze Beta.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
    • Xcode at /Users/magder/Applications/Xcode-14.app/Contents/Developer
    • Build 14A309
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio with Blaze Beta.app/Contents
    • 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.13+0-b1751.21-8125866)

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio with Blaze.app/Contents
    • 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.10+0-b96-7281165)

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.8+10-b944.6916264)

[✓] Android Studio (version 2020.3)
    • Android Studio at /Users/magder/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203.7583922/Android Studio.app/Contents
    • 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.10+0-b96-7281165)

[✓] IntelliJ IDEA Community Edition (version 2021.3.3)
    • IntelliJ at /Applications/IntelliJ CE (stable).app
    • Flutter plugin version 67.0.3
    • Dart plugin version 213.7371

[✓] VS Code (version 1.71.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (3 available)
    • Purple 14 (mobile) • 00008110-0009588C2651401E • ios            • iOS 16.0 20A357
    • macOS (desktop)    • macos                     • darwin-x64     • macOS 12.6 21G115 darwin-x64
    • Chrome (web)       • chrome                    • web-javascript • Google Chrome 105.0.5195.125

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
```

## Flutter Application Metadata
**Type**: malformed
**Version**: null
**Material**: true
**Android X**: false
**Module**: false
**Plugin**: false
**Android package**: null
**iOS bundle identifier**: null
**Creation channel**: null
**Creation framework version**: null
### Plugins
connectivity-3.0.6
connectivity_for_web-0.4.0+1
connectivity_macos-0.2.1+2
device_info-2.0.3
integration_test
url_launcher-6.1.5
url_launcher_android-6.0.17
url_launcher_ios-6.0.17
url_launcher_linux-3.0.1
url_launcher_macos-3.0.1
url_launcher_web-2.0.13
url_launcher_windows-3.0.1
video_player-2.2.11
video_player_web-2.0.12