Open baryalenn opened 8 months ago
Hi, You can control the position of the suggestions box with these properties: https://pub.dev/documentation/flutter_typeahead/latest/flutter_typeahead/RawTypeAheadField/offset.html https://pub.dev/documentation/flutter_typeahead/latest/flutter_typeahead/RawTypeAheadField/constraints.html Thanks.
Thanks for your response, but it doesn't work. The Offset moves the Suggestionbox but the Constraint does not work.
Here is the result :
And what I would like:
Thanks.
Thank you for that information.
I think we might have to redesign the way the box can be aligned slightly. I am thinking of something similar how to Positioned
works. I'll get back to you when I have time to work on it.
@clragon have you any plan to fix this issue?
I'm also facing the same issue, I need to increase the width of the suggestion box but my TextField is too small, @clragon did you fix this issue?
Unfortunately I have not had time to examine this yet. When that happens, I will update this issue.
Here is the issue details.
Everything working as expected. Can set width of the SuggestionBox using constraints
widget.
Code Example:
class ExampleTypeAhead extends StatefulWidget {
const ExampleTypeAhead({super.key});
@override
State<ExampleTypeAhead> createState() => _ExampleTypeAheadState();
}
class _ExampleTypeAheadState extends State<ExampleTypeAhead> {
final TextEditingController controller = TextEditingController();
final ProductController products = ValueNotifier<Map<Product, int>>({});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: TypeAheadField<Product>(
textFieldConfiguration: TextFieldConfiguration(
controller: controller,
autofocus: true,
decoration: const InputDecoration(
isDense: true,
border: OutlineInputBorder(),
hintText: 'What are you looking for?',
),
),
suggestionsBoxDecoration: SuggestionsBoxDecoration(
elevation: 4,
borderRadius: BorderRadius.circular(10),
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width * 0.92,
),
),
itemBuilder: (context, product) => ListTile(
title: Text(product.name),
subtitle: product.description != null
? Text(
'${product.description!} - \$${product.price}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
: Text('\$${product.price}'),
),
itemSeparatorBuilder: (BuildContext context, int index) => const Divider(height: 1),
suggestionsCallback: (String pattern) async => allProducts.where((product) {
final nameLower = product.name.toLowerCase().split(' ').join('');
final patternLower = pattern.toLowerCase().split(' ').join('');
return nameLower.contains(patternLower);
}).toList(),
onSuggestionSelected: (Product suggestion) => controller.clear(),
),
),
const SizedBox(width: 16),
ElevatedButton.icon(
onPressed: () {},
icon: const Icon(Icons.add),
label: const Text('Add'),
),
],
),
);
}
}
Screenshot:
Can not able to set width of the SuggestionBox using constraints
widget.
Code Example:
class ExampleTypeAhead extends StatefulWidget {
const ExampleTypeAhead({super.key});
@override
State<ExampleTypeAhead> createState() => _ExampleTypeAheadState();
}
class _ExampleTypeAheadState extends State<ExampleTypeAhead> {
final TextEditingController controller = TextEditingController();
final ProductController products = ValueNotifier<Map<Product, int>>({});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Expanded(
child: TypeAheadField<Product>(
controller: controller,
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width * 0.92,
),
builder: (context, controller, focusNode) => TextField(
controller: controller,
focusNode: focusNode,
autofocus: true,
decoration: const InputDecoration(
isDense: true,
border: OutlineInputBorder(),
hintText: 'What are you looking for?',
),
),
decorationBuilder: (context, child) => Material(
type: MaterialType.card,
elevation: 4,
borderRadius: BorderRadius.circular(10),
child: child,
),
itemBuilder: (context, product) => ListTile(
title: Text(product.name),
subtitle: product.description != null
? Text(
'${product.description!} - \$${product.price}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
)
: Text('\$${product.price}'),
),
itemSeparatorBuilder: (BuildContext context, int index) => const Divider(height: 1),
suggestionsCallback: (String pattern) async => allProducts.where((product) {
final nameLower = product.name.toLowerCase().split(' ').join('');
final patternLower = pattern.toLowerCase().split(' ').join('');
return nameLower.contains(patternLower);
}).toList(),
onSelected: (Product product) => controller.clear(),
),
),
const SizedBox(width: 16),
ElevatedButton.icon(
onPressed: () {},
icon: const Icon(Icons.add),
label: const Text('Add'),
),
],
),
);
}
}
Screenshot:
Hope, you understand the issue now. Please fix it when you have time.
I'm also facing the same issue, fix it pls
Steps to reproduce
How to change the width of the suggestionBox, without changing the width of the TextField ?
Expected results
When i add width in itemBuilder, the suggestionBox don't resize.
Actual results
The width of suggestionBox is always equal to the Textfield.
Package Version
5.2.0
Platform
Windows
Code sample
Code sample
```dart TypeAheadFieldLogs
Logs
```console [Paste your logs here] ```Screenshots or Video
Screenshots / Video demonstration
[Upload media here]