bugfix(collections): Оптимизация редактирования и создания коллекции
This commit is contained in:
@@ -39,10 +39,10 @@ class _CrudCollectionFullscreenFieldState
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.content != null) {
|
||||
_controller.text = widget.content!;
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -58,15 +58,14 @@ class _CrudCollectionFullscreenFieldState
|
||||
top: false,
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColors.gray_bg,
|
||||
appBar: _buildAppBar(context),
|
||||
body: _buildMainBody(context),
|
||||
appBar: _buildAppBar(),
|
||||
body: _buildMainBody(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение основного тела экрана
|
||||
Widget _buildMainBody(BuildContext context) {
|
||||
Widget _buildMainBody() {
|
||||
return Stack(
|
||||
children: [
|
||||
Padding(
|
||||
@@ -77,7 +76,7 @@ class _CrudCollectionFullscreenFieldState
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const HSpace(16),
|
||||
_buildField(context),
|
||||
_buildField(),
|
||||
if (widget.hint != null) ...[
|
||||
const HSpace(16),
|
||||
AppTypography(
|
||||
@@ -96,12 +95,10 @@ class _CrudCollectionFullscreenFieldState
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение интерактивной плашки меню
|
||||
Widget _buildMenu() {
|
||||
return Consumer<ScreenHeight>(
|
||||
builder: (context, screenHeight, _) {
|
||||
builder: (_, screenHeight, __) {
|
||||
return AnimatedOpacity(
|
||||
// opacity: screenHeight.isOpen ? 1 : 0,
|
||||
opacity: 1,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
child: Container(
|
||||
@@ -126,7 +123,6 @@ class _CrudCollectionFullscreenFieldState
|
||||
);
|
||||
}
|
||||
|
||||
/// Кнопка "Вставить из буфера обмена"
|
||||
Widget _buildPasteButton() {
|
||||
return GestureDetector(
|
||||
onTap: _onPasteTap,
|
||||
@@ -134,22 +130,20 @@ class _CrudCollectionFullscreenFieldState
|
||||
);
|
||||
}
|
||||
|
||||
/// Обработка нажатия на кнопку "Вставить"
|
||||
void _onPasteTap() async {
|
||||
Future<void> _onPasteTap() async {
|
||||
try {
|
||||
final ClipboardData? data = await Clipboard.getData('text/plain');
|
||||
if (data?.text == null || data!.text!.isEmpty) {
|
||||
final data = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
if (data?.text?.isEmpty ?? true) {
|
||||
showErrorToast('Не удалось получить текст из буфера обмена');
|
||||
return;
|
||||
}
|
||||
_controller.text += ' ${data.text}';
|
||||
_controller.text += ' ${data!.text}';
|
||||
showSuccessToast('Текст вставлен из буфера обмена');
|
||||
} catch (e) {
|
||||
showErrorToast('Ошибка при вставке текста: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Кнопка "Скопировать в буфер обмена"
|
||||
Widget _buildCopyButton() {
|
||||
return GestureDetector(
|
||||
onTap: _onCopyTap,
|
||||
@@ -157,8 +151,7 @@ class _CrudCollectionFullscreenFieldState
|
||||
);
|
||||
}
|
||||
|
||||
/// Обработка нажатия на кнопку "Копировать"
|
||||
void _onCopyTap() async {
|
||||
Future<void> _onCopyTap() async {
|
||||
if (_controller.text.isEmpty) {
|
||||
showErrorToast('Нет содержимого для отправки в буфер обмена');
|
||||
return;
|
||||
@@ -171,45 +164,30 @@ class _CrudCollectionFullscreenFieldState
|
||||
}
|
||||
}
|
||||
|
||||
/// Кнопка "Подтвердить"
|
||||
Widget _buildSubmitButton() {
|
||||
return GestureDetector(
|
||||
onTap: _onSubmitTap,
|
||||
child: SizedBox.square(
|
||||
dimension: 32.r,
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
child: const DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
child: Center(
|
||||
child: Assets.icons.typeCheck.image(
|
||||
height: 24.h,
|
||||
width: 24.w,
|
||||
color: AppColors.white,
|
||||
),
|
||||
child: Icon(Icons.check, color: AppColors.white, size: 24),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Обработка нажатия на кнопку "Подтвердить"
|
||||
void _onSubmitTap() {
|
||||
if (_controller.text.isEmpty) {
|
||||
showErrorToast(
|
||||
'Для создания публичной коллекции добавьте описание и тэги',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
widget.onEditingComplete(_controller.text);
|
||||
|
||||
context.back();
|
||||
}
|
||||
|
||||
/// Построение поля ввода
|
||||
Widget _buildField(BuildContext context) {
|
||||
Widget _buildField() {
|
||||
return SizedBox(
|
||||
height: widget.height.h,
|
||||
child: DecoratedBox(
|
||||
@@ -236,30 +214,26 @@ class _CrudCollectionFullscreenFieldState
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение шапки
|
||||
AppBar _buildAppBar(BuildContext context) {
|
||||
AppBar _buildAppBar() {
|
||||
return AppBar(
|
||||
toolbarHeight: 56.h,
|
||||
backgroundColor: AppColors.white,
|
||||
shadowColor: Colors.transparent,
|
||||
leading: IconButton(
|
||||
onPressed: () => _handleBackPress(context),
|
||||
onPressed: () => _handleBackPress(),
|
||||
icon: const Icon(CupertinoIcons.left_chevron, color: Colors.black),
|
||||
),
|
||||
centerTitle: true,
|
||||
title: GestureDetector(
|
||||
// onLongPress: () => _showExitDialog(context),
|
||||
child: AppTypography(
|
||||
widget.title,
|
||||
type: SemiBold20px(),
|
||||
color: AppColors.body_text,
|
||||
),
|
||||
title: AppTypography(
|
||||
widget.title,
|
||||
type: SemiBold20px(),
|
||||
color: AppColors.body_text,
|
||||
),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16).r,
|
||||
child: GestureDetector(
|
||||
onTap: () => _showResetDialog(context),
|
||||
onTap: _showResetDialog,
|
||||
child: Assets.icons.typeTrash.image(
|
||||
height: 24.h,
|
||||
width: 24.w,
|
||||
@@ -271,39 +245,46 @@ class _CrudCollectionFullscreenFieldState
|
||||
);
|
||||
}
|
||||
|
||||
/// Обработка нажатия на кнопку "Назад"
|
||||
void _handleBackPress(BuildContext context) async {
|
||||
// final bool? shouldExit = await _showExitDialog(context);
|
||||
// if (shouldExit ?? false) {
|
||||
context.back();
|
||||
// }
|
||||
Future<void> _handleBackPress() async {
|
||||
final shouldExit = await _showExitDialog();
|
||||
if (shouldExit ?? false) {
|
||||
context.back();
|
||||
}
|
||||
}
|
||||
|
||||
/// Показать диалог выхода
|
||||
Future<bool?> _showExitDialog(BuildContext context) async {
|
||||
return showCuperModalBottomSheet(
|
||||
Future<bool?> _showExitDialog() async {
|
||||
final res = await showCuperModalBottomSheet<bool>(
|
||||
context: context,
|
||||
height: 262.h,
|
||||
builder:
|
||||
(context) => const AlertInfoDialog(
|
||||
title: 'Вы хотите выйти из режима создания описания коллекции?',
|
||||
acceptTitle: 'Выйти, не сохранять',
|
||||
(_) => const AlertInfoDialog(
|
||||
title: 'У вас есть несохраненные изменения',
|
||||
acceptTitle: 'Выйти',
|
||||
declineTitle: 'Сохранить и выйти',
|
||||
),
|
||||
);
|
||||
|
||||
if (res == null) return false;
|
||||
if (res) return true;
|
||||
|
||||
widget.onEditingComplete(_controller.text);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Показать диалог сброса
|
||||
void _showResetDialog(BuildContext context) {
|
||||
// showCuperModalBottomSheet(
|
||||
// context: context,
|
||||
// height: 262.h,
|
||||
// builder:
|
||||
// (context) => const AlertInfoDialog(
|
||||
// title: 'Вы хотите сбросить все внесенные изменения?',
|
||||
// acceptTitle: 'Да, сбросить',
|
||||
// declineTitle: 'Нет, оставить',
|
||||
// ),
|
||||
// );
|
||||
Future<void> _showResetDialog() async {
|
||||
final res = await showCuperModalBottomSheet<bool>(
|
||||
context: context,
|
||||
height: 262.h,
|
||||
builder:
|
||||
(_) => AlertInfoDialog(
|
||||
title: 'Удалить вcе содержимое поля "${widget.title}"?',
|
||||
acceptTitle: 'Удалить',
|
||||
declineTitle: 'Отменить',
|
||||
),
|
||||
);
|
||||
|
||||
if (res == true) {
|
||||
_controller.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user