bugfix(collections): Оптимизация редактирования и создания коллекции
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
@@ -36,88 +36,85 @@ class CrudCollectionScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
/// Флаг публичности коллекции
|
||||
late CrudCollectionDto _collection;
|
||||
bool _isPublic = false;
|
||||
|
||||
CrudCollectionDto? _collection;
|
||||
|
||||
/// Смена публичности
|
||||
void _setPublic(bool public) {
|
||||
_collection = _collection?.copyWith(isPublic: public);
|
||||
safeSetState(() => _isPublic = public);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeCollection();
|
||||
}
|
||||
|
||||
void _initializeCollection() {
|
||||
_collection = CrudCollectionDto(
|
||||
desc: widget.editedCollection?.desc ?? '',
|
||||
title: widget.editedCollection?.title ?? '',
|
||||
isPublic: widget.editedCollection?.isPublic ?? false,
|
||||
avatar: widget.editedCollection?.image,
|
||||
);
|
||||
|
||||
super.initState();
|
||||
_isPublic = _collection.isPublic;
|
||||
}
|
||||
|
||||
void _pickImage() async {
|
||||
Future<void> _pickImage() async {
|
||||
final result = await FilePicker.platform.pickFiles();
|
||||
|
||||
if (result == null || result.files.isEmpty) {
|
||||
if (result?.files.single.path case final String? path?) {
|
||||
try {
|
||||
final bytes = await File(path!).readAsBytes();
|
||||
_updateCollection(avatar: bytes);
|
||||
} catch (e) {
|
||||
showErrorToast('Не удалось загрузить изображение');
|
||||
}
|
||||
} else {
|
||||
showErrorToast('Файл не выбран');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final filePath = result.files.single.path;
|
||||
|
||||
if (filePath == null) {
|
||||
showErrorToast('Не удалось получить путь к файлу');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final file = File(filePath);
|
||||
final bytes = await file.readAsBytes();
|
||||
|
||||
// final base64String = base64Encode(bytes);
|
||||
|
||||
_collection = _collection?.copyWith(avatar: bytes);
|
||||
|
||||
void _updateCollection({
|
||||
String? title,
|
||||
String? desc,
|
||||
bool? isPublic,
|
||||
Uint8List? avatar,
|
||||
}) {
|
||||
_collection = _collection.copyWith(
|
||||
title: title ?? _collection.title,
|
||||
desc: desc ?? _collection.desc,
|
||||
isPublic: isPublic ?? _collection.isPublic,
|
||||
avatar: avatar ?? _collection.avatar,
|
||||
);
|
||||
safeSetState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
logger.logBuild('build create screen');
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.gray_bg,
|
||||
appBar: _buildAppBar(context),
|
||||
body: _buildMainBody(context),
|
||||
appBar: _buildAppBar(),
|
||||
body: _buildMainBody(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Основное тело экрана
|
||||
Widget _buildMainBody(BuildContext context) {
|
||||
Widget _buildMainBody() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16).r,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
const HSpace(16),
|
||||
_buildPhotoAndTitle(context),
|
||||
_buildPhotoAndTitle(),
|
||||
const HSpace(16),
|
||||
..._buildDescription(context),
|
||||
..._buildDescription(),
|
||||
const HSpace(16),
|
||||
// _buildPublickSwitch(),
|
||||
// _buildPublicSwitch(),
|
||||
const HSpace(16),
|
||||
AnimatedOpacity(
|
||||
// opacity: _isPublic ? 1 : 0,
|
||||
opacity: 0,
|
||||
duration: const Duration(seconds: 1),
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
..._buildTagButton(),
|
||||
const HSpace(16),
|
||||
_buildTagsList(),
|
||||
@@ -125,7 +122,7 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
_buildCreateBtn(context),
|
||||
_buildCreateBtn(),
|
||||
const BottomSafeSpace(),
|
||||
],
|
||||
),
|
||||
@@ -133,30 +130,10 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
///Кнопка создания
|
||||
Widget _buildCreateBtn(BuildContext context) {
|
||||
Widget _buildCreateBtn() {
|
||||
return PrimaryButton(
|
||||
height: 52,
|
||||
onTap: () async {
|
||||
if (_collection!.desc.isEmpty && _collection!.title.isEmpty) {
|
||||
showErrorToast(
|
||||
'Для создания публичной коллекции добавьте описание и тэги',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
widget.editedCollection != null
|
||||
? await getIt<CollectionsInterface>().updateCollection(
|
||||
_collection!,
|
||||
widget.editedCollection!.id,
|
||||
)
|
||||
: await getIt<CollectionsInterface>().createCollection(
|
||||
_collection!,
|
||||
);
|
||||
|
||||
context.back();
|
||||
},
|
||||
onTap: _handleCreateOrUpdate,
|
||||
color: AppColors.primary,
|
||||
child: AppTypography(
|
||||
widget.editedCollection == null
|
||||
@@ -168,24 +145,73 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение списка тегов
|
||||
Future<void> _handleCreateOrUpdate() async {
|
||||
if (!_isCollectionValid()) return;
|
||||
|
||||
if (!_hasChanges()) {
|
||||
context.back();
|
||||
}
|
||||
|
||||
try {
|
||||
final collectionService = getIt<CollectionsInterface>();
|
||||
|
||||
widget.editedCollection != null
|
||||
? await collectionService.updateCollection(
|
||||
_collection,
|
||||
widget.editedCollection!.id,
|
||||
)
|
||||
: await collectionService.createCollection(_collection);
|
||||
|
||||
context.back();
|
||||
} catch (e) {
|
||||
showErrorToast(
|
||||
'Ошибка при ${widget.editedCollection != null ? 'обновлении' : 'создании'} коллекции',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool _isCollectionValid() {
|
||||
if (_collection.title.isEmpty && _collection.desc.isEmpty) {
|
||||
showErrorToast('Для создания коллекции добавьте название и описание');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_isPublic && _collection.desc.isEmpty) {
|
||||
showErrorToast(
|
||||
'Для создания публичной коллекции добавьте описание и тэги',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget _buildTagsList() {
|
||||
return SizedBox(
|
||||
height: 68.h,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
children: [
|
||||
Expanded(
|
||||
child: Wrap(
|
||||
runSpacing: 8.r,
|
||||
spacing: 8.r,
|
||||
children: List<Widget>.generate(6, (int index) {
|
||||
children: List.generate(6, _buildTagItem),
|
||||
),
|
||||
),
|
||||
const WSpace(9),
|
||||
_buildAddTagButton(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTagItem(int index) {
|
||||
return GestureDetector(
|
||||
onTap: () {},
|
||||
child: Container(
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(6)).r,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(6)).r,
|
||||
color: const Color(0xFFFFE4E6),
|
||||
),
|
||||
child: Padding(
|
||||
@@ -193,7 +219,7 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
AppTypography(
|
||||
'tag $index',
|
||||
type: Regular14px(),
|
||||
@@ -201,61 +227,42 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
color: AppColors.danger,
|
||||
),
|
||||
const WSpace(8),
|
||||
Center(
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
size: 14.r,
|
||||
color: AppColors.danger,
|
||||
),
|
||||
),
|
||||
Icon(Icons.close, size: 14.r, color: AppColors.danger),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
const WSpace(9),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
}
|
||||
|
||||
Widget _buildAddTagButton() {
|
||||
return GestureDetector(
|
||||
onTap: _showTagsDialog,
|
||||
child: AppTypography('+13', type: Medium16px(), color: AppColors.primary),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTagsDialog() {
|
||||
showCuperModalBottomSheet(
|
||||
context: context,
|
||||
height: 270.h,
|
||||
builder: (BuildContext context) => const TagsDialog(),
|
||||
);
|
||||
},
|
||||
child: AppTypography(
|
||||
'+13',
|
||||
type: Medium16px(),
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
builder: (_) => const TagsDialog(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение кнопки добавления тега
|
||||
List<Widget> _buildTagButton() {
|
||||
return <Widget>[
|
||||
return [
|
||||
AppTypography('Тэги', type: SemiBold14px()),
|
||||
const HSpace(4),
|
||||
CrudCollectionField(
|
||||
height: 42,
|
||||
width: 348,
|
||||
hint: 'Добавить тэг',
|
||||
// onTap: () => context.pushRoute(const AddTagsRoute()),
|
||||
),
|
||||
CrudCollectionField(height: 42, width: 348, hint: 'Добавить тэг'),
|
||||
];
|
||||
}
|
||||
|
||||
/// Построение свитчера на публичность коллекции
|
||||
Widget _buildPublickSwitch() {
|
||||
Widget _buildPublicSwitch() {
|
||||
return GestureDetector(
|
||||
onTap: () => _setPublic(!_isPublic),
|
||||
onTap: _togglePublic,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
children: [
|
||||
SizedBox.square(
|
||||
dimension: 20.r,
|
||||
child: Assets.icons.typePublic.image(color: AppColors.primary),
|
||||
@@ -287,95 +294,116 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение блока с описанием
|
||||
List<Widget> _buildDescription(BuildContext context) {
|
||||
return <Widget>[
|
||||
void _togglePublic() => _setPublic(!_isPublic);
|
||||
|
||||
void _setPublic(bool isPublic) {
|
||||
_updateCollection(isPublic: isPublic);
|
||||
safeSetState(() => _isPublic = isPublic);
|
||||
}
|
||||
|
||||
List<Widget> _buildDescription() {
|
||||
return [
|
||||
AppTypography('Описание', type: SemiBold14px()),
|
||||
const HSpace(4),
|
||||
CrudCollectionField(
|
||||
height: 110,
|
||||
width: 348,
|
||||
hint: 'Добавить описание',
|
||||
content: _collection?.desc,
|
||||
onTap: () {
|
||||
context.pushRoute(
|
||||
CrudCollectionFullscreenField(
|
||||
content: _collection.desc,
|
||||
onTap:
|
||||
() => _navigateToFullscreenField(
|
||||
title: 'Описание',
|
||||
height: 333,
|
||||
content: _collection?.desc,
|
||||
onEditingComplete: (res) {
|
||||
safeSetState(
|
||||
() => _collection = _collection?.copyWith(desc: res ?? ''),
|
||||
);
|
||||
},
|
||||
content: _collection.desc,
|
||||
onResult: (result) => _updateCollection(desc: result ?? ''),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// Построение блока фото и заголовка
|
||||
Widget _buildPhotoAndTitle(BuildContext context) {
|
||||
return Row(
|
||||
children: <Widget>[_buildPhoto(), const WSpace(8), _buildTitle(context)],
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение поля для ввода заголовка
|
||||
Widget _buildTitle(BuildContext context) {
|
||||
Widget _buildTitle() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
AppTypography('Название', type: SemiBold14px()),
|
||||
const HSpace(4),
|
||||
CrudCollectionField(
|
||||
height: 91,
|
||||
width: 225,
|
||||
hint: 'Добавить название',
|
||||
content: _collection?.title,
|
||||
onTap: () {
|
||||
context.pushRoute(
|
||||
CrudCollectionFullscreenField(
|
||||
content: _collection.title,
|
||||
onTap:
|
||||
() => _navigateToFullscreenField(
|
||||
title: 'Название',
|
||||
hint: 'Максимальное количество символов - 250',
|
||||
content: _collection?.title,
|
||||
onEditingComplete: (res) {
|
||||
safeSetState(
|
||||
() => _collection = _collection?.copyWith(title: res ?? ''),
|
||||
);
|
||||
},
|
||||
content: _collection.title,
|
||||
onResult: (result) => _updateCollection(title: result ?? ''),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение обложки
|
||||
void _navigateToFullscreenField({
|
||||
required String title,
|
||||
String? hint,
|
||||
String? content,
|
||||
required Function(String?) onResult,
|
||||
double height = 91,
|
||||
}) {
|
||||
context.pushRoute(
|
||||
CrudCollectionFullscreenField(
|
||||
title: title,
|
||||
hint: hint,
|
||||
height: height,
|
||||
content: content,
|
||||
onEditingComplete: onResult,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPhotoAndTitle() {
|
||||
return Row(
|
||||
children: [
|
||||
_buildPhoto(),
|
||||
const WSpace(8),
|
||||
Expanded(child: _buildTitle()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPhoto() {
|
||||
return GestureDetector(
|
||||
onTap: () => _pickImage(),
|
||||
onTap: _pickImage,
|
||||
child: SizedBox.square(
|
||||
dimension: 115.r,
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: <Color>[Color(0xFFB6AAFE), Color(0xFFDBD7F4)],
|
||||
colors: [Color(0xFFB6AAFE), Color(0xFFDBD7F4)],
|
||||
begin: Alignment.bottomLeft,
|
||||
end: Alignment.topRight,
|
||||
),
|
||||
),
|
||||
child: Wif(
|
||||
condition: _collection!.avatar != null,
|
||||
condition: _collection.avatar != null,
|
||||
builder:
|
||||
(context) => ClipOval(
|
||||
child: Image.memory(_collection!.avatar!, fit: BoxFit.cover),
|
||||
(_) => ClipOval(
|
||||
child: Image.memory(
|
||||
_collection.avatar!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => _buildPhotoPlaceholder(),
|
||||
),
|
||||
fallback:
|
||||
(context) => SizedBox.square(
|
||||
),
|
||||
fallback: (_) => _buildPhotoPlaceholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPhotoPlaceholder() {
|
||||
return SizedBox.square(
|
||||
dimension: 32.r,
|
||||
child: Center(
|
||||
child: Assets.icons.typePhoto.image(
|
||||
@@ -384,38 +412,16 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Построение шапки
|
||||
AppBar _buildAppBar(BuildContext context) {
|
||||
AppBar _buildAppBar() {
|
||||
return AppBar(
|
||||
toolbarHeight: 56.h,
|
||||
backgroundColor: AppColors.white,
|
||||
shadowColor: Colors.transparent,
|
||||
leading: IconButton(
|
||||
onPressed: () async {
|
||||
if (widget.editedCollection != null) {
|
||||
final bool? res = await showCuperModalBottomSheet(
|
||||
context: context,
|
||||
height: 262.h,
|
||||
builder:
|
||||
(BuildContext context) => const AlertInfoDialog(
|
||||
title: 'Вы хотите сбросить все внесенные изменения?',
|
||||
acceptTitle: 'Да, сбросить',
|
||||
declineTitle: 'Нет, оставить',
|
||||
),
|
||||
);
|
||||
|
||||
if (res != null && res) context.back();
|
||||
} else {
|
||||
context.back();
|
||||
}
|
||||
},
|
||||
onPressed: _handleBackPress,
|
||||
icon: const Icon(CupertinoIcons.left_chevron, color: Colors.black),
|
||||
),
|
||||
centerTitle: true,
|
||||
@@ -429,35 +435,66 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
color: AppColors.body_text,
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
Wif(
|
||||
condition: widget.editedCollection != null,
|
||||
builder: (BuildContext context) {
|
||||
return Padding(
|
||||
actions: [
|
||||
if (widget.editedCollection != null && _hasChanges())
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16).r,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
showCuperModalBottomSheet(
|
||||
onTap: _showResetDialog,
|
||||
child: Assets.icons.typeTrash.image(
|
||||
height: 24.h,
|
||||
width: 24.w,
|
||||
color: AppColors.danger,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleBackPress() async {
|
||||
if (widget.editedCollection != null) {
|
||||
final shouldExit = await _showExitDialog();
|
||||
if (shouldExit == true) context.back();
|
||||
} else {
|
||||
context.back();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool?> _showExitDialog() async {
|
||||
// Показываем диалог только если есть редактируемая коллекция и есть изменения
|
||||
if (widget.editedCollection != null && _hasChanges()) {
|
||||
return showCuperModalBottomSheet<bool>(
|
||||
context: context,
|
||||
height: 262.h,
|
||||
builder:
|
||||
(BuildContext context) => const AlertInfoDialog(
|
||||
(_) => const AlertInfoDialog(
|
||||
title: 'Вы хотите сбросить все внесенные изменения?',
|
||||
acceptTitle: 'Да, сбросить',
|
||||
declineTitle: 'Нет, оставить',
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Assets.icons.typeTrash.image(
|
||||
height: 24.h,
|
||||
width: 24.w,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _hasChanges() {
|
||||
// Если нет редактируемой коллекции, значит это создание новой
|
||||
if (widget.editedCollection == null) return false;
|
||||
|
||||
// Сравниваем все поля
|
||||
return _collection.title != widget.editedCollection!.title ||
|
||||
_collection.desc != widget.editedCollection!.desc ||
|
||||
_collection.isPublic != widget.editedCollection!.isPublic ||
|
||||
_collection.avatar != widget.editedCollection!.image;
|
||||
}
|
||||
|
||||
void _showResetDialog() {
|
||||
_showExitDialog().then((result) {
|
||||
if (result == true) {
|
||||
_initializeCollection();
|
||||
safeSetState(() {});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
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) {
|
||||
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