forked from eatvio/eatvio_app
260 lines
11 KiB
Dart
260 lines
11 KiB
Dart
import 'dart:io';
|
|
import 'dart:math';
|
|
|
|
import 'package:eatvio_app/core/app_router.dart';
|
|
import 'package:eatvio_app/core/locator_service.dart';
|
|
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
|
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
|
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
|
import 'package:file_picker/file_picker.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_cubit.dart';
|
|
import 'package:eatvio_app/features/menu/presentation/blocked_user_cubit/blocked_users_state.dart';
|
|
|
|
class EmptyChatScreen extends StatefulWidget {
|
|
final ProfileModel user;
|
|
|
|
const EmptyChatScreen({super.key, required this.user});
|
|
|
|
@override
|
|
State<EmptyChatScreen> createState() => _EmptyChatScreenState();
|
|
}
|
|
|
|
class _EmptyChatScreenState extends State<EmptyChatScreen> {
|
|
final TextEditingController textEditingController = TextEditingController();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: true,
|
|
appBar: AppBar(
|
|
titleSpacing: 0,
|
|
backgroundColor: appTheme.gray100,
|
|
centerTitle: false,
|
|
title: GestureDetector(
|
|
onTap: () {
|
|
GoRouter.of(context).pushNamed('profileScreen', extra: widget.user.slug);
|
|
},
|
|
child: Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 20,
|
|
foregroundImage: NetworkImage(widget.user.profilePhotoUrl),
|
|
backgroundImage: const AssetImage('assets/images/no_avatar.png'),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [Text(widget.user.name, style: CustomTextStyles.titleSmallBold.copyWith(color: PrimaryColors().black))],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
body: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
const Spacer(),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
const SizedBox(width: 8),
|
|
InkWell(
|
|
onTap: () => showImagePicker(widget.user.slug),
|
|
customBorder: const CircleBorder(),
|
|
child: Ink(
|
|
height: 40,
|
|
width: 40,
|
|
child: Transform.rotate(
|
|
angle: pi / 4,
|
|
child: const Icon(Icons.attach_file_rounded, size: 30, color: Color(0xFF858E99)),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: TextFormField(
|
|
textCapitalization: TextCapitalization.sentences,
|
|
controller: textEditingController,
|
|
maxLines: 3,
|
|
minLines: 1,
|
|
keyboardType: TextInputType.multiline,
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w400, color: Colors.black, height: 1),
|
|
decoration: InputDecoration(
|
|
isDense: true,
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
|
hintText: 'Сообщение',
|
|
hintStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w400, height: 1, color: Color(0xFFAEAEB2)),
|
|
filled: true,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(100),
|
|
borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(100),
|
|
borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(100),
|
|
borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
InkWell(
|
|
customBorder: const CircleBorder(),
|
|
onTap: () async {
|
|
// Проверяем, заблокирован ли пользователь
|
|
final blockedUsersCubit = sl<BlockedUsersCubit>();
|
|
await blockedUsersCubit.getBlockedUsers();
|
|
final blockedState = blockedUsersCubit.state;
|
|
|
|
if (blockedState is BlockedUsersStateLoaded) {
|
|
final isBlocked = blockedState.profilesList.any((profile) => profile.slug == widget.user.slug);
|
|
if (isBlocked) {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Вы не можете отправить сообщение заблокированному пользователю'), backgroundColor: Colors.red),
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (textEditingController.text.isNotEmpty) {
|
|
await sl<ChatRepository>().sendMessage(data: textEditingController.text.trim(), slug: widget.user.slug);
|
|
if (mounted) {
|
|
setState(() {
|
|
textEditingController.clear();
|
|
});
|
|
}
|
|
final chatIdOrError = await sl<ChatRepository>().getChatByUserSlug(widget.user.slug);
|
|
if (context.mounted) {
|
|
AppRouter.navigatorKey.currentContext?.pushReplacementNamed('chatScreen', extra: {'uuid': chatIdOrError});
|
|
}
|
|
}
|
|
},
|
|
child: Ink(
|
|
decoration: BoxDecoration(color: appTheme.blueA400, shape: BoxShape.circle),
|
|
height: 40,
|
|
width: 40,
|
|
child: const Icon(Icons.arrow_upward_rounded, size: 24, color: Colors.white),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void showImagePicker(String slug) {
|
|
showCupertinoModalPopup<void>(
|
|
context: context,
|
|
builder: (context) => CupertinoActionSheet(
|
|
actions: [
|
|
CupertinoActionSheetAction(
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
|
|
// Проверяем, заблокирован ли пользователь
|
|
final blockedUsersCubit = sl<BlockedUsersCubit>();
|
|
await blockedUsersCubit.getBlockedUsers();
|
|
final blockedState = blockedUsersCubit.state;
|
|
|
|
if (blockedState is BlockedUsersStateLoaded) {
|
|
final isBlocked = blockedState.profilesList.any((profile) => profile.slug == widget.user.slug);
|
|
if (isBlocked) {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Вы не можете отправить сообщение заблокированному пользователю'), backgroundColor: Colors.red),
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
final picker = ImagePicker();
|
|
List<XFile>? images = await picker.pickMultiImage();
|
|
if (images.isNotEmpty) {
|
|
List<File> files = images.map((image) => File(image.path)).toList();
|
|
await sl<ChatRepository>().sendMessage(files: files, slug: widget.user.slug);
|
|
final chatIdOrError = await sl<ChatRepository>().getChatByUserSlug(widget.user.slug);
|
|
if (mounted) {
|
|
AppRouter.navigatorKey.currentContext?.pushReplacementNamed('chatScreen', extra: {'uuid': chatIdOrError});
|
|
}
|
|
}
|
|
},
|
|
child: const Row(children: [Icon(Icons.photo_library_rounded), SizedBox(width: 8), Text('Галерея')]),
|
|
),
|
|
CupertinoActionSheetAction(
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
final picker = ImagePicker();
|
|
List<XFile>? images = await picker.pickMultiImage();
|
|
if (images.isNotEmpty) {
|
|
List<File> files = images.map((image) => File(image.path)).toList();
|
|
await sl<ChatRepository>().sendMessage(files: files, slug: widget.user.slug);
|
|
final chatIdOrError = await sl<ChatRepository>().getChatByUserSlug(widget.user.slug);
|
|
if (mounted) {
|
|
AppRouter.navigatorKey.currentContext?.pushReplacementNamed('chatScreen', extra: {'uuid': chatIdOrError});
|
|
}
|
|
}
|
|
},
|
|
child: const Row(children: [Icon(Icons.photo_camera), SizedBox(width: 8), Text('Фото')]),
|
|
),
|
|
CupertinoActionSheetAction(
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
|
allowMultiple: true,
|
|
type: FileType.custom,
|
|
allowedExtensions: [
|
|
'pdf',
|
|
'doc',
|
|
'docx',
|
|
'json',
|
|
'ppt',
|
|
'pptx',
|
|
'rtf',
|
|
'txt',
|
|
'xls',
|
|
'xlsx',
|
|
'csv',
|
|
'jpeg',
|
|
'jpg',
|
|
'png',
|
|
'gif',
|
|
'svg',
|
|
'xml',
|
|
'webp',
|
|
],
|
|
);
|
|
if (result != null) {
|
|
List<File> files = result.paths.map((path) => File(path!)).toList();
|
|
await sl<ChatRepository>().sendMessage(files: files, slug: widget.user.slug);
|
|
final chatIdOrError = await sl<ChatRepository>().getChatByUserSlug(widget.user.slug);
|
|
if (mounted) {
|
|
AppRouter.navigatorKey.currentContext?.pushReplacementNamed('chatScreen', extra: {'uuid': chatIdOrError});
|
|
}
|
|
}
|
|
},
|
|
child: const Row(children: [Icon(Icons.file_present_rounded), SizedBox(width: 8), Text('Файлы')]),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(onPressed: () => Navigator.of(context).pop(), isDestructiveAction: true, child: const Text('Отмена')),
|
|
),
|
|
);
|
|
}
|
|
}
|