Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
expandable_text.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:flutter_screenutil/flutter_screenutil.dart';
3
4class ExpandableText extends StatefulWidget {
5 final String text;
6 final int maxLines;
7
9 super.key,
10 required this.text,
11 this.maxLines = 2,
12 });
13
14 @override
15 State<ExpandableText> createState() => _ExpandableTextState();
16}
17
18class _ExpandableTextState extends State<ExpandableText> {
19 bool _isExpanded = false;
20 late TextPainter _textPainter;
21 late bool _hasOverflow;
22
23 @override
24 void initState() {
25 super.initState();
27 }
28
30 final textStyle = TextStyle(
31 fontSize: 14.sp,
32 height: 1.5,
33 );
34
35 _textPainter = TextPainter(
36 text: TextSpan(text: widget.text, style: textStyle),
37 maxLines: widget.maxLines,
38 textDirection: TextDirection.ltr,
39 )..layout(maxWidth: 32.w);
40
41 _hasOverflow = _textPainter.didExceedMaxLines;
42 }
43
44 @override
45 Widget build(BuildContext context) {
46 return LayoutBuilder(
47 builder: (context, constraints) {
49
50 return Column(
51 crossAxisAlignment: CrossAxisAlignment.start,
52 children: [
53 Text(
54 widget.text,
55 style: Theme.of(context).textTheme.bodySmall?.copyWith(
56 fontSize: 10.sp,
57 ),
58 maxLines: _isExpanded ? null : widget.maxLines,
59 overflow:
60 _isExpanded ? TextOverflow.visible : TextOverflow.ellipsis,
61 ),
62 if (_hasOverflow) ...[
63 SizedBox(height: 4.h),
64 GestureDetector(
65 onTap: () {
66 setState(() {
68 });
69 },
70 child: Text(
71 _isExpanded ? 'Read Less' : 'Read More',
72 style: Theme.of(context).textTheme.bodySmall?.copyWith(
73 color: Theme.of(context).colorScheme.primary,
74 fontSize: 9.5.sp,
75 fontWeight: FontWeight.w100,
76 ),
77 ),
78 ),
79 ],
80 ],
81 );
82 },
83 );
84 }
85}
const ExpandableText({ super.key, required this.text, this.maxLines=2, })
final String text
override State< ExpandableText > createState()
final Widget child
override void initState()
final VoidCallback onTap
void _checkOverflow()
late TextPainter _textPainter
late bool _hasOverflow
class ExpandableText extends StatefulWidget _isExpanded
final Color color
Definition failures.dart:1
override Widget build(BuildContext context)