Добавлено удаление коллекций

This commit is contained in:
2025-03-25 21:36:00 +03:00
parent 94193658f1
commit 5892830499
380 changed files with 142 additions and 4057 deletions

View File

@@ -30,4 +30,23 @@ class CollectionsDao extends DatabaseAccessor<AppDatabase>
),
);
}
/// Обновление коллекции
Future<void> updateCollection(CollectionDto dto, String id) async {
await db.managers.collections
.filter((f) => f.id(id))
.update(
(o) => o(
title: Value<String>(dto.title),
desc: Value<String>(dto.desc),
isPublic: Value<bool>(dto.isPublic),
image: Value<String?>(dto.avatar),
),
);
}
/// Удаление коллекции
Future<void> deleteCollection(String id) async {
await db.managers.collections.filter((f) => f.id(id)).delete();
}
}

View File

@@ -6,7 +6,7 @@
/// Locales: 2
/// Strings: 20 (10 per locale)
///
/// Built on 2025-03-25 at 14:49 UTC
/// Built on 2025-03-25 at 18:21 UTC
// coverage:ignore-file
// ignore_for_file: type=lint, unused_import

View File

@@ -11,6 +11,7 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:auto_route/auto_route.dart' as _i12;
import 'package:flutter/cupertino.dart' as _i13;
import 'package:remever/database/database.dart' as _i14;
import 'package:remever/screens/auth/auth_screen.dart' as _i1;
import 'package:remever/screens/collections/collection_detail_screen.dart'
as _i2;
@@ -165,11 +166,14 @@ class CrudCollectionFullscreenFieldArgs {
class CrudCollectionRoute extends _i12.PageRouteInfo<CrudCollectionRouteArgs> {
CrudCollectionRoute({
_i13.Key? key,
_i6.CrudType crudType = _i6.CrudType.CREATE,
_i14.Collection? editedCollection,
List<_i12.PageRouteInfo>? children,
}) : super(
CrudCollectionRoute.name,
args: CrudCollectionRouteArgs(key: key, crudType: crudType),
args: CrudCollectionRouteArgs(
key: key,
editedCollection: editedCollection,
),
initialChildren: children,
);
@@ -181,24 +185,24 @@ class CrudCollectionRoute extends _i12.PageRouteInfo<CrudCollectionRouteArgs> {
final args = data.argsAs<CrudCollectionRouteArgs>(
orElse: () => const CrudCollectionRouteArgs(),
);
return _i6.CrudCollectionScreen(key: args.key, crudType: args.crudType);
return _i6.CrudCollectionScreen(
key: args.key,
editedCollection: args.editedCollection,
);
},
);
}
class CrudCollectionRouteArgs {
const CrudCollectionRouteArgs({
this.key,
this.crudType = _i6.CrudType.CREATE,
});
const CrudCollectionRouteArgs({this.key, this.editedCollection});
final _i13.Key? key;
final _i6.CrudType crudType;
final _i14.Collection? editedCollection;
@override
String toString() {
return 'CrudCollectionRouteArgs{key: $key, crudType: $crudType}';
return 'CrudCollectionRouteArgs{key: $key, editedCollection: $editedCollection}';
}
}

View File

@@ -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();

View File

@@ -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()),
),
),
);
}
///

View File

@@ -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,

View File

@@ -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),
),

View File

@@ -6,8 +6,13 @@ import 'package:remever/models/collection_dto.dart';
///
abstract interface class CollectionsInterface {
/// Получение списка коллекций
Stream<List<Collection>> getCollectionsList();
Stream<List<Collection>> watchCollectionsList();
/// Создание новой коллекции
Future<void> createCollection(CollectionDto dto);
Future<void> updateCollection(CollectionDto dto, String id);
Future<void> deleteCollection(String id);
/// Сделать коллекцию публичной
Future<bool> makeCollectionPublic(String id, bool isPublic);
}

View File

@@ -11,7 +11,7 @@ import 'package:remever/services/collection/collections_interface.dart';
@Singleton(as: CollectionsInterface)
final class CollectionsService implements CollectionsInterface {
@override
Stream<List<Collection>> getCollectionsList() {
Stream<List<Collection>> watchCollectionsList() {
return getIt<AppDatabase>().collectionsDao.getCollections();
}
@@ -19,4 +19,20 @@ final class CollectionsService implements CollectionsInterface {
Future<void> createCollection(CollectionDto dto) async {
return await getIt<AppDatabase>().collectionsDao.createCollection(dto);
}
@override
Future<void> updateCollection(CollectionDto dto, String id) async {
return await getIt<AppDatabase>().collectionsDao.updateCollection(dto, id);
}
@override
Future<void> deleteCollection(String id) async {
return await getIt<AppDatabase>().collectionsDao.deleteCollection(id);
}
@override
Future<bool> makeCollectionPublic(String id, bool isPublic) {
// TODO: implement makeCollectionPublic
throw UnimplementedError();
}
}