Repository: flutter
Issue: SelectableText has negative constraints when textWidthBasis: TextWidthBasis.longestLine specified
Labels: framework,a: typography,has reproducible steps,P2,found in release: 2.2,found in release: 2.6,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
-->

## Steps to Reproduce

<!-- You must include full steps to reproduce so that we can reproduce the problem. -->

1. Run `flutter create bug`.
2. Update the files as follows: ... <!-- include every file that is different from the template app! -->
3. ... <!-- describe how to reproduce the problem -->
```
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Material App Bar'),
        ),
        body: Card(
            color: Colors.red,
            child: ConstrainedBox(
              constraints: BoxConstraints(minWidth: 100),
              child: SelectableText('',
                textWidthBasis: TextWidthBasis.longestLine,
              ),
            ),
        ),
      ),
    );
  }
}
```
**Expected results:** <!-- what did you want to see? -->
Has BoxConstraints.zero (Does not error)
**Actual results:** <!-- what did you see? -->
```
======== Exception caught by rendering library ==========================================
The following assertion was thrown during performLayout():
BoxConstraints has a negative minimum width.

These invalid constraints were provided to _RenderEditableCustomPaint's layout() function by the following function, which probably computed the invalid constraints in question:
  RenderEditable.performLayout (package:flutter/src/rendering/editable.dart:3223:30)
The offending constraints were: BoxConstraints(w=-Infinity, h=16.0; NOT NORMALIZED)
The relevant error-causing widget was: 
  SelectableText file:///Users/loganwarner/StudioProjects/playground/lib/selected_text_bug.dart:20:22
When the exception was thrown, this was the stack: 
#0      BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError (package:flutter/src/rendering/box.dart:517:9)
#1      BoxConstraints.debugAssertIsValid.<anonymous closure> (package:flutter/src/rendering/box.dart:546:19)
#2      BoxConstraints.debugAssertIsValid (package:flutter/src/rendering/box.dart:565:6)
#3      RenderObject.layout (package:flutter/src/rendering/object.dart:1679:24)
#4      RenderEditable.performLayout (package:flutter/src/rendering/editable.dart:3223:30)
...
The following RenderObject was being processed when the exception was fired: RenderEditable#118fa relayoutBoundary=up18 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(100.0<=w<=382.0, 0.0<=h<=733.0)
...  size: Size(100.0, 16.0)
...  cursorColor: Color(0x002196f3)
...  showCursor: ValueNotifier<bool>#18c3c(false)
...  maxLines: null
...  minLines: null
...  selectionColor: Color(0x662196f3)
...  textScaleFactor: 0.9
...  locale: en_US
...  selection: TextSelection(baseOffset: -1, extentOffset: -1, affinity: TextAffinity.downstream, isDirectional: false)
...  offset: ScrollPositionWithSingleContext#00586(offset: 0.0, range: null..null, viewport: null, ScrollableState, BouncingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#aefd5, ScrollDirection.idle)
RenderObject: RenderEditable#118fa relayoutBoundary=up18 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  parentData: <none> (can use size)
  constraints: BoxConstraints(100.0<=w<=382.0, 0.0<=h<=733.0)
  size: Size(100.0, 16.0)
  cursorColor: Color(0x002196f3)
  showCursor: ValueNotifier<bool>#18c3c(false)
  maxLines: null
  minLines: null
  selectionColor: Color(0x662196f3)
  textScaleFactor: 0.9
  locale: en_US
  selection: TextSelection(baseOffset: -1, extentOffset: -1, affinity: TextAffinity.downstream, isDirectional: false)
  offset: ScrollPositionWithSingleContext#00586(offset: 0.0, range: null..null, viewport: null, ScrollableState, BouncingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#aefd5, ScrollDirection.idle)
...  text: TextSpan
...    debugLabel: (englishLike body1 2014).merge(blackCupertino bodyText2)
...    inherit: false
...    color: Color(0xdd000000)
...    family: .SF UI Text
...    size: 14.0
...    weight: 400
...    baseline: alphabetic
...    decoration: TextDecoration.none
...    : TextSpan
...      ""
================================================================================
```
<details>
  <summary>Logs</summary>

```
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.4 20F71 darwin-arm, locale en-NZ)
    • Flutter version 2.2.3 at /Users/user/Development/flutter
    • Framework revision f4abaa0735 (8 weeks ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/loganwarner/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.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 11.0.10+0-b96-7281165)

[✓] Connected device (3 available)
    • iPhone 12 (mobile)     • 7B1A7104-0351-4C50-A238-F295B0992501 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • iPhone 12 Pro (mobile) • B8616F65-1E40-4E02-A098-96B0E85F04AC • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 92.0.4515.159

• No issues found!
```

</details>