Repository navigation
update the GestureRecognizer in RichText fails. #110342
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: gesturesflutter/packages/flutter/gestures repository.flutter/packages/flutter/gestures repository.found in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
Description
Steps to Reproduce
- Execute
flutter runon the code sample - Tap on the
Hello Worldrich-text widget, and the console will show Hello World - Tap on the floating action button. It will update the value of the
gestureRecognizerin existedHello Worldrich-text widget.
Expected results:
- Before changing the value of the
gestureRecognizerin existedHello Worldrich-text widget, the console will show Hello World. - After changing the value, the console will show Hello Flutter.
Actual results:
- The console always shows Hello World whether or not the value of the
gestureRecognizeris changed.
Code sample:
class _MyHomePageState extends State<MyHomePage> {
late TapGestureRecognizer _tapGestureRecognizer;
@override
void initState() {
super.initState();
_tapGestureRecognizer = TapGestureRecognizer()
..onTap = () {
print('Hello World');
};
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: RichText(
text: TextSpan(
text: 'Hello World',
style: const TextStyle(color: Colors.black),
recognizer: _tapGestureRecognizer,
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_updateRichText();
},
),
);
}
void _updateRichText() {
setState(() {
print('set state');
_tapGestureRecognizer.dispose();
_tapGestureRecognizer = TapGestureRecognizer()
..onTap = () {
print('Hello Flutter');
};
});
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: gesturesflutter/packages/flutter/gestures repository.flutter/packages/flutter/gestures repository.found in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
Activity
LucasXu0 commentedon Aug 26, 2022
After reading the flutter source code, I found a little clue.
text_span.dart
paragraph.dart
In my personal opinion, I think it is necessary to refresh the value of the
textof this_textPaintereven in the case of metadata.I can make a PR to modify if needed.
huycozy commentedon Aug 29, 2022
Hi @LucasXu0, thanks for filing the issue. This issue is reproducible on the latest
stableandmasterchannels.Logs
Sample code
flutter doctor -v
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.2.1 21D62 darwin-x64, locale en-VN) • Flutter version 3.0.5 at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f1875d570e (9 hours ago), 2022-07-13 11:24:16 -0700 • Engine revision e85ea0e79c • Dart version 2.17.6 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.3) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.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.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2020.3.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • 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 [✓] IntelliJ IDEA Community Edition (version 2022.1.1) • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app • 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 [✓] VS Code (version 1.69.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.44.0 [✓] Connected device (3 available) • SM T225 (mobile) • R9JT3004VRJ • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found![✓] Flutter (Channel master, 3.1.0-0.0.pre.2552, on macOS 12.5 21G72 darwin-x64, locale en-EE) • Flutter version 3.1.0-0.0.pre.2552 on channel master at /Users/huynq/Documents/GitHub/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision f66a097919 (2 hours ago), 2022-08-28 20:20:36 -0400 • Engine revision 4e36ebc1f3 • Dart version 2.19.0 (build 2.19.0-146.0.dev) • DevTools version 2.16.0 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13E113 • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.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.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2020.3.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • 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 [✓] IntelliJ IDEA Community Edition (version 2022.1.1) • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app • 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 [✓] VS Code (version 1.70.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.46.0 [✓] Connected device (3 available) • iPhone 13 (mobile) • 2526BC1A-435D-4B08-B99C-44B928F2517B • ios • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator) • macOS (desktop) • macos • darwin-x64 • macOS 12.5 21G72 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.101 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found!When try changing the TextSpan's properties, such as
textvalue as below example, theGestureRecognizerworks as expected.Sample code (update TextSpan's properties)
Logs (update TextSpan's properties)
Hello World set state Hello Flutter Hello FlutterCould you try and notice the same thing?
LucasXu0 commentedon Aug 30, 2022
Hi, @huycozy. Thanks for the reply.
I know that modifying the text or style will trigger the gesture recognizer update. But in my case, only the gesture recognizer is modified, and no other properties are changed.
As mentioned above, If we modify the text or text style. The
compare tofunction will returnRenderComparison.layoutas result.text_span.dart
So I suggest that for the case where only the gesture recognizer is modified, there is no need to re-layout, but to modify
_textPainter.valuehuycozy commentedon Aug 30, 2022
@LucasXu0: I see. Keep this open for further insights from the team. Thank you!
The completed sample code can be found at #110342 (comment).
fix: flutter#110342 unable to update rich text widget gesture recognizer
1 remaining item
LucasXu0 commentedon Dec 13, 2022
Hi, @huycozy. Since this question has been unresponsive for a time, I created a PR and tried to fix it. Do you know of anyone who can help to review?
huycozy commentedon Dec 14, 2022
@LucasXu0 Thanks for submitting the PR. I saw the PR being reviewed and waiting to be merged.
fix: #110342 unable to update rich text widget gesture recognizer (#1…
fix: flutter#110342 unable to update rich text widget gesture recogni…
github-actions commentedon Mar 4, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.