D1APP-53 chat (beta)
This commit is contained in:
parent
e0e92c41d3
commit
5f971f4ae5
|
|
@ -88,11 +88,12 @@ class DirectState extends CoreProvier {
|
|||
}
|
||||
|
||||
Future<void> sendMessage() async {
|
||||
if (text == null || text!.isEmpty && recordedFile == null) return;
|
||||
if ((text == null || text!.isEmpty) && recordedFile == null) return;
|
||||
final body = {};
|
||||
if (text != null) {
|
||||
body.addAll({'text': text});
|
||||
messages.add(
|
||||
messages.insert(
|
||||
0,
|
||||
MessageData(
|
||||
id: 0,
|
||||
writedByAdmin: false,
|
||||
|
|
@ -115,6 +116,10 @@ class DirectState extends CoreProvier {
|
|||
notifyListeners();
|
||||
final service =
|
||||
RequestService(RequestHelper.sendDirectMessage(typeId), body: body);
|
||||
if (recordedFile == null) {
|
||||
await service.post();
|
||||
} else {
|
||||
await service.multipart(recordedFile, 'POST');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class Message extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
final firstMessageOfGroupId = context
|
||||
.read<DirectState>()
|
||||
.dailyMessages[message.createdAt.split('T').first]!
|
||||
.dailyMessages[message.createdAt.replaceAll('T', ' ').split(' ').first]!
|
||||
.last;
|
||||
return Column(
|
||||
crossAxisAlignment: message.writedByAdmin
|
||||
|
|
@ -156,9 +156,9 @@ class _MessageContainer extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: DesignConfig.highBorderRadius.copyWith(
|
||||
borderRadius: DesignConfig.mediumBorderRadius.copyWith(
|
||||
bottomLeft: writedByAdmin ? Radius.zero : null,
|
||||
bottomRight: !writedByAdmin ? Radius.zero : null,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ class _TypingState extends State<_Typing> {
|
|||
flex: 15,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: TextField(
|
||||
child: TextFormField(
|
||||
textInputAction: TextInputAction.send,
|
||||
style: Theme.of(context).textTheme.bodyText2,
|
||||
decoration: InputDecoration(
|
||||
|
|
@ -147,7 +147,7 @@ class _RecordChecking extends StatelessWidget {
|
|||
children: [
|
||||
DidvanIconButton(
|
||||
icon: DidvanIcons.send_solid,
|
||||
onPressed: () => state.stopRecording(sendImidiately: true),
|
||||
onPressed: state.sendMessage,
|
||||
color: Theme.of(context).colorScheme.focusedBorder,
|
||||
),
|
||||
Expanded(
|
||||
|
|
|
|||
|
|
@ -55,11 +55,20 @@ class ChatRoomItem extends StatelessWidget {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
if (chatRoom.lastMessage.text == null)
|
||||
const Icon(
|
||||
DidvanIcons.mic_light,
|
||||
size: 18,
|
||||
),
|
||||
DidvanText(
|
||||
chatRoom.lastMessage.text ?? '',
|
||||
chatRoom.lastMessage.text ?? 'پیام صوتی',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
DidvanText(
|
||||
DateTimeUtils.momentGenerator(chatRoom.updatedAt),
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ class UserProvider extends CoreProvier {
|
|||
return token;
|
||||
}
|
||||
await StorageService.setValue(key: 'token', value: newToken);
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> getUserInfo() async {
|
||||
|
|
@ -36,7 +37,7 @@ class UserProvider extends CoreProvier {
|
|||
appState = AppState.isolatedBusy;
|
||||
final RequestService service =
|
||||
RequestService(RequestHelper.updateUserProfile);
|
||||
await service.multipart(file);
|
||||
await service.multipart(file, 'PUT');
|
||||
if (service.isSuccess) {
|
||||
user = user.copyWith(photo: service.result['photo']);
|
||||
appState = AppState.idle;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:convert';
|
|||
import 'dart:developer';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http_parser/http_parser.dart' as parser;
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class RequestService {
|
||||
static late String token;
|
||||
|
|
@ -100,12 +99,17 @@ class RequestService {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> multipart(XFile file) async {
|
||||
Future<void> multipart(dynamic file, String method) async {
|
||||
try {
|
||||
final request = http.MultipartRequest('PUT', Uri.parse(url));
|
||||
final request = http.MultipartRequest(method, Uri.parse(url));
|
||||
_headers.update('Content-Type', (_) => 'multipart/form-data');
|
||||
request.headers.addAll(_headers);
|
||||
final length = await file.length();
|
||||
if (_requestBody != null) {
|
||||
_requestBody!.forEach((key, value) {
|
||||
request.fields.addAll({key.toString(): value.toString()});
|
||||
});
|
||||
}
|
||||
request.files.add(
|
||||
http.MultipartFile(
|
||||
'photo',
|
||||
|
|
|
|||
Loading…
Reference in New Issue