From bef9f2e4e9694903f184f55c33661c35f88ec145 Mon Sep 17 00:00:00 2001 From: AhsanRns Date: Thu, 9 May 2024 14:14:57 +0500 Subject: [PATCH] feat: thumbnail validation --- evently/i18n/de.json | 3 +- evently/i18n/en-US.json | 3 +- evently/i18n/es.json | 3 +- evently/i18n/ru-RU.json | 3 +- evently/lib/generated/locale_keys.g.dart | 1 + evently/lib/screens/overview_screen.dart | 107 +++++++++++++++-------- 6 files changed, 80 insertions(+), 40 deletions(-) diff --git a/evently/i18n/de.json b/evently/i18n/de.json index 87f0e82879..e1a203b9b1 100644 --- a/evently/i18n/de.json +++ b/evently/i18n/de.json @@ -46,5 +46,6 @@ "enter_event_name": "Enter event name", "event_name_remaining_characters": "Event name should have {} characters or more", "enter_host_name": "Enter host name", - "host_name_remaining_characters": "Host name should have {} characters or more" + "host_name_remaining_characters": "Host name should have {} characters or more", + "please_select_thumbnail" : "please select thumbnail" } \ No newline at end of file diff --git a/evently/i18n/en-US.json b/evently/i18n/en-US.json index 87f0e82879..e1a203b9b1 100644 --- a/evently/i18n/en-US.json +++ b/evently/i18n/en-US.json @@ -46,5 +46,6 @@ "enter_event_name": "Enter event name", "event_name_remaining_characters": "Event name should have {} characters or more", "enter_host_name": "Enter host name", - "host_name_remaining_characters": "Host name should have {} characters or more" + "host_name_remaining_characters": "Host name should have {} characters or more", + "please_select_thumbnail" : "please select thumbnail" } \ No newline at end of file diff --git a/evently/i18n/es.json b/evently/i18n/es.json index 87f0e82879..e1a203b9b1 100644 --- a/evently/i18n/es.json +++ b/evently/i18n/es.json @@ -46,5 +46,6 @@ "enter_event_name": "Enter event name", "event_name_remaining_characters": "Event name should have {} characters or more", "enter_host_name": "Enter host name", - "host_name_remaining_characters": "Host name should have {} characters or more" + "host_name_remaining_characters": "Host name should have {} characters or more", + "please_select_thumbnail" : "please select thumbnail" } \ No newline at end of file diff --git a/evently/i18n/ru-RU.json b/evently/i18n/ru-RU.json index 87f0e82879..e1a203b9b1 100644 --- a/evently/i18n/ru-RU.json +++ b/evently/i18n/ru-RU.json @@ -46,5 +46,6 @@ "enter_event_name": "Enter event name", "event_name_remaining_characters": "Event name should have {} characters or more", "enter_host_name": "Enter host name", - "host_name_remaining_characters": "Host name should have {} characters or more" + "host_name_remaining_characters": "Host name should have {} characters or more", + "please_select_thumbnail" : "please select thumbnail" } \ No newline at end of file diff --git a/evently/lib/generated/locale_keys.g.dart b/evently/lib/generated/locale_keys.g.dart index be6426954b..002f02322a 100644 --- a/evently/lib/generated/locale_keys.g.dart +++ b/evently/lib/generated/locale_keys.g.dart @@ -49,5 +49,6 @@ abstract class LocaleKeys { static const event_name_remaining_characters = 'event_name_remaining_characters'; static const enter_host_name = 'enter_host_name'; static const host_name_remaining_characters = 'host_name_remaining_characters'; + static const please_select_thumbnail = 'please_select_thumbnail'; } diff --git a/evently/lib/screens/overview_screen.dart b/evently/lib/screens/overview_screen.dart index 3c3a389b95..f580b0dd5f 100644 --- a/evently/lib/screens/overview_screen.dart +++ b/evently/lib/screens/overview_screen.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:dotted_border/dotted_border.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:evently/evently_provider.dart'; @@ -10,6 +12,7 @@ import 'package:evently/utils/space_utils.dart'; import 'package:evently/viewmodels/create_event_viewmodel.dart'; import 'package:evently/widgets/clipped_button.dart'; import 'package:evently/widgets/evently_text_field.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -26,6 +29,7 @@ class _OverViewScreenState extends State { final _formKey = GlobalKey(); final ValueNotifier _eventNameFieldError = ValueNotifier(""); final ValueNotifier _hostNameFieldError = ValueNotifier(""); + final ValueNotifier _thumbnailError = ValueNotifier(""); @override void initState() { @@ -163,45 +167,76 @@ class _OverViewScreenState extends State { style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w700), ), VerticalSpace(10.h), - ClipRRect( - borderRadius: BorderRadius.only(topRight: Radius.circular(8.r), topLeft: Radius.circular(8.r)), - child: Center( - child: DottedBorder( - borderType: BorderType.Rect, - dashPattern: const [10, 6], - color: EventlyAppTheme.kLightPurple, - strokeWidth: 3.h, - child: provider.thumbnail != null - ? Stack( - children: [ - Image.file(provider.thumbnail!), - SvgPicture.asset(SVGUtils.kSvgUpload), - ], - ) - : GestureDetector( - onTap: () => provider.pickThumbnail(), - child: Container( - width: double.infinity, - padding: EdgeInsets.symmetric(vertical: 20.w), - child: Column( + FormField( + validator: (_) { + if (provider.thumbnail == null) { + _thumbnailError.value = LocaleKeys.please_select_thumbnail.tr(); + return; + } + _thumbnailError.value = ''; + return null; + }, + builder: (FormFieldState field) { + return ClipRRect( + borderRadius: BorderRadius.only(topRight: Radius.circular(8.r), topLeft: Radius.circular(8.r)), + child: Center( + child: DottedBorder( + borderType: BorderType.Rect, + dashPattern: const [10, 6], + color: EventlyAppTheme.kLightPurple, + strokeWidth: 3.h, + child: provider.thumbnail != null + ? Stack( + alignment: Alignment.center, children: [ - Text( - LocaleKeys.tap_select.tr(), - style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold, color: EventlyAppTheme.kLightPurple), - ), - VerticalSpace(10.h), - SvgPicture.asset(SVGUtils.kSvgUpload), - VerticalSpace(10.h), - Text( - LocaleKeys.mb_limit.tr(), - style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold, color: EventlyAppTheme.kLightPurple), - ), + Image.file(provider.thumbnail!), + GestureDetector(onTap: () => provider.pickThumbnail(), child: SvgPicture.asset(SVGUtils.kSvgUpload)), ], + ) + : GestureDetector( + onTap: () => provider.pickThumbnail(), + child: Container( + width: double.infinity, + padding: EdgeInsets.symmetric(vertical: 20.w), + child: Column( + children: [ + Text( + LocaleKeys.tap_select.tr(), + style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold, color: EventlyAppTheme.kLightPurple), + ), + VerticalSpace(10.h), + SvgPicture.asset(SVGUtils.kSvgUpload), + VerticalSpace(10.h), + Text( + LocaleKeys.mb_limit.tr(), + style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold, color: EventlyAppTheme.kLightPurple), + ), + ], + ), + ), ), - ), - ), - ), - ), + ), + ), + ); + }, + ), + ValueListenableBuilder( + valueListenable: _thumbnailError, + builder: (_, String thumbnailError, __) { + if (thumbnailError.isEmpty) { + return const SizedBox.shrink(); + } + return Padding( + padding: EdgeInsets.only(left: 10.w, right: 10.w, top: 2.h), + child: Text( + thumbnailError, + style: TextStyle( + fontSize: 12.sp, + color: Colors.red, + ), + ), + ); + }, ), VerticalSpace(20.h), ClippedButton(