I'm getting data from the API, text length is different from every post, so I want to make a responsible Text
widget, which is want to behave like this image
I tried this solution but here if I click show more text every Text widget size is increase(see this
) because I declare
descTextShowFlag
this bool
variable as global, and are there any way to increase the text widget height dynamically because here I want to give the maxline
property as default, this maxline
property also want to increase dynamically, If there any good way to that please tell me
import 'package:auto_size_text/auto_size_text.dart';
import 'package:exa/Model/ModelNewsFeed.dart';
import 'package:flutter/material.dart';
class Examplewidget extends StatefulWidget {
NewsFeeds newsFeeds;
Examplewidget(this.newsFeeds);
@override
_ExamplewidgetState createState() => _ExamplewidgetState();
}
class _ExamplewidgetState extends State<Examplewidget> {
String data = "We’ll see how image picker works in flutter for android and iOS. Ans: Image picker is a plugin which is used to get images from gallery or camera in the app. ... This is called Privacy - Photo Library Usage Description in the visual editor(Xcode or Android Studio).";
bool descTextShowFlag = false;
@override
Widget build(BuildContext context) {
int listsize = widget.newsFeeds.data.data.length;
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(14.0),
child: ListView.builder(
itemCount: listsize,
itemBuilder: (context, index) {
String textStatus =
"${widget.newsFeeds.data.data[index].postContent}";
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text( "$textStatus",
style: TextStyle(fontSize: 16.0),
maxLines: descTextShowFlag ? 8 : 2,
textAlign: TextAlign.start),
InkWell(
onTap: () {
setState(() {
descTextShowFlag = !descTextShowFlag;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
descTextShowFlag
? Text(
"Show Less",
style: TextStyle(
fontSize: 16.0,
color: Colors.blue),
)
: Text("Show More",
style: TextStyle(color: Colors.blue))
],
),
),
],
);
}),
),
);
}
}