Skip to content

Instantly share code, notes, and snippets.

@vasyafromrussia
Created March 14, 2020 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vasyafromrussia/86ae91df9008b9c1742e36824c8f10db to your computer and use it in GitHub Desktop.
Save vasyafromrussia/86ae91df9008b9c1742e36824c8f10db to your computer and use it in GitHub Desktop.
Flutter simple expandable text
class ExpandableText extends StatefulWidget {
final String text;
final int maxLines;
const ExpandableText({Key key, this.maxLines, this.text}) : super(key: key);
@override
_ExpandableTextState createState() => _ExpandableTextState();
}
class _ExpandableTextState extends State<ExpandableText> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) => GestureDetector(
onTap: () {
setState(() {
_isExpanded = !_isExpanded;
});
},
child: Text(
widget.text,
overflow: TextOverflow.ellipsis,
maxLines: _isExpanded ? null : widget.maxLines,
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment