You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemm-flutter-app/lib/widgets/txt.dart

171 lines
4.8 KiB
Dart

4 years ago
// import 'package:auto_size_text/auto_size_text.dart';
import 'package:mohem_flutter_app/theme/colors.dart';
import 'package:mohem_flutter_app/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
enum TxtType {
small,
normal,
heading1,
heading2,
heading3,
appBar,
}
class Txt extends StatelessWidget {
String text;
int? maxLines;
double? fontSize;
Color? color;
bool? bold;
bool? isUnderline;
bool? isFlatButton;
double? pedding;
TextAlign? textAlign;
FontWeight? fontWeight;
Function? onTap;
TxtType txtType;
Txt(this.text, {this.maxLines, this.color, this.bold, this.fontSize, this.isUnderline, this.isFlatButton, this.pedding, this.textAlign, this.fontWeight, this.onTap, this.txtType = TxtType.normal});
@override
Widget build(BuildContext context) {
if (isFlatButton != null)
return Padding(
padding: EdgeInsets.only(right: pedding ?? 0, left: pedding ?? 0),
child: InkWell(
onTap: () {
onTap!();
},
customBorder: inkWellCorner(r: 4),
child: Padding(
padding: const EdgeInsets.only(
left: 14,
right: 14,
top: 6,
bottom: 6,
),
child: getText(),
),
),
);
else
return getText();
}
Widget getText() {
return Material(
type: MaterialType.transparency,
child: Text(
text,
maxLines: maxLines,
textAlign: textAlign,
overflow: maxLines != null ? TextOverflow.ellipsis : null,
style: TextStyle(
fontSize: fontSize ??
(txtType == TxtType.small
? 8.sp
: txtType == TxtType.normal
? 10.sp
: txtType == TxtType.heading1
? 11.sp
: txtType == TxtType.heading2
? 12.sp
: txtType == TxtType.heading3
? 13.sp
: txtType == TxtType.appBar
? 14.sp
: 8.sp),
color: color ??
(txtType == TxtType.appBar
? Colors.black
: txtType == TxtType.heading1
? headingColor
: txtType == TxtType.heading2
? headingColor
: txtType == TxtType.heading3
? headingColor
: null),
fontWeight: (fontWeight != null)
? fontWeight
: ((bold != null)
? FontWeight.bold
: (txtType == TxtType.appBar
? FontWeight.bold
: txtType == TxtType.heading1
? FontWeight.bold
: txtType == TxtType.heading2
? FontWeight.bold
: txtType == TxtType.heading3
? FontWeight.bold
: null)),
decoration: (isUnderline != null) ? TextDecoration.underline : null,
),
),
);
}
}
// class TxtAuto extends StatelessWidget {
// String text;
// int? maxLines;
// double? fontSize;
// Color? color;
// bool? bold;
// bool? isUnderline;
// bool? isFlatButton;
// double? pedding;
// TextAlign? textAlign;
//
// TxtAuto(
// this.text, {
// this.maxLines,
// this.color,
// this.bold,
// this.fontSize,
// this.isUnderline,
// this.isFlatButton,
// this.pedding,
// this.textAlign,
// });
//
// @override
// Widget build(BuildContext context) {
// if (isFlatButton != null)
// return Padding(
// padding: EdgeInsets.only(right: pedding ?? 0, left: pedding ?? 0),
// child: InkWell(
// onTap: () {},
// customBorder: inkWellCorner(r: 4),
// child: Padding(
// padding: const EdgeInsets.only(
// left: 14,
// right: 14,
// top: 6,
// bottom: 6,
// ),
// child: getText(),
// ),
// ),
// );
// else
// return getText();
// }
//
// Widget getText() {
// return AutoSizeText(
// text,
// maxLines: maxLines,
// textAlign: textAlign,
// overflow: maxLines != null ? TextOverflow.ellipsis : null,
// style: TextStyle(
// fontSize: fontSize,
// color: color,
// fontWeight: (bold != null) ? FontWeight.bold : null,
// decoration: (isUnderline != null) ? TextDecoration.underline : null,
// ),
// );
// }
// }