Repository: flutter
Issue: [flutter_markdown] onSelectionChanged is nullable, null check operator is used without explicit null check
Labels: a: text input,framework,package,a: production,team-ecosystem,P2,p: flutter_markdown,triaged-ecosystem,fyi-text-input

### What package does this bug report belong to?

flutter_markdown

### What target platforms are you seeing this bug on?

Web

### Have you already upgraded your packages?

Yes

### Dependency versions

<details><summary>pubspec.lock</summary>

```lock
  flutter_markdown:
    dependency: "direct main"
    description:
      name: flutter_markdown
      sha256: "9921f9deda326f8a885e202b1e35237eadfc1345239a0f6f0f1ff287e047547f"
      url: "https://pub.dev"
    source: hosted
    version: "0.7.1"
```

</details>


### Steps to reproduce

Honestly I am not entirely sure about reproduction steps, as I see the issue from Sentry, and since generally error reporting is subpar, I essentially get this stack:

<details><summary>Stack</summary>

```lock

/root/.pub-cache/hosted/pub.dev/flutter_markdown-0.7.1/lib/src/builder.dart in MarkdownBuilder._buildRichText.<anonymous function>.fgc.prototype.$2 at line 966:17

Called from: ../../../../flutter/packages/flutter/lib/src/material/selectable_text.dart in _SelectableTextState._handleSelectionChanged

org-dartlang-sdk:///dart-sdk/lib/_internal/js_runtime/lib/js_helper.dart in A.iWN at line 2274:9
../../../../flutter/packages/flutter/lib/src/widgets/framework.dart in EditableTextState._handleSelectionChanged at line 925:26
../../../../flutter/packages/flutter/lib/src/widgets/editable_text.dart in EditableTextState._formatAndSetValue at line 3903:7
../../../../flutter/packages/flutter/lib/src/widgets/editable_text.dart in EditableTextState.userUpdateTextEditingValue at line 4271:5
../../../../flutter/packages/flutter/lib/src/rendering/editable.dart in RenderEditable._setSelection at line 734:5
../../../../flutter/packages/flutter/lib/src/rendering/editable.dart in RenderEditable.selectPositionAt at line 2090:5
../../../../flutter/packages/flutter/lib/src/rendering/editable.dart in A.aIf.prototype.nQ at line 2074:8
../../../../flutter/packages/flutter/lib/src/rendering/editable.dart in TextSelectionGestureDetectorBuilder.onTapDown at line 2067:5
```
</details>

But checking the source code there is indeed a `onSelectionChanged!` without null checking first (at least not in the `_buildRichText` function body)

The relevant line is [this](https://github.com/flutter/packages/blob/bf2570a33ee882b200047d5fea81a04c6005e614/packages/flutter_markdown/lib/src/builder.dart#L966) (this is the current `main` I assume, sorry I am not aware of the versioning of such packages)

### Expected results

Missing value should be handled gracefully.

### Actual results

`Null check operator used on a null value` is thrown

### Code sample

_No response_
I apologise for not supplying explicit reproduction steps or code sample. I do not have any, and since the issue seems pretty clear from inspecting the code, I hope it does not require any further clarification

### Screenshots or Videos

_No response_

### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.2 23C64 darwin-arm64, locale en-HU)
    • Flutter version 3.19.3 on channel stable at /Users/harkairt/fvm/versions/3.19.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (3 months ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/harkairt/Library/Android/sdk
    • Platform android-34, build-tools 31.0.0
    • ANDROID_SDK_ROOT = /Users/harkairt/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • 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 17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.88.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.2 23C64 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 124.0.6367.208

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>