Пачка экранов и логики #3
@@ -10,7 +10,6 @@ import 'package:remever/components/extensions/context.dart';
|
||||
import 'package:remever/components/extensions/state.dart';
|
||||
import 'package:remever/database/database.dart';
|
||||
import 'package:remever/gen/assets.gen.dart';
|
||||
import 'package:remever/i18n/strings.g.dart';
|
||||
import 'package:remever/inject.dart';
|
||||
import 'package:remever/router.gr.dart';
|
||||
import 'package:remever/screens/collections/widgets/collection_progress_bar.dart';
|
||||
@@ -18,6 +17,7 @@ import 'package:remever/screens/dialogs/dialog_header.dart';
|
||||
import 'package:remever/services/tickets/tickets_interface.dart';
|
||||
import 'package:remever/widgets/primary_button.dart';
|
||||
|
||||
/// Диалог для переноса карточки в другую коллекцию
|
||||
class ReplaceDialog extends StatefulWidget {
|
||||
const ReplaceDialog({
|
||||
super.key,
|
||||
@@ -33,8 +33,10 @@ class ReplaceDialog extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
/// Коллекция, в которую будет перенесена карточка
|
||||
Collection? _collectionToTransfer;
|
||||
|
||||
/// Обработчик выбора коллекции
|
||||
void _onCollectionTap() {
|
||||
context.pushRoute(
|
||||
CollectionSearchRoute(
|
||||
@@ -45,23 +47,29 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
void _onTransferTap() async {
|
||||
/// Обработчик кнопки "Перенести"
|
||||
Future<void> _onTransferTap() async {
|
||||
// Проверяем, что выбрана коллекция для переноса
|
||||
if (_collectionToTransfer == null) {
|
||||
showErrorToast('Необходимо выбрать место для переноса');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверяем, что выбранная коллекция не совпадает с текущей
|
||||
if (_collectionToTransfer!.id == widget.currentCollection.id) {
|
||||
showErrorToast('Карточка итак в этой коллекции, выберете другую');
|
||||
showErrorToast(
|
||||
'Карточка уже находится в этой коллекции, выберите другую',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Переносим карточку через сервис
|
||||
await getIt<TicketsInterface>().transferTicket(
|
||||
widget.ticket.id,
|
||||
_collectionToTransfer!.id,
|
||||
);
|
||||
|
||||
// Закрываем диалог
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
@@ -70,41 +78,25 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
return Material(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
const DialogHeader(title: 'Переместить карточку'),
|
||||
const HSpace(16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28).r,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
AppTypography('из коллекции', type: Medium16px()),
|
||||
const HSpace(8),
|
||||
_buildCollection(widget.currentCollection),
|
||||
const HSpace(16),
|
||||
Center(
|
||||
child: SizedBox.square(
|
||||
dimension: 34.r,
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.gray,
|
||||
),
|
||||
child: Center(
|
||||
child: Assets.icons.typeArrowDown.image(
|
||||
height: 18.h,
|
||||
width: 18.w,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildArrowIcon(),
|
||||
const HSpace(16),
|
||||
AppTypography('в коллекцию', type: Medium16px()),
|
||||
const HSpace(8),
|
||||
_buildCollection(_collectionToTransfer, isSelectable: true),
|
||||
const HSpace(16),
|
||||
_buildTransferButton(context),
|
||||
_buildTransferButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -113,20 +105,40 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTransferButton(BuildContext context) {
|
||||
/// Кнопка "Перенести"
|
||||
Widget _buildTransferButton() {
|
||||
return PrimaryButton(
|
||||
onTap: _onTransferTap,
|
||||
child: AppTypography(
|
||||
'Перенести',
|
||||
type: Regular14px(),
|
||||
color: AppColors.white,
|
||||
),
|
||||
onTap: () => _onTransferTap(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Иконка стрелки между коллекциями
|
||||
Widget _buildArrowIcon() {
|
||||
return Center(
|
||||
child: SizedBox.square(
|
||||
dimension: 34.r,
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.gray,
|
||||
),
|
||||
child: Center(
|
||||
child: Assets.icons.typeArrowDown.image(height: 18.h, width: 18.w),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Виджет отображения коллекции
|
||||
Widget _buildCollection(Collection? collection, {bool isSelectable = false}) {
|
||||
return GestureDetector(
|
||||
onTap: isSelectable ? () => _onCollectionTap() : null,
|
||||
onTap: isSelectable ? _onCollectionTap : null,
|
||||
child: Container(
|
||||
constraints: BoxConstraints(minHeight: 66.h, maxHeight: 84.h),
|
||||
decoration: BoxDecoration(
|
||||
@@ -143,7 +155,7 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
children: <Widget>[
|
||||
children: [
|
||||
_buildAvatar(collection),
|
||||
const WSpace(5),
|
||||
_buildInfo(collection),
|
||||
@@ -153,16 +165,14 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
/// Построение основной информации
|
||||
///
|
||||
/// Информация о коллекции
|
||||
Widget _buildInfo(Collection collection) {
|
||||
return SizedBox(
|
||||
width: 230.w,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
children: [
|
||||
_buildTitle(collection),
|
||||
const HSpace(4),
|
||||
Row(
|
||||
@@ -174,7 +184,7 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
),
|
||||
const WSpace(2),
|
||||
AppTypography(
|
||||
'${collection.likesCount.toString()} ${Utils.declOfNum(collection.likesCount, ['карточек', 'карточки', 'карточек'])}',
|
||||
'${collection.likesCount} ${Utils.declOfNum(collection.likesCount, ['карточек', 'карточки', 'карточек'])}',
|
||||
type: Regular14px(),
|
||||
color: AppColors.disabled,
|
||||
),
|
||||
@@ -187,9 +197,7 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
/// Название коллекции
|
||||
///
|
||||
Widget _buildTitle(Collection collection) {
|
||||
return AppTypography(
|
||||
collection.title,
|
||||
@@ -199,9 +207,7 @@ class _ReplaceDialogState extends State<ReplaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
/// Обложка коллекции
|
||||
///
|
||||
Widget _buildAvatar(Collection collection) {
|
||||
return SizedBox.square(
|
||||
dimension: 50.r,
|
||||
|
||||
Reference in New Issue
Block a user