Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for 'SelectableText' #94

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

definitelyme
Copy link

Tested on Android, iOS & Web platforms.

@definitelyme definitelyme changed the title Add support for 'SelectableText' Adds support for 'SelectableText' Jul 15, 2021
@definitelyme definitelyme marked this pull request as ready for review July 15, 2021 18:08
@TjarcoKerssens
Copy link

@leisim Is it possible to merge this and publish this feature?

@definitelyme
Copy link
Author

definitelyme commented Oct 16, 2021

Hi @TjarcoKerssens,
Here's a temporary workaround till it's resolved; add this to pubspec.yaml

auto_size_text:
    git:
      url: https://github.com/definitelyme/auto_size_text.git
      ref: ft/selectable-text

@esDotDev
Copy link

esDotDev commented Nov 4, 2021

Can't you just use textBuilder for this?

@definitelyme
Copy link
Author

What widget is that? There isn't a TextBuilder widget in Flutter

@schultek
Copy link

@definitelyme Thanks for this feature, I needed it in a project of mine.
However I'm experiencing some weird behavior in the text wrapping.

See this example:
Bildschirmfoto 2022-02-21 um 14 10 23

These are two AutoSizeText widgets in a Row, with exactly the same properties and width. The left one is the selectable version, the right side the normal version.
As you see the selectable version is overflowing with the same calculated font size.

I found this issue that explains that there is a tiny extra margin with the EditableText which is used by SelectableText.

In order to fix this and correctly calculate a fitting font size, we need to account for this margin in the _checkTextFits method of _AutoSizeTextState. We need to change the textPainter.layout() call to:

if (widget._isSelectableText) {
  textPainter.layout(maxWidth: constraints.maxWidth - widget.cursorWidth - 1.0);
} else {
   textPainter.layout(maxWidth: constraints.maxWidth);
}

I tested this and it seems to work.

@definitelyme
Copy link
Author

Nice! I didn't notice this, I'll update my PR.

@schultek
Copy link

schultek commented Mar 3, 2022

@definitelyme Any update on this?

@PcolBP
Copy link

PcolBP commented Mar 4, 2022

For me isnt working well enought. Before text will shrink SelectableText appears with Scrollbar example below:
image
and after shrinking web container a little bit more, scroll dissapear and text is shrinked
image
That behavior doesnt exist in just AutoSizeText. Tried with NeverScrollablePhysics and ScrollConfiguration with scrollbars: false still same effect.

Any ideas?

@schultek
Copy link

schultek commented Mar 4, 2022

@PcolBP Is this after using the change I proposed in my comment before? If not its the same issue.

@PcolBP
Copy link

PcolBP commented Mar 7, 2022

@schultek Yeah, thats it. For me was enought to set just:

maxWidth - 2;

But, I've noticed some weird behavior. A text is blurry after shrinking.

Upper text is Selectable, bottom is Text.
Before:

image

After:
image

I've created own fork with customBuilders:

painterBuilder: (maxWidth) {
          return maxWidth - 2;
        },
widgetBuilder: (calculatedStyle, scaleFactor) {
          return SelectableText(
            text,
            style: calculatedStyle.copyWith(
              fontFeatures: const [FontFeature.proportionalFigures()], // Added to fix blurry text
            ),
            textAlign: TextAlign.justify,
            textScaleFactor: scaleFactor,
          );
        },

EDIT:

Issue with blurry text related to #81215

@definitelyme
Copy link
Author

@definitelyme Any update on this?

I have updated my PR to include the fix you suggested.

@amejiarosario amejiarosario mentioned this pull request Jul 5, 2022
@amejiarosario
Copy link

Thanks for this branch!
I was going to use it, but then unfortunately overflowReplacement is not defined in AutoSizeText.selectable. Any reason for leaving it out?

@definitelyme
Copy link
Author

@amejiarosario SelectableText does not define any overflowReplacement property.

@nilsreichardt
Copy link

Since Flutter 3.3 you can use the SelectionArea widget. See #49 (comment) for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants