Создание коллекций

This commit is contained in:
2025-03-25 20:53:53 +03:00
parent cb6ce05059
commit e6517402d3
375 changed files with 1775 additions and 1519 deletions

View File

@@ -33,8 +33,8 @@ class CrudCollectionField extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(12).r,
child:
content != null
? AppTypography(hint, maxLines: 99, type: Regular16px())
content != null && content!.isNotEmpty
? AppTypography(content!, maxLines: 99, type: Regular16px())
: AppTypography(
hint,
maxLines: 99,

View File

@@ -1,6 +1,7 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_keyboard_size/flutter_keyboard_size.dart';
import 'package:remever/common/functions.dart';
import 'package:remever/common/resources.dart';
@@ -11,55 +12,86 @@ import 'package:remever/gen/assets.gen.dart';
import 'package:remever/screens/dialogs/alert_dialog.dart';
@RoutePage()
class CrudCollectionFullscreenField extends StatelessWidget {
CrudCollectionFullscreenField({
class CrudCollectionFullscreenField extends StatefulWidget {
const CrudCollectionFullscreenField({
super.key,
this.title = '',
this.hint,
this.content,
this.height = 92,
required this.onEditingComplete,
});
final String title;
final double height;
final String? hint;
final String? content;
final void Function(String?) onEditingComplete;
@override
State<CrudCollectionFullscreenField> createState() =>
_CrudCollectionFullscreenFieldState();
}
class _CrudCollectionFullscreenFieldState
extends State<CrudCollectionFullscreenField> {
final TextEditingController _controller = TextEditingController();
@override
void initState() {
if (widget.content != null) {
_controller.text = widget.content!;
}
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return KeyboardSizeProvider(
child: Scaffold(
backgroundColor: AppColors.gray_bg,
appBar: _buildAppBar(context),
body: _buildMainBody(context),
child: SafeArea(
top: false,
child: Scaffold(
backgroundColor: AppColors.gray_bg,
appBar: _buildAppBar(context),
body: _buildMainBody(context),
),
),
);
}
/// Построение основного тела экрана
Widget _buildMainBody(BuildContext context) {
return Column(
children: <Widget>[
return Stack(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16).r,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const HSpace(16),
_buildField(context),
if (hint != null) ...<Widget>[
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const HSpace(16),
AppTypography(
hint!,
type: Regular14px(),
color: AppColors.disabled,
),
_buildField(context),
if (widget.hint != null) ...[
const HSpace(16),
AppTypography(
widget.hint!,
type: Regular14px(),
color: AppColors.disabled,
),
],
const HSpace(50),
],
],
),
),
),
const Spacer(),
_buildMenu(),
Align(alignment: Alignment.bottomCenter, child: _buildMenu()),
],
);
}
@@ -67,9 +99,10 @@ class CrudCollectionFullscreenField extends StatelessWidget {
/// Построение интерактивной плашки меню
Widget _buildMenu() {
return Consumer<ScreenHeight>(
builder: (BuildContext context, ScreenHeight res, Widget? child) {
builder: (context, screenHeight, _) {
return AnimatedOpacity(
opacity: res.isOpen ? 1 : 0,
// opacity: screenHeight.isOpen ? 1 : 0,
opacity: 1,
duration: const Duration(milliseconds: 500),
child: Container(
height: 64.h,
@@ -81,37 +114,10 @@ class CrudCollectionFullscreenField extends StatelessWidget {
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
GestureDetector(
onTap: () {},
child: Assets.icons.typePaste.image(
height: 24.h,
width: 24.w,
),
),
GestureDetector(
onTap: () {},
child: Assets.icons.typeCopy.image(height: 24.h, width: 24.w),
),
GestureDetector(
onTap: () => context.back(),
child: SizedBox.square(
dimension: 32.r,
child: DecoratedBox(
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: AppColors.primary,
),
child: Center(
child: Assets.icons.typeCheck.image(
height: 24.h,
width: 24.w,
color: AppColors.white,
),
),
),
),
),
children: [
_buildPasteButton(),
_buildCopyButton(),
_buildSubmitButton(),
],
),
),
@@ -120,14 +126,96 @@ class CrudCollectionFullscreenField extends StatelessWidget {
);
}
/// Кнопка "Вставить из буфера обмена"
Widget _buildPasteButton() {
return GestureDetector(
onTap: _onPasteTap,
child: Assets.icons.typePaste.image(height: 24.h, width: 24.w),
);
}
/// Обработка нажатия на кнопку "Вставить"
void _onPasteTap() async {
try {
final ClipboardData? data = await Clipboard.getData('text/plain');
if (data?.text == null || data!.text!.isEmpty) {
showErrorToast('Не удалось получить текст из буфера обмена');
return;
}
_controller.text += ' ${data.text}';
showSuccessToast('Текст вставлен из буфера обмена');
} catch (e) {
showErrorToast('Ошибка при вставке текста: $e');
}
}
/// Кнопка "Скопировать в буфер обмена"
Widget _buildCopyButton() {
return GestureDetector(
onTap: _onCopyTap,
child: Assets.icons.typeCopy.image(height: 24.h, width: 24.w),
);
}
/// Обработка нажатия на кнопку "Копировать"
void _onCopyTap() async {
if (_controller.text.isEmpty) {
showErrorToast('Нет содержимого для отправки в буфер обмена');
return;
}
try {
await Clipboard.setData(ClipboardData(text: _controller.text));
showSuccessToast('Текст скопирован в буфер обмена');
} catch (e) {
showErrorToast('Ошибка при копировании текста: $e');
}
}
/// Кнопка "Подтвердить"
Widget _buildSubmitButton() {
return GestureDetector(
onTap: _onSubmitTap,
child: SizedBox.square(
dimension: 32.r,
child: DecoratedBox(
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: AppColors.primary,
),
child: Center(
child: Assets.icons.typeCheck.image(
height: 24.h,
width: 24.w,
color: AppColors.white,
),
),
),
),
);
}
/// Обработка нажатия на кнопку "Подтвердить"
void _onSubmitTap() {
if (_controller.text.isEmpty) {
showErrorToast(
'Для создания публичной коллекции добавьте описание и тэги',
);
return;
}
widget.onEditingComplete(_controller.text);
context.back();
}
/// Построение поля ввода
Widget _buildField(BuildContext context) {
return SizedBox(
height: height.h,
height: widget.height.h,
child: DecoratedBox(
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: const BorderRadius.all(Radius.circular(12)).r,
borderRadius: BorderRadius.circular(12).r,
),
child: Padding(
padding: const EdgeInsets.all(12).r,
@@ -136,6 +224,7 @@ class CrudCollectionFullscreenField extends StatelessWidget {
controller: _controller,
textCapitalization: TextCapitalization.sentences,
maxLines: 99,
maxLength: 250,
cursorColor: AppColors.danger,
decoration: const InputDecoration.collapsed(
hintText: 'Введите содержимое',
@@ -154,50 +243,23 @@ class CrudCollectionFullscreenField extends StatelessWidget {
backgroundColor: AppColors.white,
shadowColor: Colors.transparent,
leading: IconButton(
onPressed: () async {
context.back();
},
onPressed: () => _handleBackPress(context),
icon: const Icon(CupertinoIcons.left_chevron, color: Colors.black),
),
centerTitle: true,
title: GestureDetector(
onLongPress: () async {
final bool? res = await showCuperModalBottomSheet(
context: context,
height: 262.h,
builder:
(BuildContext context) => const AlertInfoDialog(
title:
'Вы хотите выйти из режима создания описания коллекции?',
acceptTitle: 'Выйти, не сохранять',
declineTitle: 'Сохранить и выйти',
),
);
if (res != null && res) context.back();
},
// onLongPress: () => _showExitDialog(context),
child: AppTypography(
title,
widget.title,
type: SemiBold20px(),
color: AppColors.body_text,
),
),
actions: <Widget>[
actions: [
Padding(
padding: const EdgeInsets.only(right: 16).r,
child: GestureDetector(
onTap: () {
showCuperModalBottomSheet(
context: context,
height: 262.h,
builder:
(BuildContext context) => const AlertInfoDialog(
title: 'Вы хотите сбросить все внесенные изменения?',
acceptTitle: 'Да, сбросить',
declineTitle: 'Нет, оставить',
),
);
},
onTap: () => _showResetDialog(context),
child: Assets.icons.typeTrash.image(
height: 24.h,
width: 24.w,
@@ -208,4 +270,40 @@ class CrudCollectionFullscreenField extends StatelessWidget {
],
);
}
/// Обработка нажатия на кнопку "Назад"
void _handleBackPress(BuildContext context) async {
// final bool? shouldExit = await _showExitDialog(context);
// if (shouldExit ?? false) {
context.back();
// }
}
/// Показать диалог выхода
Future<bool?> _showExitDialog(BuildContext context) async {
return showCuperModalBottomSheet(
context: context,
height: 262.h,
builder:
(context) => const AlertInfoDialog(
title: 'Вы хотите выйти из режима создания описания коллекции?',
acceptTitle: 'Выйти, не сохранять',
declineTitle: 'Сохранить и выйти',
),
);
}
/// Показать диалог сброса
void _showResetDialog(BuildContext context) {
// showCuperModalBottomSheet(
// context: context,
// height: 262.h,
// builder:
// (context) => const AlertInfoDialog(
// title: 'Вы хотите сбросить все внесенные изменения?',
// acceptTitle: 'Да, сбросить',
// declineTitle: 'Нет, оставить',
// ),
// );
}
}