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), .of(context)
children: <TextSpan>[ .fileNumber,
new TextSpan( fontSize: SizeConfig.getTextMultiplierBasedOnWidth() *3,
text: TranslationBase color: Color(0xFF575757),
.of(context) fontWeight: FontWeight.w600,
.fileNumber, ),
SizedBox(width: 1,),
style: TextStyle( AppText(
fontSize: SizeConfig.getTextMultiplierBasedOnWidth() *3, patient.patientId.toString(),
fontFamily: 'Poppins', fontSize: SizeConfig.getTextMultiplierBasedOnWidth() *3.5,
color: Color(0xFF575757), color: Color(0xFF2E303A),
fontWeight: FontWeight.w600, fontWeight: FontWeight.w700,
isCopyable: true,
),), ),
new TextSpan( ],
text: patient.patientId.toString(),
style: TextStyle(
fontWeight: FontWeight.w700,
fontFamily: 'Poppins',
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,96 +98,149 @@ class _AppTextState extends State<AppText> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return GestureDetector(
margin: widget.margin != null child: Container(
? EdgeInsets.all(widget.margin) margin: widget.margin != null
: EdgeInsets.only( ? EdgeInsets.all(widget.margin)
top: widget.marginTop, : EdgeInsets.only(
right: widget.marginRight, top: widget.marginTop,
bottom: widget.marginBottom, right: widget.marginRight,
left: widget.marginLeft), bottom: widget.marginBottom,
child: Column( left: widget.marginLeft),
mainAxisAlignment: MainAxisAlignment.center, child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center,
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Stack( children: [
children: [ Stack(
Text( children: [
!hidden _textWidget(),
? text if (widget.readMore && text.length > widget.maxLength && hidden)
: (text.substring( Positioned(
0, bottom: 0,
text.length > widget.maxLength left: 0,
? widget.maxLength right: 0,
: text.length)), child: Container(
textAlign: widget.textAlign, decoration: BoxDecoration(
overflow: widget.maxLines != null gradient: LinearGradient(
? ((widget.maxLines > 1) colors: [
? TextOverflow.fade Theme.of(context).backgroundColor,
: TextOverflow.ellipsis) Theme.of(context).backgroundColor.withOpacity(0),
: null, ],
maxLines: widget.maxLines ?? null, begin: Alignment.bottomCenter,
style: widget.style != null end: Alignment.topCenter)),
? _getFontStyle().copyWith( height: 30,
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)
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).backgroundColor,
Theme.of(context).backgroundColor.withOpacity(0),
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter)),
height: 30,
),
)
],
),
if (widget.allowExpand &&
widget.readMore &&
text.length > widget.maxLength)
Padding(
padding: EdgeInsets.only(top: 8.0, right: 8.0, bottom: 8.0),
child: InkWell(
onTap: () {
setState(() {
hidden = !hidden;
});
},
child: Text(hidden ? "Read More" : "Read less",
style: _getFontStyle().copyWith(
color: HexColor('#FF0000'),
fontWeight: FontWeight.w800,
fontFamily: "Poppins",
)),
),
), ),
], if (widget.allowExpand &&
widget.readMore &&
text.length > widget.maxLength)
Padding(
padding: EdgeInsets.only(top: 8.0, right: 8.0, bottom: 8.0),
child: InkWell(
onTap: () {
setState(() {
hidden = !hidden;
});
},
child: Text(hidden ? "Read More" : "Read less",
style: _getFontStyle().copyWith(
color: HexColor('#FF0000'),
fontWeight: FontWeight.w800,
fontFamily: "Poppins",
)),
),
),
],
),
), ),
// 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