Repository: flutter
Issue: Preserve `SelectableText`'s selection on setState
Labels: framework,f: material design,c: proposal,P3,workaround available,team-text-input,triaged-text-input

![selectabletext](https://user-images.githubusercontent.com/20254485/120792105-fd800780-c56f-11eb-8ad4-24cde0dedc9b.gif)

`setState()` is called for changing the text style in this example when the mouse pointer enters the region of the decorated `TextSpan` and when it exits there.  If it occurs while part of `SelectableText` is already selected, the selection is cancelled unexpectedly.

The yellow circle in the GIF animation means the mouse is being left-clicked.

## Steps to Reproduce

1. Copy and paste the code below to an editor.
2. Run the app.
3. Select part of the text and then hover the mouse pointer over the blue text.

```dart
import 'package:flutter/material.dart';

void main() => runApp(const App());

class App extends StatelessWidget {
  const App();

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Padding(
          padding: EdgeInsets.all(16.0),
          child: _Text(),
        ),
      ),
    );
  }
}

class _Text extends StatefulWidget {
  const _Text();

  @override
  _TextState createState() => _TextState();
}

class _TextState extends State<_Text> {
  var _isHovered = false;

  @override
  Widget build(BuildContext context) {
    return SelectableText.rich(
      TextSpan(
        children: [
          TextSpan(
            text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ',
          ),
          TextSpan(
            text: 'sed do eiusmod tempor incididunt',
            onEnter: (_) => setState(() => _isHovered = true),
            onExit: (_) => setState(() => _isHovered = false),
            style: TextStyle(
              color: Colors.blue,
              decoration: _isHovered ? TextDecoration.underline : null,
            ),
          ),
          TextSpan(
            text: ' ut labore et dolore magna aliqua.',
          ),
        ],
      ),
    );
  }
}
```

**Expected results:**

Text selection is kept unchanged even if `setState()` is called.

**Actual results:**

Text selection is lost every time `SelectableText` is rebuilt (or redrawn?).

<details>
  <summary>flutter doctor -v</summary>

```
[✓] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19042.1023], locale ja-JP)
    • Flutter version 2.2.1 at D:\tool\dev\flutter
    • Framework revision 02c026b03c (8 days ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at D:\tool\dev\Android\sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_SDK_ROOT = D:\tool\dev\Android\sdk
    • Java binary at: D:\tool\dev\java\jdk8u292-b10\bin\java
    • Java version OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.4)
    • Visual Studio at D:\tool\dev\Microsoft\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.7.30517.126
    • Windows 10 SDK version 10.0.18362.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2021.1)
    • IntelliJ at D:\tool\dev\JetBrains\apps\IDEA-U\ch-0\211.6693.111
    • Flutter plugin version 57.0.5
    • Dart plugin version 211.7233

[✓] VS Code, 64-bit edition (version 1.56.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.22.0

[✓] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19042.1023]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 91.0.4472.77
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 91.0.864.37

! Doctor found issues in 1 category.
```
</details>