Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Allow positioning the suggestions box more freely #577

Open
baryalenn opened this issue Mar 22, 2024 · 8 comments
Open

[Feature] Allow positioning the suggestions box more freely #577

baryalenn opened this issue Mar 22, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@baryalenn
Copy link

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
TypeAheadField<ParticipantModel>(
                    constraints: const BoxConstraints(minWidth: 1000),
                    loadingBuilder: (context) {
                      return const SizedBox(
                        height: 55,
                        child: ListTile(
                          title: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [Text("loading"), LinearProgressIndicator()],
                          ),
                        ),
                      );
                    },
                    controller: patternController,
                    suggestionsController: ref.read(suggestionsParticipantsControllerProvider),
                    builder: (context, controller, focusNode) {
                      return SizedBox(
                        child: TextFormField(
                          controller: controller,
                          focusNode: focusNode,
                          decoration: InputDecoration(
                              contentPadding: const EdgeInsets.all(8.0),
                              labelText: 'Rechercher un participant',
                              focusedBorder: const OutlineInputBorder(borderSide: BorderSide(width: 1.0)),
                              enabledBorder: const OutlineInputBorder(borderSide: BorderSide(width: 1.0)),
                              errorBorder: const OutlineInputBorder(borderSide: BorderSide(width: 1.0)),
                              prefixIcon: const Icon(Icons.search),
                              suffixIcon: IconButton(
                                tooltip: "Inscrire un nouveau participant",
                                icon: const Icon(Icons.person_add),
                                onPressed: () {
                                  context.goNamed(inscriptionRouteName);
                                },
                              )),
                        ),
                      );
                    },
                    suggestionsCallback: (pattern) async {
                      return getSuggestions(participantsOfYear, pattern);
                    },
                    onSelected: (participant) {},
                    itemBuilder: (context, suggestion) {
                      return Column(
                        children: [
                          ListTileParticipant(participant: suggestion, isOffstageTimeAgo: true)
                        ],
                      );
                    },
                    emptyBuilder: (BuildContext noItemContext) {
                      return TextFieldTapRegion(
                        child: ListTile(
                          title: const Text("No participant"),
                          onTap: () {
                            context.goNamed(inscriptionRouteName);
                          },
                        ),
                      );
                    },
                    errorBuilder: (context, error) {
                      ref.watch(utilsProvider).errorData(error);
                      return const Text("Error");
                    },
                  )

Logs

Logs
[Paste your logs here]

Screenshots or Video

Screenshots / Video demonstration [Upload media here]
@baryalenn baryalenn added the bug Something isn't working label Mar 22, 2024
@clragon
Copy link
Collaborator

clragon commented Mar 27, 2024

@clragon clragon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2024
@clragon clragon added invalid This doesn't seem right and removed bug Something isn't working labels Mar 27, 2024
@clragon clragon self-assigned this Mar 27, 2024
@baryalenn
Copy link
Author

Thanks for your response, but it doesn't work.
The Offset moves the Suggestionbox but the Constraint does not work.

Here is the result :
1

And what I would like:
2

Thanks.

@clragon clragon reopened this Mar 30, 2024
@clragon
Copy link
Collaborator

clragon commented Mar 31, 2024

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 clragon added bug Something isn't working and removed invalid This doesn't seem right labels Mar 31, 2024
@chayanforyou
Copy link

@clragon have you any plan to fix this issue?

@RG-Hariharasudhan
Copy link

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?

@clragon
Copy link
Collaborator

clragon commented Sep 28, 2024

Unfortunately I have not had time to examine this yet. When that happens, I will update this issue.

@chayanforyou
Copy link

Here is the issue details.

Version 4.8.0

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:


Version 5.0.2

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.

@cssword
Copy link

cssword commented Nov 26, 2024

I'm also facing the same issue, fix it pls

@clragon clragon added enhancement New feature or request and removed bug Something isn't working labels Dec 12, 2024
@clragon clragon changed the title [Question] How to change the width of the suggestionBox, without changing the width of the TextField [Feature] Allow positioning the suggestions box more freely Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants