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.
diplomatic-quarter/lib/pages/learning/content_widget.dart

53 lines
1.4 KiB
Dart

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class ContentWidget extends StatefulWidget {
final String body;
ContentWidget({required this.body});
@override
_ContentWidgetState createState() => _ContentWidgetState();
}
class _ContentWidgetState extends State<ContentWidget> {
bool isExpanded = false;
@override
Widget build(BuildContext context) {
final truncatedText = widget.body.length > 70 ? '${widget.body.substring(0, 70)}... ' : widget.body;
return RichText(
text: TextSpan(
children: [
TextSpan(
text: isExpanded ? widget.body : truncatedText,
style: TextStyle(
color: Color(0xFFA2A2A2),
fontSize: 13,
fontWeight: FontWeight.w400,
height: 13 / 10,
),
),
if (widget.body.length > 100)
TextSpan(
text: isExpanded ? 'See Less' : 'See More',
style: TextStyle(
color: Color(0xFF2B353E),
fontSize: 13,
fontWeight: FontWeight.w500,
height: 13 / 10,
),
recognizer: TapGestureRecognizer()
..onTap = () {
setState(() {
isExpanded = !isExpanded;
});
},
),
],
),
);
}
}