|
|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
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/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:hexcolor/hexcolor.dart';
|
|
|
|
|
|
|
|
|
|
class AppText extends StatefulWidget {
|
|
|
|
|
@ -30,6 +33,7 @@ class AppText extends StatefulWidget {
|
|
|
|
|
final bool visibility;
|
|
|
|
|
final TextOverflow textOverflow;
|
|
|
|
|
final TextDecoration textDecoration;
|
|
|
|
|
final bool isCopyable;
|
|
|
|
|
|
|
|
|
|
AppText(
|
|
|
|
|
this.text, {
|
|
|
|
|
@ -56,7 +60,9 @@ class AppText extends StatefulWidget {
|
|
|
|
|
this.allowExpand = true,
|
|
|
|
|
this.visibility = true,
|
|
|
|
|
this.textOverflow,
|
|
|
|
|
this.textDecoration, this.letterSpacing,
|
|
|
|
|
this.textDecoration,
|
|
|
|
|
this.letterSpacing,
|
|
|
|
|
this.isCopyable = true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -92,96 +98,149 @@ class _AppTextState extends State<AppText> {
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
margin: widget.margin != null
|
|
|
|
|
? EdgeInsets.all(widget.margin)
|
|
|
|
|
: EdgeInsets.only(
|
|
|
|
|
top: widget.marginTop,
|
|
|
|
|
right: widget.marginRight,
|
|
|
|
|
bottom: widget.marginBottom,
|
|
|
|
|
left: widget.marginLeft),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Stack(
|
|
|
|
|
children: [
|
|
|
|
|
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),
|
|
|
|
|
),
|
|
|
|
|
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",
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
child: Container(
|
|
|
|
|
margin: widget.margin != null
|
|
|
|
|
? EdgeInsets.all(widget.margin)
|
|
|
|
|
: EdgeInsets.only(
|
|
|
|
|
top: widget.marginTop,
|
|
|
|
|
right: widget.marginRight,
|
|
|
|
|
bottom: widget.marginBottom,
|
|
|
|
|
left: widget.marginLeft),
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Stack(
|
|
|
|
|
children: [
|
|
|
|
|
_textWidget(),
|
|
|
|
|
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",
|
|
|
|
|
)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
// 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() {
|
|
|
|
|
switch (widget.style) {
|
|
|
|
|
case "headline2":
|
|
|
|
|
|