responsive create/edit space

This commit is contained in:
hannathkadher
2024-11-26 12:16:46 +04:00
parent 703e0efd2e
commit 17943a5ddf

View File

@ -45,169 +45,162 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
selectedProducts = widget.selectedProducts.isNotEmpty ? widget.selectedProducts : []; selectedProducts = widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
} }
@override
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
final screenHeight = MediaQuery.of(context).size.height;
return AlertDialog( return AlertDialog(
title: widget.isEdit ? Text('Edit Space') : Text('Create new Space'), title: widget.isEdit ? const Text('Edit Space') : const Text('Create New Space'),
backgroundColor: ColorsManager.whiteColors, backgroundColor: ColorsManager.whiteColors,
content: SizedBox( content: SizedBox(
width: 600, width: screenWidth * 0.5, // Limit dialog width
child: Column( child: SingleChildScrollView(
mainAxisSize: MainAxisSize.min, // Scrollable content to prevent overflow
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
children: [ mainAxisSize: MainAxisSize.min,
Row( crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Stack( Row(
alignment: Alignment.center, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Stack(
width: 100, alignment: Alignment.center,
height: 100,
decoration: const BoxDecoration(
color: ColorsManager.boxColor,
shape: BoxShape.circle,
),
),
SvgPicture.asset(
selectedIcon,
width: 60,
height: 60,
),
Positioned(
top: 2,
left: 2,
child: InkWell(
onTap: () => _showIconSelectionDialog(),
child: Container(
width: 20,
height: 20,
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: SvgPicture.asset(Assets.iconEdit, width: 10, height: 10),
),
),
),
],
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Name input field Container(
TextField( width: screenWidth * 0.1, // Adjusted width
controller: nameController, height: screenWidth * 0.1, // Adjusted height
onChanged: (value) { decoration: const BoxDecoration(
enteredName = value; color: ColorsManager.boxColor,
}, shape: BoxShape.circle,
style: const TextStyle(color: Colors.black), ),
decoration: InputDecoration( ),
hintText: 'Please enter the name', SvgPicture.asset(
hintStyle: const TextStyle( selectedIcon,
fontSize: 14, width: screenWidth * 0.04,
color: ColorsManager.lightGrayColor, height: screenWidth * 0.04,
fontWeight: FontWeight.w400), ),
filled: true, Positioned(
fillColor: ColorsManager.boxColor, top: 6,
enabledBorder: OutlineInputBorder( right: 6,
borderRadius: BorderRadius.circular(10), child: InkWell(
borderSide: const BorderSide( onTap: _showIconSelectionDialog,
color: ColorsManager child: Container(
.boxColor, // Light gray color when enabled (not focused) width: screenWidth * 0.020,
width: 1.5, height: screenWidth * 0.020,
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
), ),
), child: SvgPicture.asset(
// Set border when focused Assets.iconEdit,
focusedBorder: OutlineInputBorder( width: screenWidth * 0.06,
borderRadius: BorderRadius.circular(10), height: screenWidth * 0.06,
borderSide: const BorderSide(
color: ColorsManager.boxColor, // Primary color when focused
width: 1.5,
),
),
// Set border for disabled state
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: ColorsManager.boxColor, // Light gray for disabled state
width: 1.5,
),
),
// Set border for error state
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: ColorsManager.boxColor, // Red border when there's an error
width: 1.5,
),
),
// Border for focused error state
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: ColorsManager
.boxColor, // Red border when there's an error and it's focused
width: 1.5,
), ),
), ),
), ),
), ),
const SizedBox(height: 16),
if (selectedProducts.isNotEmpty)
_buildSelectedProductsButtons(widget.products ?? [])
else
DefaultButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => AddDeviceWidget(
products: widget.products,
onProductsSelected: (selectedProductsMap) {
setState(() {
selectedProducts = selectedProductsMap;
});
},
),
);
},
backgroundColor: ColorsManager.textFieldGreyColor,
foregroundColor: Colors.black, // Set the desired text/icon color
borderColor: ColorsManager.neutralGray, // Define border color
borderRadius: 20.0,
padding: 20.0, // Add padding
child: Row(
mainAxisSize:
MainAxisSize.min, // Adjust the button size to fit the content
children: [
SvgPicture.asset(
Assets.addIcon, // Replace with your actual icon path
width: 20, // Set the size of the icon
height: 20,
),
const SizedBox(width: 8), // Add spacing between the icon and text
const Text(
'Add devices / Assign a space model',
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: 'Aftika',
fontWeight: FontWeight.w400,
height: 1.5, // Adjust line height for better spacing
),
),
const SizedBox(width: 8),
],
),
)
], ],
), ),
),
], const SizedBox(width: 16),
), Expanded(
], // Ensure the text field expands responsively
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
controller: nameController,
onChanged: (value) {
enteredName = value;
},
style: const TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'Please enter the name',
hintStyle: const TextStyle(
fontSize: 14,
color: ColorsManager.lightGrayColor,
fontWeight: FontWeight.w400,
),
filled: true,
fillColor: ColorsManager.boxColor,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: ColorsManager.boxColor,
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: ColorsManager.boxColor,
width: 1.5,
),
),
),
),
const SizedBox(height: 16),
if (selectedProducts.isNotEmpty)
_buildSelectedProductsButtons(widget.products ?? [])
else
DefaultButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => AddDeviceWidget(
products: widget.products,
onProductsSelected: (selectedProductsMap) {
setState(() {
selectedProducts = selectedProductsMap;
});
},
),
);
},
backgroundColor: ColorsManager.textFieldGreyColor,
foregroundColor: Colors.black,
borderColor: ColorsManager.neutralGray,
borderRadius: 16.0,
padding: 10.0, // Reduced padding for smaller size
child: Align(
alignment: Alignment.centerLeft,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.only(
left: 6.0),
child: SvgPicture.asset(
Assets.addIcon,
width: screenWidth * 0.015, // Adjust icon size
height: screenWidth * 0.015,
),
),
const SizedBox(width: 3),
const Flexible(
child: Text(
'Add devices / Assign a space model',
overflow: TextOverflow.ellipsis, // Prevent overflow
style: TextStyle(
color: Colors.black,
fontSize: 14,
fontFamily: 'Aftika',
fontWeight: FontWeight.w400,
),
),
),
],
),
)),
],
),
),
],
),
],
),
), ),
), ),
actions: [ actions: [
@ -224,11 +217,10 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
Expanded( Expanded(
child: DefaultButton( child: DefaultButton(
onPressed: () { onPressed: () {
late String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? ''); String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? '');
if (newName.isNotEmpty) { if (newName.isNotEmpty) {
widget.onCreateSpace( widget.onCreateSpace(newName, selectedIcon, selectedProducts);
newName, selectedIcon, selectedProducts); // Pass the name and icon back Navigator.of(context).pop();
Navigator.of(context).pop(); // Close the dialog
} }
}, },
backgroundColor: ColorsManager.secondaryColor, backgroundColor: ColorsManager.secondaryColor,
@ -243,6 +235,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
} }
void _showIconSelectionDialog() { void _showIconSelectionDialog() {
final screenWidth = MediaQuery.of(context).size.width;
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
@ -250,8 +244,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
title: const Text('Select Icon'), title: const Text('Select Icon'),
backgroundColor: Colors.white, backgroundColor: Colors.white,
content: Container( content: Container(
width: 500, width: screenWidth * 0.5,
height: 200,
padding: const EdgeInsets.all(18), padding: const EdgeInsets.all(18),
decoration: BoxDecoration( decoration: BoxDecoration(
color: ColorsManager.boxColor, color: ColorsManager.boxColor,
@ -274,8 +267,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
}, },
child: SvgPicture.asset( child: SvgPicture.asset(
spaceIconList[index], spaceIconList[index],
width: 50, width: screenWidth * 0.06,
height: 50, height: screenWidth * 0.06,
), ),
); );
}, },
@ -287,8 +280,10 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
} }
Widget _buildSelectedProductsButtons(List<ProductModel> products) { Widget _buildSelectedProductsButtons(List<ProductModel> products) {
final screenWidth = MediaQuery.of(context).size.width;
return Container( return Container(
width: 600, width: screenWidth * 0.6,
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(8),
decoration: BoxDecoration( decoration: BoxDecoration(
color: ColorsManager.textFieldGreyColor, color: ColorsManager.textFieldGreyColor,