From ffecdcbef2bc17300188019d57c905e2f9a88112 Mon Sep 17 00:00:00 2001 From: Vikas Kumar Date: Wed, 13 Apr 2022 00:36:57 +0530 Subject: [PATCH] added selectable text property for web --- lib/auto_size_text.dart | 3 +- lib/src/auto_size_text.dart | 84 ++++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 29 deletions(-) diff --git a/lib/auto_size_text.dart b/lib/auto_size_text.dart index 0ff37b6..7532704 100644 --- a/lib/auto_size_text.dart +++ b/lib/auto_size_text.dart @@ -4,7 +4,8 @@ library auto_size_text; import 'dart:async'; -import 'package:flutter/widgets.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; part 'src/auto_size_text.dart'; part 'src/auto_size_group.dart'; diff --git a/lib/src/auto_size_text.dart b/lib/src/auto_size_text.dart index ec43838..6cb52c4 100644 --- a/lib/src/auto_size_text.dart +++ b/lib/src/auto_size_text.dart @@ -412,35 +412,63 @@ class _AutoSizeTextState extends State { 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 (kIsWeb) { + 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, + semanticsLabel: widget.semanticsLabel, + ); + } else { + 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, - ); + if (kIsWeb) { + 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, + 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, + ); + } } }