mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
added validation for community name
This commit is contained in:
@ -1,37 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class CreateCommunityDialog extends StatefulWidget {
|
||||
final Function(String name, String description) onCreateCommunity;
|
||||
final List<CommunityModel> communities;
|
||||
|
||||
const CreateCommunityDialog({super.key, required this.onCreateCommunity});
|
||||
const CreateCommunityDialog(
|
||||
{super.key, required this.onCreateCommunity, required this.communities});
|
||||
|
||||
@override
|
||||
CreateCommunityDialogState createState() => CreateCommunityDialogState();
|
||||
}
|
||||
|
||||
class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
||||
String enteredName = ''; // Store the entered community name
|
||||
String enteredName = '';
|
||||
bool isNameFieldExist = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
backgroundColor: Colors.transparent, // Transparent for shadow effect
|
||||
backgroundColor:
|
||||
ColorsManager.transparentColor, // Transparent for shadow effect
|
||||
child: Stack(
|
||||
children: [
|
||||
// Background container with shadow and rounded corners
|
||||
Container(
|
||||
width: 490,
|
||||
width: screenWidth * 0.3,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
color: ColorsManager.whiteColors,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.25),
|
||||
color: ColorsManager.blackColor.withOpacity(0.25),
|
||||
blurRadius: 20,
|
||||
spreadRadius: 5,
|
||||
offset: const Offset(0, 5),
|
||||
@ -53,10 +62,15 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
||||
// Input field for the community name
|
||||
TextField(
|
||||
onChanged: (value) {
|
||||
enteredName = value; // Capture entered name
|
||||
setState(() {
|
||||
enteredName = value.trim(); // Trim whitespace
|
||||
isNameFieldExist = widget.communities.any(
|
||||
(community) => community.name == enteredName,
|
||||
);
|
||||
});
|
||||
},
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
color: ColorsManager.blackColor,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Please enter the community name',
|
||||
@ -68,45 +82,51 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderSide: const BorderSide(color: ColorsManager.boxColor, width: 1),
|
||||
borderSide: const BorderSide(
|
||||
color: ColorsManager.boxColor, width: 1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide: const BorderSide(color: ColorsManager.boxColor, width: 1),
|
||||
borderSide: const BorderSide(
|
||||
color: ColorsManager.boxColor, width: 1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: ColorsManager.boxColor, width: 1),
|
||||
borderSide: const BorderSide(
|
||||
color: ColorsManager.boxColor, width: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isNameFieldExist)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
'*Name already exists.',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(color: ColorsManager.red),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Action buttons
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: ColorsManager.boxColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cancel',
|
||||
style: TextStyle(color: Colors.black),
|
||||
child: Expanded(
|
||||
child: CancelButton(
|
||||
label: 'Cancel',
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
child: DefaultButton(
|
||||
onPressed: () {
|
||||
if (enteredName.isNotEmpty) {
|
||||
if (enteredName.isNotEmpty && !isNameFieldExist) {
|
||||
widget.onCreateCommunity(
|
||||
enteredName,
|
||||
"",
|
||||
@ -114,14 +134,11 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
backgroundColor: isNameFieldExist || enteredName.isEmpty
|
||||
? ColorsManager.lightGrayColor
|
||||
: ColorsManager.secondaryColor,
|
||||
borderRadius: 10,
|
||||
foregroundColor: ColorsManager.whiteColors,
|
||||
child: const Text('OK'),
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user