Skip to content

update the GestureRecognizer in RichText fails. #110342

@LucasXu0

Description

@LucasXu0

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Tap on the Hello World rich-text widget, and the console will show Hello World
  3. Tap on the floating action button. It will update the value of thegestureRecognizer in existed Hello World rich-text widget.

Expected results:

  1. Before changing the value of thegestureRecognizer in existed Hello World rich-text widget, the console will show Hello World.
  2. After changing the value, the console will show Hello Flutter.

Actual results:

  1. The console always shows Hello World whether or not the value of thegestureRecognizer is 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');
        };
    });
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: gesturesflutter/packages/flutter/gestures repository.found in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions