Создание коллекций
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:remever/common/functions.dart';
|
||||
import 'package:remever/common/resources.dart';
|
||||
import 'package:remever/common/toast.dart';
|
||||
import 'package:remever/common/widgets/bottom_safe_space.dart';
|
||||
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/gen/assets.gen.dart';
|
||||
import 'package:remever/inject.dart';
|
||||
import 'package:remever/models/collection_dto.dart';
|
||||
import 'package:remever/router.gr.dart';
|
||||
import 'package:remever/screens/crud_collection/widgets/crud_collection_field.dart';
|
||||
import 'package:remever/screens/dialogs/alert_dialog.dart';
|
||||
import 'package:remever/screens/dialogs/tags_dialog.dart';
|
||||
import 'package:remever/services/collection/collections_interface.dart';
|
||||
import 'package:remever/widgets/primary_button.dart';
|
||||
|
||||
import '../../../components/extensions/state.dart';
|
||||
@@ -34,11 +40,49 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
/// Флаг публичности коллекции
|
||||
bool _isPublic = false;
|
||||
|
||||
CollectionDto? _collection;
|
||||
|
||||
/// Смена публичности
|
||||
void _setPublic(bool public) {
|
||||
_collection = _collection?.copyWith(isPublic: public);
|
||||
safeSetState(() => _isPublic = public);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_collection = CollectionDto(desc: '', title: '', isPublic: false);
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void _pickImage() async {
|
||||
final result = await FilePicker.platform.pickFiles();
|
||||
|
||||
if (result == null || result.files.isEmpty) {
|
||||
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: base64String);
|
||||
|
||||
safeSetState(() {});
|
||||
|
||||
print('Base64 строка: $base64String');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -88,16 +132,18 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
Widget _buildCreateBtn(BuildContext context) {
|
||||
return PrimaryButton(
|
||||
height: 52,
|
||||
onTap: () {
|
||||
if (true) {
|
||||
Toast.showDismissible(
|
||||
onTap: () async {
|
||||
if (_collection!.desc.isEmpty && _collection!.title.isEmpty) {
|
||||
showErrorToast(
|
||||
'Для создания публичной коллекции добавьте описание и тэги',
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// context.read<HomeCubit>().toCollection();
|
||||
getIt<CollectionsInterface>().createCollection(_collection!);
|
||||
|
||||
context.back();
|
||||
},
|
||||
color: AppColors.primary,
|
||||
child: AppTypography(
|
||||
@@ -238,9 +284,19 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
height: 110,
|
||||
width: 348,
|
||||
hint: 'Добавить описание',
|
||||
content: _collection?.desc,
|
||||
onTap: () {
|
||||
context.pushRoute(
|
||||
CrudCollectionFullscreenField(title: 'Описание', height: 333),
|
||||
CrudCollectionFullscreenField(
|
||||
title: 'Описание',
|
||||
height: 333,
|
||||
content: _collection?.desc,
|
||||
onEditingComplete: (res) {
|
||||
safeSetState(
|
||||
() => _collection = _collection?.copyWith(desc: res ?? ''),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -265,11 +321,18 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
height: 91,
|
||||
width: 225,
|
||||
hint: 'Добавить название',
|
||||
content: _collection?.title,
|
||||
onTap: () {
|
||||
context.pushRoute(
|
||||
CrudCollectionFullscreenField(
|
||||
title: 'Название',
|
||||
hint: 'Максимальное количество символов - 250',
|
||||
content: _collection?.title,
|
||||
onEditingComplete: (res) {
|
||||
safeSetState(
|
||||
() => _collection = _collection?.copyWith(title: res ?? ''),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -280,26 +343,40 @@ class _CrudCollectionScreenState extends State<CrudCollectionScreen> {
|
||||
|
||||
/// Построение обложки
|
||||
Widget _buildPhoto() {
|
||||
return SizedBox.square(
|
||||
dimension: 115.r,
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: <Color>[Color(0xFFB6AAFE), Color(0xFFDBD7F4)],
|
||||
begin: Alignment.bottomLeft,
|
||||
end: Alignment.topRight,
|
||||
),
|
||||
),
|
||||
child: SizedBox.square(
|
||||
dimension: 32.r,
|
||||
child: Center(
|
||||
child: Assets.icons.typePhoto.image(
|
||||
height: 32.h,
|
||||
width: 32.w,
|
||||
color: AppColors.primary,
|
||||
return GestureDetector(
|
||||
onTap: () => _pickImage(),
|
||||
child: SizedBox.square(
|
||||
dimension: 115.r,
|
||||
child: DecoratedBox(
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: <Color>[Color(0xFFB6AAFE), Color(0xFFDBD7F4)],
|
||||
begin: Alignment.bottomLeft,
|
||||
end: Alignment.topRight,
|
||||
),
|
||||
),
|
||||
child: Wif(
|
||||
condition: _collection!.avatar != null,
|
||||
builder:
|
||||
(context) => ClipOval(
|
||||
child: Image.memory(
|
||||
base64Decode(_collection!.avatar!),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
fallback:
|
||||
(context) => SizedBox.square(
|
||||
dimension: 32.r,
|
||||
child: Center(
|
||||
child: Assets.icons.typePhoto.image(
|
||||
height: 32.h,
|
||||
width: 32.w,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user