Функциональность чата с функцией «Читать больше и читать меньше» не работает.IOS

Программируем под IOS
Ответить
Anonymous
 Функциональность чата с функцией «Читать больше и читать меньше» не работает.

Сообщение Anonymous »

У меня есть функция чата, в которой я передаю текст, и он отображается в чате для вопросов и ответов. Функция чата передает ответы, которые иногда могут представлять собой большой объем текста (как в Whatsapp), поэтому требуется функция «Читать дальше», чтобы только если они захотят прочитать, они могли нажать на кнопку и прочитать ее. Но приведенный ниже код не меняет динамически размер пузырька чата, когда я нажимаю «Подробнее».

Код: Выделить всё

Widget _buildChatBubble(String text, {required bool isQuestion}) {
final double borderRadiusValue = 20.0;
final int maxTextLengthToShow = 200;
bool isTextTooLong = text.length > maxTextLengthToShow;
bool showFullText = false;

return Consumer(
builder: (context, themeProvider, _) {
final String avatarImage = themeProvider.isIconSelected
? 'images/chatbot_icon4.jpg'
: 'images/chatbot_icon4.jpg';

if (!isQuestion) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SizedBox(height: MediaQuery.of(context).size.height * 0.01),
Container(
margin: EdgeInsets.symmetric(vertical: 5.0),
alignment: Alignment.centerLeft,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.only(left: 12.0, right: 5.0),
child: CircleAvatar(
radius: 20,
backgroundImage: AssetImage(avatarImage),
backgroundColor: Colors.transparent,
),
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.7,
child: Container(
constraints: BoxConstraints(
maxWidth: 230.0,
),
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: themeProvider.themeData.colorScheme.onError,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(borderRadiusValue),
bottomRight: Radius.circular(borderRadiusValue),
topRight: Radius.circular(borderRadiusValue),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text.length >  maxTextLengthToShow
? text.substring(0, maxTextLengthToShow) +
"..."
: text,
style: TextStyle(
color: CustomColor.whiteColor,
fontSize: 16.0,
),
),
if (isTextTooLong)
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () {
print('Read More button pressed');
setState(() {
showFullText = !showFullText;
});
},
child: Text(
showFullText ? 'Read Less' : 'Read More',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
IconButton(
onPressed: () {
_copyToClipboard(text);
},
icon: const Icon(
size: 20.0,
Icons.content_copy_rounded,
color: Colors.white,
),
),
IconButton(
onPressed: () {
_speak(text);
},
icon: Icon(
size: 20.0,
Icons.volume_up_sharp,
color: Colors.white,
),
),
],
),
],
),
),
),
],
),
),
Row(
children: [
SizedBox(width: MediaQuery.of(context).size.width * 0.12),
Padding(
padding: EdgeInsets.symmetric(horizontal: 12.0),
child: Text(
DateFormat.yMd().add_jm().format(DateTime.now()),
style: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.black,
fontSize: 12.0,
),
),
),
],
),
SizedBox(height: MediaQuery.of(context).size.height * 0.02),
],
);
} else {
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SizedBox(height: MediaQuery.of(context).size.height * 0.01),
Container(
margin: EdgeInsets.symmetric(vertical: 5.0),
alignment: Alignment.centerRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.75,
child: Container(
constraints: BoxConstraints(
maxWidth: 230.0,
),
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
color:  themeProvider
.themeData.colorScheme.onBackground,
borderRadius: BorderRadius.only(
topRight: Radius.circular(borderRadiusValue),
bottomRight:
Radius.circular(borderRadiusValue * 0.1),
bottomLeft: Radius.circular(borderRadiusValue),
topLeft: Radius.circular(borderRadiusValue),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text,
style: TextStyle(
color: themeProvider
.themeData.colorScheme.onPrimary,
fontSize: 16.0,
),
),
],
),
),
),
),
],
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 12.0),
child: Text(
DateFormat.yMd().add_jm().format(DateTime.now()),
style: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.black,
fontSize: 12.0,
),
),
),
],
);
}
},
);
}
Пожалуйста, дайте мне знать, что вы, ребята, сделаете, чтобы решить эту проблему? Был бы очень признателен!!:-)
Я использовал максимальную длину текста более 200, затем сократил пузырь чата, и это сработало. Проблема в том, что когда я нажимаю «читать дальше», размер не изменяется, и я могу прочитать весь текстовый контейнер. Я хочу, чтобы он динамически менялся для опций «читать больше» и «читать меньше».

Подробнее здесь: https://stackoverflow.com/questions/782 ... ot-working
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»