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