add copy to selected texts

merge-requests/795/head
mosazaid 5 years ago
parent fa9942ac24
commit 0fb4b4a890

@ -708,5 +708,6 @@ const Map<String, Map<String, String>> localizedValues = {
"inProgress": {"en": "inProgress", "ar": "تحت المعالجه"}, "inProgress": {"en": "inProgress", "ar": "تحت المعالجه"},
"Completed": {"en": "Completed", "ar": "مكتمل"}, "Completed": {"en": "Completed", "ar": "مكتمل"},
"Locked": {"en": "Locked", "ar": "مقفل"}, "Locked": {"en": "Locked", "ar": "مقفل"},
"textCopiedSuccessfully": {"en": "Text copied successfully", "ar": "تم نسخ النص بنجاح"},
}; };

@ -1370,6 +1370,7 @@ class TranslationBase {
String get edit => localizedValues['edit'][locale.languageCode]; String get edit => localizedValues['edit'][locale.languageCode];
String get summeryReply => localizedValues['summeryReply'][locale.languageCode]; String get summeryReply => localizedValues['summeryReply'][locale.languageCode];
String get severityValidationError => localizedValues['severityValidationError'][locale.languageCode]; String get severityValidationError => localizedValues['severityValidationError'][locale.languageCode];
String get textCopiedSuccessfully => localizedValues['textCopiedSuccessfully'][locale.languageCode];
} }
class TranslationBaseDelegate extends LocalizationsDelegate<TranslationBase> { class TranslationBaseDelegate extends LocalizationsDelegate<TranslationBase> {

@ -191,32 +191,25 @@ class PatientProfileAppBar extends StatelessWidget
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
RichText( Row(
text: TextSpan( children: [
style: TextStyle( AppText(
fontSize: 1.6 * SizeConfig.textMultiplier, TranslationBase
color: Colors.black),
children: <TextSpan>[
new TextSpan(
text: TranslationBase
.of(context) .of(context)
.fileNumber, .fileNumber,
style: TextStyle(
fontSize: SizeConfig.getTextMultiplierBasedOnWidth() *3, fontSize: SizeConfig.getTextMultiplierBasedOnWidth() *3,
fontFamily: 'Poppins',
color: Color(0xFF575757), color: Color(0xFF575757),
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
),
),), SizedBox(width: 1,),
new TextSpan( AppText(
text: patient.patientId.toString(), patient.patientId.toString(),
style: TextStyle( fontSize: SizeConfig.getTextMultiplierBasedOnWidth() *3.5,
color: Color(0xFF2E303A),
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
fontFamily: 'Poppins', isCopyable: true,
fontSize: SizeConfig.getTextMultiplierBasedOnWidth() *3.5, color: Color(0xFF2E303A),)),
],
), ),
],
), ),
Row( Row(
children: [ children: [

@ -1,6 +1,9 @@
import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
class AppText extends StatefulWidget { class AppText extends StatefulWidget {
@ -30,6 +33,7 @@ class AppText extends StatefulWidget {
final bool visibility; final bool visibility;
final TextOverflow textOverflow; final TextOverflow textOverflow;
final TextDecoration textDecoration; final TextDecoration textDecoration;
final bool isCopyable;
AppText( AppText(
this.text, { this.text, {
@ -56,7 +60,9 @@ class AppText extends StatefulWidget {
this.allowExpand = true, this.allowExpand = true,
this.visibility = true, this.visibility = true,
this.textOverflow, this.textOverflow,
this.textDecoration, this.letterSpacing, this.textDecoration,
this.letterSpacing,
this.isCopyable = true,
}); });
@override @override
@ -92,7 +98,8 @@ class _AppTextState extends State<AppText> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return GestureDetector(
child: Container(
margin: widget.margin != null margin: widget.margin != null
? EdgeInsets.all(widget.margin) ? EdgeInsets.all(widget.margin)
: EdgeInsets.only( : EdgeInsets.only(
@ -106,39 +113,7 @@ class _AppTextState extends State<AppText> {
children: [ children: [
Stack( Stack(
children: [ children: [
Text( _textWidget(),
!hidden
? text
: (text.substring(
0,
text.length > widget.maxLength
? widget.maxLength
: text.length)),
textAlign: widget.textAlign,
overflow: widget.maxLines != null
? ((widget.maxLines > 1)
? TextOverflow.fade
: TextOverflow.ellipsis)
: null,
maxLines: widget.maxLines ?? null,
style: widget.style != null
? _getFontStyle().copyWith(
fontStyle: widget.italic ? FontStyle.italic : null,
color: widget.color,
fontWeight: widget.fontWeight ?? _getFontWeight(),
height: widget.fontHeight)
: TextStyle(
fontStyle: widget.italic ? FontStyle.italic : null,
color:
widget.color != null ? widget.color : Colors.black,
fontSize: widget.fontSize ?? _getFontSize(),
letterSpacing:
widget.letterSpacing??(widget.variant == "overline" ? 1.5 : null),
fontWeight: widget.fontWeight ?? _getFontWeight(),
fontFamily: widget.fontFamily ?? 'Poppins',
decoration: widget.textDecoration,
height: widget.fontHeight),
),
if (widget.readMore && text.length > widget.maxLength && hidden) if (widget.readMore && text.length > widget.maxLength && hidden)
Positioned( Positioned(
bottom: 0, bottom: 0,
@ -179,9 +154,93 @@ class _AppTextState extends State<AppText> {
), ),
], ],
), ),
),
// onLongPress: (){
// if(widget.isCopyable){
// DrAppToastMsg.showShortToast(TranslationBase.of(context).textCopiedSuccessfully);
// Clipboard.setData(new ClipboardData(text: widget.text));
// }
// },
); );
} }
Widget _textWidget() {
if (widget.isCopyable) {
return Theme(
data: ThemeData(
textSelectionColor: Colors.lightBlueAccent,
),
child: Container(
child: SelectableText(
!hidden
? text
: (text.substring(
0,
text.length > widget.maxLength
? widget.maxLength
: text.length)),
textAlign: widget.textAlign,
// overflow: widget.maxLines != null
// ? ((widget.maxLines > 1)
// ? TextOverflow.fade
// : TextOverflow.ellipsis)
// : null,
maxLines: widget.maxLines ?? null,
style: widget.style != null
? _getFontStyle().copyWith(
fontStyle: widget.italic ? FontStyle.italic : null,
color: widget.color,
fontWeight: widget.fontWeight ?? _getFontWeight(),
height: widget.fontHeight)
: TextStyle(
fontStyle: widget.italic ? FontStyle.italic : null,
color: widget.color != null ? widget.color : Colors.black,
fontSize: widget.fontSize ?? _getFontSize(),
letterSpacing: widget.letterSpacing ??
(widget.variant == "overline" ? 1.5 : null),
fontWeight: widget.fontWeight ?? _getFontWeight(),
fontFamily: widget.fontFamily ?? 'Poppins',
decoration: widget.textDecoration,
height: widget.fontHeight),
),
),
);
} else {
return Text(
!hidden
? text
: (text.substring(
0,
text.length > widget.maxLength
? widget.maxLength
: text.length)),
textAlign: widget.textAlign,
overflow: widget.maxLines != null
? ((widget.maxLines > 1)
? TextOverflow.fade
: TextOverflow.ellipsis)
: null,
maxLines: widget.maxLines ?? null,
style: widget.style != null
? _getFontStyle().copyWith(
fontStyle: widget.italic ? FontStyle.italic : null,
color: widget.color,
fontWeight: widget.fontWeight ?? _getFontWeight(),
height: widget.fontHeight)
: TextStyle(
fontStyle: widget.italic ? FontStyle.italic : null,
color: widget.color != null ? widget.color : Colors.black,
fontSize: widget.fontSize ?? _getFontSize(),
letterSpacing: widget.letterSpacing ??
(widget.variant == "overline" ? 1.5 : null),
fontWeight: widget.fontWeight ?? _getFontWeight(),
fontFamily: widget.fontFamily ?? 'Poppins',
decoration: widget.textDecoration,
height: widget.fontHeight),
);
}
}
TextStyle _getFontStyle() { TextStyle _getFontStyle() {
switch (widget.style) { switch (widget.style) {
case "headline2": case "headline2":

Loading…
Cancel
Save