136 lines
4.6 KiB
Dart
136 lines
4.6 KiB
Dart
import 'package:auto_route/auto_route.dart';
|
||
import 'package:flutter/cupertino.dart';
|
||
import 'package:remever/common/functions.dart';
|
||
import 'package:remever/common/resources.dart';
|
||
import 'package:remever/common/widgets/bottom_safe_space.dart';
|
||
import 'package:remever/components/extensions/context.dart';
|
||
import 'package:remever/database/database.dart';
|
||
import 'package:remever/gen/assets.gen.dart';
|
||
import 'package:remever/inject.dart';
|
||
import 'package:remever/router.gr.dart';
|
||
import 'package:remever/screens/dialogs/alert_dialog.dart';
|
||
import 'package:remever/screens/dialogs/dialog_header.dart';
|
||
import 'package:remever/screens/dialogs/dialog_item.dart';
|
||
import 'package:remever/services/collection/collections_interface.dart';
|
||
import 'package:share_plus/share_plus.dart';
|
||
|
||
class ActionDialog extends StatelessWidget {
|
||
const ActionDialog({super.key, required this.collection});
|
||
|
||
final Collection collection;
|
||
|
||
void _onTrainingTap(BuildContext context) {
|
||
showInfoToast('Все скоро будет. Рим не сразу строился');
|
||
|
||
Navigator.pop(context);
|
||
}
|
||
|
||
void _onEditTap(BuildContext context) {
|
||
Navigator.pop(context);
|
||
context.pushRoute(CrudCollectionRoute(editedCollection: collection));
|
||
}
|
||
|
||
void _onStatistickTap(BuildContext context) {
|
||
showInfoToast('Ты серьезно?');
|
||
Navigator.pop(context);
|
||
}
|
||
|
||
void _onDownloadTap(BuildContext context) {
|
||
showInfoToast('Ты серьезно?');
|
||
Navigator.pop(context);
|
||
}
|
||
|
||
void _onShareTap(BuildContext context) async {
|
||
await Share.share('View my collection ${collection.id}');
|
||
}
|
||
|
||
void _onDeleteTap(BuildContext context) async {
|
||
final bool? res = await showCuperModalBottomSheet(
|
||
context: context,
|
||
height: 262.h,
|
||
builder:
|
||
(BuildContext context) => const AlertInfoDialog(
|
||
title: 'Вы хотите удалить коллекцию?\nЭто действие необратимо',
|
||
acceptTitle: 'Да, удалить',
|
||
declineTitle: 'Нет, оставить',
|
||
),
|
||
);
|
||
|
||
if (res != null && res) {
|
||
await getIt<CollectionsInterface>().deleteCollection(collection.id);
|
||
|
||
Navigator.pop(context);
|
||
}
|
||
}
|
||
|
||
void _makePublic(BuildContext context, bool public) {
|
||
if (!public) {
|
||
showCuperModalBottomSheet(
|
||
context: context,
|
||
height: 282.h,
|
||
builder:
|
||
(BuildContext context) => const AlertInfoDialog(
|
||
title:
|
||
'Коллекция станет видна всем пользователям сервиса.\nЕё будет проще найти по тэгам ;)',
|
||
acceptTitle: 'Позже добавлю',
|
||
declineTitle: 'Добавить тэги',
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Column(
|
||
children: <Widget>[
|
||
const DialogHeader(title: 'Действия'),
|
||
DialogItem(
|
||
title: 'Публичная коллекция',
|
||
dimension: 36,
|
||
child: FittedBox(
|
||
fit: BoxFit.contain,
|
||
child: CupertinoSwitch(
|
||
activeTrackColor: AppColors.primary,
|
||
value: collection.isPublic,
|
||
onChanged: (bool value) => _makePublic(context, value),
|
||
),
|
||
),
|
||
onTap: () => _makePublic(context, collection.isPublic),
|
||
),
|
||
DialogItem(
|
||
title: 'Исключена из тренировки',
|
||
child: Assets.icons.typeHide.image(color: AppColors.primary),
|
||
onTap: () => _onTrainingTap(context),
|
||
),
|
||
DialogItem(
|
||
title: 'Редактировать',
|
||
child: Assets.icons.typeEdit.image(color: AppColors.primary),
|
||
onTap: () => _onEditTap(context),
|
||
),
|
||
DialogItem(
|
||
title: 'Статистика',
|
||
child: Assets.icons.typeStat.image(color: AppColors.primary),
|
||
onTap: () => _onStatistickTap(context),
|
||
),
|
||
DialogItem(
|
||
title: 'Скачать',
|
||
child: Assets.icons.typeDownload.image(color: AppColors.primary),
|
||
onTap: () => _onDownloadTap(context),
|
||
),
|
||
DialogItem(
|
||
title: 'Поделиться',
|
||
child: Assets.icons.typeShare.image(color: AppColors.primary),
|
||
onTap: () => _onShareTap(context),
|
||
),
|
||
DialogItem(
|
||
title: 'Удалить',
|
||
color: AppColors.danger,
|
||
onTap: () => _onDeleteTap(context),
|
||
child: Assets.icons.typeTrash.image(color: AppColors.danger),
|
||
),
|
||
const BottomSafeSpace(),
|
||
],
|
||
);
|
||
}
|
||
}
|