Добавлено удаление коллекций
This commit is contained in:
@@ -77,7 +77,7 @@ class _CollectionScreenState extends State<CollectionScreen> {
|
||||
const CollectionsFilters(),
|
||||
Expanded(
|
||||
child: StreamBuilder<List<Collection>>(
|
||||
stream: getIt<CollectionsInterface>().getCollectionsList(),
|
||||
stream: getIt<CollectionsInterface>().watchCollectionsList(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const _LoadingList();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -77,7 +76,9 @@ class CollectionCard extends StatelessWidget {
|
||||
showCuperModalBottomSheet(
|
||||
context: context,
|
||||
height: 477.h,
|
||||
builder: (BuildContext context) => const ActionDialog(),
|
||||
builder:
|
||||
(BuildContext context) =>
|
||||
ActionDialog(collection: collection),
|
||||
);
|
||||
},
|
||||
child: Assets.icons.typeMenuVertical.image(
|
||||
@@ -176,16 +177,6 @@ class CollectionCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return SizedBox.square(
|
||||
dimension: 50.r,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
image: DecorationImage(image: Assets.images.img.provider()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
@@ -12,6 +12,7 @@ import 'package:remever/common/widgets/typography.dart';
|
||||
import 'package:remever/common/widgets/w_if.dart';
|
||||
import 'package:remever/common/widgets/wspace.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/models/collection_dto.dart';
|
||||
@@ -24,13 +25,11 @@ import 'package:remever/widgets/primary_button.dart';
|
||||
|
||||
import '../../../components/extensions/state.dart';
|
||||
|
||||
enum CrudType { CREATE, EDIT }
|
||||
|
||||
@RoutePage()
|
||||
class CrudCollectionScreen extends StatefulWidget {
|
||||
const CrudCollectionScreen({super.key, this.crudType = CrudType.CREATE});
|
||||
const CrudCollectionScreen({super.key, this.editedCollection});
|
||||
|
||||
final CrudType crudType;
|
||||
final Collection? editedCollection;
|
||||
|
||||
@override
|
||||
State<CrudCollectionScreen> createState() => _CrudCollectionScreenState();
|
||||
@@ -50,7 +49,12 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_collection = CollectionDto(desc: '', title: '', isPublic: false);
|
||||
_collection = CollectionDto(
|
||||
desc: widget.editedCollection?.desc ?? '',
|
||||
title: widget.editedCollection?.title ?? '',
|
||||
isPublic: widget.editedCollection?.isPublic ?? false,
|
||||
avatar: widget.editedCollection?.image,
|
||||
);
|
||||
|
||||
super.initState();
|
||||
}
|
||||
@@ -79,8 +83,6 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
_collection = _collection?.copyWith(avatar: base64String);
|
||||
|
||||
safeSetState(() {});
|
||||
|
||||
print('Base64 строка: $base64String');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -108,7 +110,8 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
_buildPublickSwitch(),
|
||||
const HSpace(16),
|
||||
AnimatedOpacity(
|
||||
opacity: _isPublic ? 1 : 0,
|
||||
// opacity: _isPublic ? 1 : 0,
|
||||
opacity: 0,
|
||||
duration: const Duration(seconds: 1),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -141,13 +144,20 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
getIt<CollectionsInterface>().createCollection(_collection!);
|
||||
widget.editedCollection != null
|
||||
? await getIt<CollectionsInterface>().updateCollection(
|
||||
_collection!,
|
||||
widget.editedCollection!.id,
|
||||
)
|
||||
: await getIt<CollectionsInterface>().createCollection(
|
||||
_collection!,
|
||||
);
|
||||
|
||||
context.back();
|
||||
},
|
||||
color: AppColors.primary,
|
||||
child: AppTypography(
|
||||
widget.crudType == CrudType.CREATE
|
||||
widget.editedCollection == null
|
||||
? 'Создать коллекцию'
|
||||
: 'Сохранить изменения',
|
||||
type: Regular14px(),
|
||||
@@ -390,7 +400,7 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
shadowColor: Colors.transparent,
|
||||
leading: IconButton(
|
||||
onPressed: () async {
|
||||
if (widget.crudType == CrudType.EDIT) {
|
||||
if (widget.editedCollection != null) {
|
||||
final bool? res = await showCuperModalBottomSheet(
|
||||
context: context,
|
||||
height: 262.h,
|
||||
@@ -413,7 +423,7 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
title: GestureDetector(
|
||||
onLongPress: () => context.pushRoute(const SandboxRoute()),
|
||||
child: AppTypography(
|
||||
widget.crudType == CrudType.CREATE
|
||||
widget.editedCollection == null
|
||||
? 'Создать коллекцию'
|
||||
: 'Редактировать',
|
||||
type: SemiBold20px(),
|
||||
@@ -422,7 +432,7 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
),
|
||||
actions: <Widget>[
|
||||
Wif(
|
||||
condition: widget.crudType == CrudType.EDIT,
|
||||
condition: widget.editedCollection != null,
|
||||
builder: (BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 16).r,
|
||||
|
||||
@@ -5,15 +5,36 @@ 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/crud_collection/crud_collection.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';
|
||||
|
||||
class ActionDialog extends StatelessWidget {
|
||||
const ActionDialog({super.key});
|
||||
const ActionDialog({super.key, required this.collection});
|
||||
|
||||
final Collection collection;
|
||||
|
||||
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) {
|
||||
@@ -27,23 +48,11 @@ class ActionDialog extends StatelessWidget {
|
||||
fit: BoxFit.contain,
|
||||
child: CupertinoSwitch(
|
||||
activeTrackColor: AppColors.primary,
|
||||
value: true,
|
||||
onChanged: (bool value) {},
|
||||
value: collection.isPublic,
|
||||
onChanged: (bool value) => _makePublic(context, value),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
showCuperModalBottomSheet(
|
||||
context: context,
|
||||
height: 282.h,
|
||||
builder:
|
||||
(BuildContext context) => const AlertInfoDialog(
|
||||
title:
|
||||
'Коллекция станет видна всем пользователям сервиса.\nЕё будет проще найти по тэгам ;)',
|
||||
acceptTitle: 'Позже добавлю',
|
||||
declineTitle: 'Добавить тэги',
|
||||
),
|
||||
);
|
||||
},
|
||||
onTap: () => _makePublic(context, collection.isPublic),
|
||||
),
|
||||
DialogItem(
|
||||
title: 'Исключена из тренировки',
|
||||
@@ -57,7 +66,9 @@ class ActionDialog extends StatelessWidget {
|
||||
child: Assets.icons.typeEdit.image(color: AppColors.primary),
|
||||
onTap: () {
|
||||
// context.back();
|
||||
context.pushRoute(CrudCollectionRoute(crudType: CrudType.EDIT));
|
||||
context.pushRoute(
|
||||
CrudCollectionRoute(editedCollection: collection),
|
||||
);
|
||||
},
|
||||
),
|
||||
DialogItem(
|
||||
@@ -84,8 +95,8 @@ class ActionDialog extends StatelessWidget {
|
||||
DialogItem(
|
||||
title: 'Удалить',
|
||||
color: AppColors.danger,
|
||||
onTap: () {
|
||||
showCuperModalBottomSheet(
|
||||
onTap: () async {
|
||||
final bool? res = await showCuperModalBottomSheet(
|
||||
context: context,
|
||||
height: 262.h,
|
||||
builder:
|
||||
@@ -96,6 +107,14 @@ class ActionDialog extends StatelessWidget {
|
||||
declineTitle: 'Нет, оставить',
|
||||
),
|
||||
);
|
||||
|
||||
if (true) {
|
||||
await getIt<CollectionsInterface>().deleteCollection(
|
||||
collection.id,
|
||||
);
|
||||
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
child: Assets.icons.typeTrash.image(color: AppColors.danger),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user