Open karabanovbs opened 7 months ago
Reproducible using the code sample provided above.
This seems to be a problem that occurs because when a new line occurs, the height of the new line is set to the height of the previous text (object?).
ColoredBox(
color: Colors.red,
child: SizedBox(
width: 300,
child: Text.rich(
TextSpan(
children: [
WidgetSpan(
child: Container(
color: Colors.blue,
height: 100.0,
),
),
TextSpan(text: '\n'),
],
),
),
),
),
When the height of the new line is unknown, it seems that the height of the new line is determined based on the height of the previous text(?)
In fact, if the text is inserted after a newline (so they know the new line height), it displays well.
ColoredBox(
color: Colors.red,
child: SizedBox(
width: 300,
child: Text.rich(
TextSpan(
children: [
WidgetSpan(
child: Container(
color: Colors.blue,
height: 100.0,
),
),
TextSpan(text: '\n '),
],
),
),
),
),
I'm not sure because I haven't seen the implementation part in detail, but it seems to be managed by text_painter. At first glance, it seems like a pretty natural movement..
At first glance, it seems like a pretty natural movement..
I disagree that the current behavior is natural. If you place a \n
after the WidgetSpan the second line will be extremely tall. If you place a \n\u200c
(U+200C ZERO WIDTH NON-JOINER—a non-printing character) it will be normal. Why would a non-printing character affect the height of the line?
Steps to reproduce
1) Create Rich text widget; 2) Put WidgetSpan inside rich text; 3) Put Text (text should wrap the line) widget inside Widget span 4) Put TextSpan with line break after WidgetSpan
May be it is important: Without step No. 4 or without line wrapping inside Text it works good.
Expected results
Expected result
Actual results
Unexpected space
Code sample
Code sample
```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Center( child: ColoredBox( color: Colors.red, child: SizedBox( width: 300, child: Text.rich( TextSpan( children: [ WidgetSpan( child: Text( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', ), ), TextSpan(text: '\n'), ], ), ), ), ), ), ), ); } } ```Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
```console [✓] Flutter (Channel stable, 3.19.4, on macOS 14.1.1 23B81 darwin-arm64 (Rosetta), locale en-AE) • Flutter version 3.19.4 on channel stable at /Users/boriskarabanov/fvm/versions/3.19.4 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 68bfaea224 (3 weeks ago), 2024-03-20 15:36:31 -0700 • Engine revision a5c24f538d • Dart version 3.3.2 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/boriskarabanov/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/boriskarabanov/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314) • 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.14.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.1) • Android Studio at /Users/boriskarabanov/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.7+0-17.0.7b1000.6-10550314) [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5) • IntelliJ at /Users/boriskarabanov/Applications/IntelliJ IDEA Ultimate.app • Flutter plugin version 76.3.4 • Dart plugin version 232.10248 [✓] VS Code (version 1.88.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (3 available) • SM S9010 (mobile) • R5CT444XHFN • android-arm64 • Android 14 (API 34) • macOS (desktop) • macos • darwin-arm64 • macOS 14.1.1 23B81 darwin-arm64 (Rosetta) • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.107 ! Error: Browsing on the local area network for Boris Karabanov’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources • All expected network resources are available. • No issues found! ```