Created
March 14, 2020 12:01
-
-
Save vasyafromrussia/86ae91df9008b9c1742e36824c8f10db to your computer and use it in GitHub Desktop.
Flutter simple expandable text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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