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