Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/auto_size_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ library auto_size_text;
import 'dart:async';

import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart' show SelectableText;

part 'src/auto_size_text.dart';
part 'src/auto_size_group.dart';
94 changes: 65 additions & 29 deletions lib/src/auto_size_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class AutoSizeText extends StatefulWidget {
this.textScaleFactor,
this.maxLines,
this.semanticsLabel,
this.selectable,
}) : textSpan = null,
super(key: key);

Expand All @@ -57,6 +58,7 @@ class AutoSizeText extends StatefulWidget {
this.textScaleFactor,
this.maxLines,
this.semanticsLabel,
this.selectable,
}) : data = null,
super(key: key);

Expand Down Expand Up @@ -215,6 +217,14 @@ class AutoSizeText extends StatefulWidget {
/// ```
final String? semanticsLabel;

/// Whether the text should be selectable
///
/// If present, this widget is generating text using SelectableText or SelectableText.rich instead of the default Text or Text.rich.
///
/// If present, locale, softWrap, overflow and semanticsLabel are ignored as the are not supported by SelectableText.

final bool? selectable;

@override
_AutoSizeTextState createState() => _AutoSizeTextState();
}
Expand Down Expand Up @@ -411,36 +421,62 @@ class _AutoSizeTextState extends State<AutoSizeText> {
}

Widget _buildText(double fontSize, TextStyle style, int? maxLines) {
if (widget.data != null) {
return Text(
widget.data!,
key: widget.textKey,
style: style.copyWith(fontSize: fontSize),
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
locale: widget.locale,
softWrap: widget.softWrap,
overflow: widget.overflow,
textScaleFactor: 1,
maxLines: maxLines,
semanticsLabel: widget.semanticsLabel,
);
if (widget.selectable == true) {
if (widget.data != null) {
return SelectableText(
widget.data!,
key: widget.textKey,
style: style.copyWith(fontSize: fontSize),
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
textScaleFactor: 1,
maxLines: maxLines,
);
} else {
return SelectableText.rich(
widget.textSpan!,
key: widget.textKey,
style: style,
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
textScaleFactor: fontSize / style.fontSize!,
maxLines: maxLines,
);
}
} else {
return Text.rich(
widget.textSpan!,
key: widget.textKey,
style: style,
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
locale: widget.locale,
softWrap: widget.softWrap,
overflow: widget.overflow,
textScaleFactor: fontSize / style.fontSize!,
maxLines: maxLines,
semanticsLabel: widget.semanticsLabel,
);
if (widget.data != null) {
return Text(
widget.data!,
key: widget.textKey,
style: style.copyWith(fontSize: fontSize),
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
locale: widget.locale,
softWrap: widget.softWrap,
overflow: widget.overflow,
textScaleFactor: 1,
maxLines: maxLines,
semanticsLabel: widget.semanticsLabel,
);
} else {
return Text.rich(
widget.textSpan!,
key: widget.textKey,
style: style,
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textDirection: widget.textDirection,
locale: widget.locale,
softWrap: widget.softWrap,
overflow: widget.overflow,
textScaleFactor: fontSize / style.fontSize!,
maxLines: maxLines,
semanticsLabel: widget.semanticsLabel,
);
}
}
}

Expand Down