forked from eatvio/eatvio_app
fix(password+recipe): Issue-221 and Issue-418
This commit is contained in:
@@ -10,7 +10,11 @@ class ExpandableText extends StatefulWidget {
|
||||
final String text;
|
||||
final int maxLines;
|
||||
|
||||
const ExpandableText({super.key, required this.text, this.maxLines = 3});
|
||||
const ExpandableText({
|
||||
super.key,
|
||||
required this.text,
|
||||
this.maxLines = 5, // по умолчанию 5 строк
|
||||
});
|
||||
|
||||
@override
|
||||
State<ExpandableText> createState() => _ExpandableTextState();
|
||||
@@ -18,6 +22,29 @@ class ExpandableText extends StatefulWidget {
|
||||
|
||||
class _ExpandableTextState extends State<ExpandableText> {
|
||||
bool isExpanded = false;
|
||||
bool showExpandButton = false;
|
||||
|
||||
final GlobalKey _textKey = GlobalKey();
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _checkTextOverflow());
|
||||
}
|
||||
|
||||
void _checkTextOverflow() {
|
||||
final textRenderObject = _textKey.currentContext?.findRenderObject();
|
||||
if (textRenderObject is RenderBox) {
|
||||
final maxLinesHeight = widget.maxLines * TextStyles.textMMediumAuto.fontSize! * 1.2;
|
||||
final actualHeight = textRenderObject.size.height;
|
||||
|
||||
if (actualHeight > maxLinesHeight && !showExpandButton) {
|
||||
setState(() {
|
||||
showExpandButton = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void toggleExpansion() {
|
||||
setState(() {
|
||||
@@ -33,52 +60,63 @@ class _ExpandableTextState extends State<ExpandableText> {
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Stack(
|
||||
children: [
|
||||
Text(
|
||||
widget.text,
|
||||
style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black),
|
||||
// style: {
|
||||
// "*": Style(
|
||||
// margin: Margins.all(0),
|
||||
// color: Colors.black87,
|
||||
// maxLines: isExpanded ? null : widget.maxLines,
|
||||
// textOverflow: TextOverflow.clip,
|
||||
// ),
|
||||
// },
|
||||
),
|
||||
if (!isExpanded)
|
||||
Positioned.fill(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
height: 35,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Colors.white.withValues(alpha: 0.0), Colors.white.withValues(alpha: 0.6), Colors.white],
|
||||
child: AnimatedSize(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeInOut,
|
||||
child: Stack(
|
||||
children: [
|
||||
Text(
|
||||
widget.text,
|
||||
key: _textKey,
|
||||
style: TextStyles.textMMediumAuto.copyWith(color: appTheme.black),
|
||||
maxLines: isExpanded ? null : widget.maxLines,
|
||||
overflow: TextOverflow.clip,
|
||||
),
|
||||
if (!isExpanded && showExpandButton)
|
||||
Positioned.fill(
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Container(
|
||||
height: 35,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.white.withAlpha(0),
|
||||
Colors.white.withAlpha((255 * 0.6).toInt()),
|
||||
Colors.white,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: GestureDetector(
|
||||
onTap: toggleExpansion,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(isExpanded ? s.hide : s.expand, style: TextStyles.textMMedium.copyWith(color: appTheme.blueA400)),
|
||||
Transform.rotate(angle: isExpanded ? math.pi : 0, child: SvgPicture.asset('assets/icons/arrow_down.svg', width: 12, height: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showExpandButton)
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: GestureDetector(
|
||||
onTap: toggleExpansion,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
isExpanded ? s.hide : s.expand,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.blueA400),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Transform.rotate(
|
||||
angle: isExpanded ? math.pi : 0,
|
||||
child: SvgPicture.asset('assets/icons/arrow_down.svg', width: 12, height: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user