kaboc/flutter_custom_text

Text change is not reflected to onTap/onLongPress callbacks right away

kaboc opened this issue · 0 comments

kaboc commented

The following example app shows text containing an email address, which is tappable, and a button.

import 'package:flutter/material.dart';
import 'package:custom_text/custom_text.dart';

void main() => runApp(const App());

class App extends StatefulWidget {
  const App();

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  var _upperCase = false;

  @override
  Widget build(BuildContext context) {
    const text = 'Email: foo@example.com';

    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CustomText(
                _upperCase ? text.toUpperCase() : text,
                definitions: [
                  TextDefinition(
                    matcher: const EmailMatcher(),
                    matchStyle: const TextStyle(color: Colors.blue),
                    tapStyle: const TextStyle(),
                    onTap: (email) => print(email),
                  ),
                ],
              ),
              const SizedBox(height: 16.0),
              ElevatedButton(
                child: Text('To ${_upperCase ? 'lower' : 'upper'} case'),
                onPressed: () {
                  setState(() => _upperCase = !_upperCase);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Every time the button is pressed, the text is toggled between upper and lower cases , and the widget is rebuilt by setState().
Tapping on the email address prints the tapped string in the console.

Expected behaviour:

The latest string is given to the onTap callback and printed.

Actual behaviour:

The callback receives the one right before the latest (lowercase when the latest is uppercase, and vice versa) and prints it.

It appears this bug was not caused by the refactor done recently but already existed at the point of v0.5.0. Maybe even earlier.