/* * @Author : Linloir * @Date : 2022-10-14 17:04:12 * @LastEditTime : 2022-10-15 10:53:28 * @Description : */ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:tcp_client/chat/cubit/chat_cubit.dart'; import 'package:tcp_client/chat/model/chat_history.dart'; import 'package:tcp_client/repositories/tcp_repository/models/tcp_request.dart'; class TextBox extends StatelessWidget { const TextBox({ required this.history, super.key }); final ChatHistory history; @override Widget build(BuildContext context) { return InkWell( onTap: (){}, child: Padding( padding: const EdgeInsets.all(8.0), child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ if(history.type == ChatHistoryType.outcome) ...[ if(history.status == ChatHistoryStatus.sending) ...[ SizedBox( height: 15.0, width: 15.0, child: CircularProgressIndicator( color: Colors.white.withOpacity(0.5), strokeWidth: 2.0, ), ), const SizedBox(width: 16.0,), ], if(history.status == ChatHistoryStatus.failed) ...[ ClipOval( child: Material( color: Colors.transparent, child: InkWell( child: Icon( Icons.error_rounded, color: Colors.white.withOpacity(0.5), size: 20, ), onTap: () async { context.read().tcpRepository.pushRequest(SendMessageRequest( message: history.message, token: (await SharedPreferences.getInstance()).getInt('token') )); }, ), ), ), const SizedBox(width: 8.0,), ], if(history.status == ChatHistoryStatus.done) ...[ Icon( Icons.check_rounded, color: Colors.white.withOpacity(0.5), size: 20, ), const SizedBox(width: 12.0,), ], ], Flexible( child: Text( history.message.contentDecoded, softWrap: true, style: TextStyle( fontSize: 18, color: history.type == ChatHistoryType.income ? Colors.grey[900] : Colors.white ), ), ), ] ) ), ); } }