From eee0282de0c32caf846a3476c87fa7e16f92806f Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 14 Aug 2024 13:09:15 +0300 Subject: [PATCH] =?UTF-8?q?feat(blogPostCreate):=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=B2=D0=B2=D0=BE=D0=B4=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=20=D0=B2=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=B5,=20=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=83=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8C=D1=88=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/blog_post_create_screen.dart | 128 +++++++++++------- .../bloc/blog_post_create_bloc.dart | 6 +- pubspec.yaml | 1 + 3 files changed, 83 insertions(+), 52 deletions(-) diff --git a/lib/features/blog_post_create/presentation/pages/blog_post_create_screen.dart b/lib/features/blog_post_create/presentation/pages/blog_post_create_screen.dart index eadcc00c..e1414dbe 100644 --- a/lib/features/blog_post_create/presentation/pages/blog_post_create_screen.dart +++ b/lib/features/blog_post_create/presentation/pages/blog_post_create_screen.dart @@ -1,8 +1,10 @@ +import 'dart:async'; import 'dart:io'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:image_picker/image_picker.dart'; import '../../../../presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart'; @@ -25,6 +27,27 @@ class BlogPostCreateScreen extends StatefulWidget { } class _BlogPostCreateScreenState extends State { + bool shrinkImage = false; + + late StreamSubscription keyboardSubscription; + + @override + void initState() { + super.initState(); + var keyboardVisibilityController = KeyboardVisibilityController(); + keyboardSubscription = keyboardVisibilityController.onChange.listen((bool visible) { + setState(() { + shrinkImage = visible; + }); + }); + } + + @override + void dispose() { + keyboardSubscription.cancel(); + super.dispose(); + } + Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { @@ -79,9 +102,9 @@ class _BlogPostCreateScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Изображение поста'), - SizedBox(height: 8), - _buildAddPhoto(context, state), + if (state.youtubeURL!.text.isEmpty) Text('Изображение поста'), + if (state.youtubeURL!.text.isEmpty) SizedBox(height: 8), + if (state.youtubeURL!.text.isEmpty) _buildAddPhoto(state), SizedBox(height: 16), Text('Заголовок'), SizedBox(height: 8), @@ -97,9 +120,9 @@ class _BlogPostCreateScreenState extends State { minLines: 1, ), SizedBox(height: 16), - Text('Ссылка на видео'), - SizedBox(height: 8), - CustomTextFormField( + if (state.image == null) Text('Ссылка на видео'), + if (state.image == null) SizedBox(height: 8), + if (state.image == null) CustomTextFormField( controller: state.youtubeURL, ), SizedBox(height: 80), @@ -108,55 +131,62 @@ class _BlogPostCreateScreenState extends State { ), ); } + + _buildAddPhoto(BlogPostCreateLoadedState state) { + bool isLoading = state.isLoading; + + return GestureDetector( + onTap: addImage(context, isLoading), + child: Stack( + children: [ + if (state.image == null) + AnimatedContainer( + height: shrinkImage ? 52 : 128, + curve: Curves.easeIn, + duration: Duration(milliseconds: 150), + decoration: AppDecoration.fillGray.copyWith( + borderRadius: BorderRadius.circular(16), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Icon( + Icons.photo_library, + color: appTheme.blueGray300, + ), + SizedBox(width: 8), + Text( + "Добавить фото", + selectionColor: appTheme.blueA400, + ), + ], + ), + ), + if (state.image != null) + AnimatedContainer( + width: shrinkImage ? 52 : MediaQuery.of(context).size.width - 32, + curve: Curves.easeIn, + duration: Duration(milliseconds: 150), + child: ClipRRect( + borderRadius: BorderRadius.circular(16), + child: Image( + image: FileImage( + File(state.image!.path), + ), + ), + ), + ), + ], + ), + ); + } } _submitForm(BuildContext context, String title, String description, String youtubeURL) async { context.read().add(CreateBlogPost()); } -_buildAddPhoto(BuildContext context, BlogPostCreateLoadedState state) { - bool isLoading = state.isLoading; - - return GestureDetector( - onTap: addImage(context, isLoading), - child: Stack( - children: [ - if (state.image == null) - Container( - height: 128, - decoration: AppDecoration.fillGray.copyWith( - borderRadius: BorderRadius.circular(16), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Icon( - Icons.photo_library, - color: appTheme.blueGray300, - ), - SizedBox(width: 8), - Text( - "Добавить фото", - selectionColor: appTheme.blueA400, - ), - ], - ), - ), - if (state.image != null) - ClipRRect( - borderRadius: BorderRadius.circular(16), - child: Image( - image: FileImage( - File(state.image!.path), - ), - ), - ) - ], - ), - ); -} - addImage(BuildContext context, bool isLoading) { if (!isLoading) { return () async { diff --git a/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart b/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart index fde96210..798b771c 100644 --- a/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart +++ b/lib/presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart @@ -81,9 +81,9 @@ class BlogPostCreateBloc extends Bloc String url = baseUrl + '/api/blogPosts/create'; FormData formData = FormData.fromMap({ - 'title': title ?? '', - 'description': description ?? '', - 'youtube_url': youtubeURL ?? '', + 'title': title, + 'description': description, + 'youtube_url': youtubeURL, 'state': 'active', 'image': await MultipartFile.fromFile(image!.path, filename: image.name), }); diff --git a/pubspec.yaml b/pubspec.yaml index 5939ba1c..612c9396 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,6 +47,7 @@ dependencies: location: ^7.0.0 syncfusion_flutter_charts: ^26.2.8 table_calendar: ^3.1.2 + flutter_keyboard_visibility: ^6.0.0 dev_dependencies: build_runner: ^2.4.11