simple textfield

This commit is contained in:
Valentin CZERYBA 2024-12-20 22:44:05 +01:00
parent 18fdc7d6c4
commit eadf07177b

View File

@ -51,7 +51,7 @@ class _MyHomePageState extends State<ListItemMenu> {
TextEditingController startDatepicker = TextEditingController(); TextEditingController startDatepicker = TextEditingController();
TextEditingController endDatepicker = TextEditingController(); TextEditingController endDatepicker = TextEditingController();
TextEditingController inputItem = TextEditingController(); TextEditingController inputItem = TextEditingController();
final _stringTagController = StringTagController(); TextEditingController inputTags = TextEditingController();
bool showDateFields = false; // State to toggle date fields bool showDateFields = false; // State to toggle date fields
bool showArrow = true; bool showArrow = true;
@ -535,89 +535,54 @@ class _MyHomePageState extends State<ListItemMenu> {
); );
} }
TextFieldTags<String> _buildTagsField() { Padding _buildTagsField() {
return TextFieldTags<String>(
textfieldTagsController: _stringTagController,
initialTags: [],
textSeparators: const [' ', ','],
validator: (String tag) {
if (_stringTagController.getTags!.contains(tag)) {
return 'Tu as deja rentre ce tag';
}
return null;
},
inputFieldBuilder: (context, inputFieldValues) {
return Padding( return Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: TextField( child: Column(
controller: inputFieldValues.textEditingController,
focusNode: inputFieldValues.focusNode,
onChanged: inputFieldValues.onTagChanged,
onSubmitted: inputFieldValues.onTagSubmitted,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Tags',
hintText:
inputFieldValues.tags.isNotEmpty ? '' : "Enter tag...",
errorText: inputFieldValues.error,
prefixIcon: inputFieldValues.tags.isNotEmpty
? SingleChildScrollView(
controller: inputFieldValues.tagScrollController,
scrollDirection: Axis.vertical,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
runSpacing: 4.0,
spacing: 4.0,
children: inputFieldValues.tags.map((String tag) {
return Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
color: Colors.blue,
),
margin: const EdgeInsets.symmetric(
horizontal: 5.0),
padding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [ children: [
InkWell( TextField(
child: Text( controller: inputTags,
'$tag', decoration: InputDecoration(
style: const TextStyle( labelText: 'Search by tags',
color: Colors.white), border: OutlineInputBorder(),
), suffixIcon: inputItem.text.isEmpty
onTap: () { ? null
//print("$tag selected"); : IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
setState(() {
inputItem.clear();
itemName = ''; // Reset the geographical zone state
suggestionsItem.clear();
showDateFields = true;
showArrow = true;
});
fetchPostsByLocation();
}, },
), ),
const SizedBox(width: 4.0),
InkWell(
child: const Icon(
Icons.cancel,
size: 14.0,
color: Color.fromARGB(
255, 233, 233, 233),
), ),
onTap: () { onChanged: (value) {
inputFieldValues.onTagRemoved(tag); if (value.isNotEmpty) {
}, setState(() {
) itemName = value;
searchSuggestionsByItem(value);
});
} else {
setState(() {
showDateFields = true;
showArrow = true; // Optionally clear suggestions
inputItem.clear(); // Clear the text field
itemName = ''; // Reset the geographical zone state
suggestionsItem.clear();
/// Clear the filted posts
});
fetchPostsByLocation();
}
}),
], ],
), ),
); );
}).toList()),
),
)
: null,
),
),
);
});
} }
Padding _buildItemZoneSearchField() { Padding _buildItemZoneSearchField() {
@ -654,11 +619,11 @@ class _MyHomePageState extends State<ListItemMenu> {
}); });
} else { } else {
setState(() { setState(() {
showDateFields = true;
showArrow = true; // Optionally clear suggestions
inputItem.clear(); // Clear the text field inputItem.clear(); // Clear the text field
itemName = ''; // Reset the geographical zone state itemName = ''; // Reset the geographical zone state
suggestionsItem.clear(); suggestionsItem.clear();
showDateFields = true;
showArrow = true; // Optionally clear suggestions
/// Clear the filted posts /// Clear the filted posts
}); });