mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed list view
This commit is contained in:
138
lib/common/dialog_dropdown.dart
Normal file
138
lib/common/dialog_dropdown.dart
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class DialogDropdown extends StatefulWidget {
|
||||||
|
final List<String> items;
|
||||||
|
final ValueChanged<String> onSelected;
|
||||||
|
final String? selectedValue;
|
||||||
|
|
||||||
|
const DialogDropdown({
|
||||||
|
Key? key,
|
||||||
|
required this.items,
|
||||||
|
required this.onSelected,
|
||||||
|
this.selectedValue,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_DialogDropdownState createState() => _DialogDropdownState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DialogDropdownState extends State<DialogDropdown> {
|
||||||
|
bool _isOpen = false;
|
||||||
|
late OverlayEntry _overlayEntry;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _toggleDropdown() {
|
||||||
|
if (_isOpen) {
|
||||||
|
_closeDropdown();
|
||||||
|
} else {
|
||||||
|
_openDropdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _openDropdown() {
|
||||||
|
_overlayEntry = _createOverlayEntry();
|
||||||
|
Overlay.of(context).insert(_overlayEntry);
|
||||||
|
_isOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _closeDropdown() {
|
||||||
|
_overlayEntry.remove();
|
||||||
|
_isOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
OverlayEntry _createOverlayEntry() {
|
||||||
|
final renderBox = context.findRenderObject() as RenderBox;
|
||||||
|
final size = renderBox.size;
|
||||||
|
final offset = renderBox.localToGlobal(Offset.zero);
|
||||||
|
|
||||||
|
return OverlayEntry(
|
||||||
|
builder: (context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
_closeDropdown();
|
||||||
|
},
|
||||||
|
behavior: HitTestBehavior.translucent,
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Positioned(
|
||||||
|
left: offset.dx,
|
||||||
|
top: offset.dy + size.height,
|
||||||
|
width: size.width,
|
||||||
|
child: Material(
|
||||||
|
elevation: 4.0,
|
||||||
|
child: Container(
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxHeight: 200.0, // Set max height for dropdown
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: widget.items.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final item = widget.items[index];
|
||||||
|
return Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
color: ColorsManager.lightGrayBorderColor,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ListTile(
|
||||||
|
title: Text(
|
||||||
|
item,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium
|
||||||
|
?.copyWith(
|
||||||
|
color: ColorsManager.textPrimaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
widget.onSelected(item);
|
||||||
|
_closeDropdown();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: _toggleDropdown,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: ColorsManager.transparentColor),
|
||||||
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
widget.selectedValue ?? 'Select an item',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
const Icon(Icons.arrow_drop_down),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
160
lib/common/dialog_textfield_dropdown.dart
Normal file
160
lib/common/dialog_textfield_dropdown.dart
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class DialogTextfieldDropdown extends StatefulWidget {
|
||||||
|
final List<String> items;
|
||||||
|
final ValueChanged<String> onSelected;
|
||||||
|
final String? initialValue;
|
||||||
|
|
||||||
|
const DialogTextfieldDropdown({
|
||||||
|
Key? key,
|
||||||
|
required this.items,
|
||||||
|
required this.onSelected,
|
||||||
|
this.initialValue,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_DialogTextfieldDropdownState createState() =>
|
||||||
|
_DialogTextfieldDropdownState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DialogTextfieldDropdownState extends State<DialogTextfieldDropdown> {
|
||||||
|
bool _isOpen = false;
|
||||||
|
late OverlayEntry _overlayEntry;
|
||||||
|
final TextEditingController _controller = TextEditingController();
|
||||||
|
late List<String> _filteredItems; // Filtered items list
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller.text = widget.initialValue ?? 'Select Tag';
|
||||||
|
_filteredItems = List.from(widget.items); // Initialize filtered items
|
||||||
|
}
|
||||||
|
|
||||||
|
void _toggleDropdown() {
|
||||||
|
if (_isOpen) {
|
||||||
|
_closeDropdown();
|
||||||
|
} else {
|
||||||
|
_openDropdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _openDropdown() {
|
||||||
|
_overlayEntry = _createOverlayEntry();
|
||||||
|
Overlay.of(context).insert(_overlayEntry);
|
||||||
|
_isOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _closeDropdown() {
|
||||||
|
_overlayEntry.remove();
|
||||||
|
_isOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
OverlayEntry _createOverlayEntry() {
|
||||||
|
final renderBox = context.findRenderObject() as RenderBox;
|
||||||
|
final size = renderBox.size;
|
||||||
|
final offset = renderBox.localToGlobal(Offset.zero);
|
||||||
|
|
||||||
|
return OverlayEntry(
|
||||||
|
builder: (context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
_closeDropdown();
|
||||||
|
},
|
||||||
|
behavior: HitTestBehavior.translucent,
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Positioned(
|
||||||
|
left: offset.dx,
|
||||||
|
top: offset.dy + size.height,
|
||||||
|
width: size.width,
|
||||||
|
child: Material(
|
||||||
|
elevation: 4.0,
|
||||||
|
child: Container(
|
||||||
|
color: ColorsManager.whiteColors,
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxHeight: 200.0,
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: _filteredItems.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final item = _filteredItems[index];
|
||||||
|
return Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
color: ColorsManager.lightGrayBorderColor,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ListTile(
|
||||||
|
title: Text(item,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium
|
||||||
|
?.copyWith(
|
||||||
|
color: ColorsManager.textPrimaryColor)),
|
||||||
|
onTap: () {
|
||||||
|
_controller.text = item;
|
||||||
|
widget.onSelected(item);
|
||||||
|
setState(() {
|
||||||
|
_filteredItems
|
||||||
|
.remove(item); // Remove selected item
|
||||||
|
});
|
||||||
|
_closeDropdown();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: _toggleDropdown,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: ColorsManager.transparentColor),
|
||||||
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _controller,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
_filteredItems = widget.items
|
||||||
|
.where((item) =>
|
||||||
|
item.toLowerCase().contains(value.toLowerCase()))
|
||||||
|
.toList(); // Filter items dynamically
|
||||||
|
});
|
||||||
|
widget.onSelected(value);
|
||||||
|
},
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Enter or Select tag',
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Icon(Icons.arrow_drop_down),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -127,7 +127,8 @@ class AssignTagModelBloc
|
|||||||
}
|
}
|
||||||
final uniqueTags = tags.map((tag) => tag.tag?.trim() ?? '').toSet();
|
final uniqueTags = tags.map((tag) => tag.tag?.trim() ?? '').toSet();
|
||||||
final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty);
|
final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty);
|
||||||
return uniqueTags.length == tags.length && !hasEmptyTag;
|
final isValid = uniqueTags.length == tags.length && !hasEmptyTag;
|
||||||
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
String? _getValidationError(List<TagModel> tags) {
|
String? _getValidationError(List<TagModel> tags) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/common/dialog_dropdown.dart';
|
||||||
|
import 'package:syncrow_web/common/dialog_textfield_dropdown.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/cancel_button.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/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
@ -79,6 +81,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
style:
|
style:
|
||||||
Theme.of(context).textTheme.bodyMedium)),
|
Theme.of(context).textTheme.bodyMedium)),
|
||||||
DataColumn(
|
DataColumn(
|
||||||
|
numeric: false,
|
||||||
|
headingRowAlignment: MainAxisAlignment.start,
|
||||||
label: Text('Tag',
|
label: Text('Tag',
|
||||||
style:
|
style:
|
||||||
Theme.of(context).textTheme.bodyMedium)),
|
Theme.of(context).textTheme.bodyMedium)),
|
||||||
@ -109,6 +113,8 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
: List.generate(state.tags.length, (index) {
|
: List.generate(state.tags.length, (index) {
|
||||||
final tag = state.tags[index];
|
final tag = state.tags[index];
|
||||||
final controller = controllers[index];
|
final controller = controllers[index];
|
||||||
|
final availableTags = getAvailableTags(
|
||||||
|
allTags ?? [], state.tags, tag);
|
||||||
|
|
||||||
return DataRow(
|
return DataRow(
|
||||||
cells: [
|
cells: [
|
||||||
@ -159,39 +165,14 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
DataCell(
|
DataCell(
|
||||||
Row(
|
Container(
|
||||||
children: [
|
alignment: Alignment
|
||||||
Expanded(
|
.centerLeft, // Align cell content to the left
|
||||||
child: TextFormField(
|
child: SizedBox(
|
||||||
controller: controller,
|
width: double
|
||||||
onChanged: (value) {
|
.infinity, // Ensure full width for dropdown
|
||||||
context
|
child: DialogTextfieldDropdown(
|
||||||
.read<AssignTagModelBloc>()
|
items: availableTags ?? [],
|
||||||
.add(UpdateTag(
|
|
||||||
index: index,
|
|
||||||
tag: value.trim(),
|
|
||||||
));
|
|
||||||
},
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
border: InputBorder.none,
|
|
||||||
),
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: MediaQuery.of(context)
|
|
||||||
.size
|
|
||||||
.width *
|
|
||||||
0.15,
|
|
||||||
child: PopupMenuButton<String>(
|
|
||||||
color: ColorsManager.whiteColors,
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.arrow_drop_down,
|
|
||||||
color:
|
|
||||||
ColorsManager.blackColor),
|
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
controller.text = value;
|
controller.text = value;
|
||||||
context
|
context
|
||||||
@ -201,88 +182,26 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
tag: value,
|
tag: value,
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
itemBuilder: (context) {
|
|
||||||
return (allTags ?? [])
|
|
||||||
.where((tagValue) => !state
|
|
||||||
.tags
|
|
||||||
.map((e) => e.tag)
|
|
||||||
.contains(tagValue))
|
|
||||||
.map((tagValue) {
|
|
||||||
return PopupMenuItem<String>(
|
|
||||||
textStyle: const TextStyle(
|
|
||||||
color: ColorsManager
|
|
||||||
.textPrimaryColor),
|
|
||||||
value: tagValue,
|
|
||||||
child: ConstrainedBox(
|
|
||||||
constraints:
|
|
||||||
BoxConstraints(
|
|
||||||
minWidth: MediaQuery.of(
|
|
||||||
context)
|
|
||||||
.size
|
|
||||||
.width *
|
|
||||||
0.15,
|
|
||||||
maxWidth: MediaQuery.of(
|
|
||||||
context)
|
|
||||||
.size
|
|
||||||
.width *
|
|
||||||
0.15,
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
tagValue,
|
|
||||||
overflow: TextOverflow
|
|
||||||
.ellipsis,
|
|
||||||
),
|
|
||||||
));
|
|
||||||
}).toList();
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
DataCell(
|
DataCell(
|
||||||
DropdownButtonHideUnderline(
|
SizedBox(
|
||||||
child: DropdownButton<String>(
|
width: double.infinity,
|
||||||
value: tag.location ?? 'None',
|
child: DialogDropdown(
|
||||||
dropdownColor: ColorsManager
|
items: locations,
|
||||||
.whiteColors, // Dropdown background
|
selectedValue:
|
||||||
style: const TextStyle(
|
tag.location ?? 'None',
|
||||||
color: Colors
|
onSelected: (value) {
|
||||||
.black), // Style for selected text
|
|
||||||
items: [
|
|
||||||
const DropdownMenuItem<String>(
|
|
||||||
value: 'None',
|
|
||||||
child: Text(
|
|
||||||
'None',
|
|
||||||
style: TextStyle(
|
|
||||||
color: ColorsManager
|
|
||||||
.textPrimaryColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...locations.map((location) {
|
|
||||||
return DropdownMenuItem<String>(
|
|
||||||
value: location,
|
|
||||||
child: Text(
|
|
||||||
location,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: ColorsManager
|
|
||||||
.textPrimaryColor),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
],
|
|
||||||
onChanged: (value) {
|
|
||||||
if (value != null) {
|
|
||||||
context
|
context
|
||||||
.read<AssignTagModelBloc>()
|
.read<AssignTagModelBloc>()
|
||||||
.add(UpdateLocation(
|
.add(UpdateLocation(
|
||||||
index: index,
|
index: index,
|
||||||
location: value,
|
location: value,
|
||||||
));
|
));
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
)),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -380,4 +299,15 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> getAvailableTags(
|
||||||
|
List<String> allTags, List<TagModel> currentTags, TagModel currentTag) {
|
||||||
|
print("happening");
|
||||||
|
return allTags
|
||||||
|
.where((tagValue) => !currentTags
|
||||||
|
.where((e) => e != currentTag) // Exclude the current row
|
||||||
|
.map((e) => e.tag)
|
||||||
|
.contains(tagValue))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user