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

flutter_typeahead Get the initially selected option #606

Closed
alejandroalbarracin opened this issue Oct 3, 2024 · 2 comments
Closed

flutter_typeahead Get the initially selected option #606

alejandroalbarracin opened this issue Oct 3, 2024 · 2 comments
Labels
invalid This doesn't seem right

Comments

@alejandroalbarracin
Copy link

Hello, can you help me with a question? I have an array where I select a city and save the data in a database, but when I try to modify the city, the previously saved city is not loading correctly. I’m not sure if flutter_typeahead can handle this.

TypeAheadField(
//renderiza el texto para que se muestre al momento de seleccionar la ciudad del array
controller: cityController,
builder: ( BuildContext context, controller, FocusNode focusNode) {

                    return TextField(
                      controller: controller,
                      focusNode: focusNode,
                      obscureText: false,
                      decoration: InputDecoration(
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(color:colors.primary, width: 2.0)
                        ),
                        fillColor: Colors.white,
                        border: OutlineInputBorder(
                          
                          borderRadius: BorderRadius.circular(8)
                        ),
                        labelText: 'Buscar y seleccionar ciudad.'
                      ),
                    );
                  },
    
                  suggestionsCallback: (pattern) async {
    
                    final Completer<List<City>> completer = Completer();
    
                    // Cancelar el timer anterior si existe
                    if(_debounce?.isActive ?? false) _debounce!.cancel();
                    // Crear un nuevo timer
                    _debounce = Timer(const Duration(milliseconds: 500), () async {
                     await cityProvider.getCity(limit: 10, page: 1, search: pattern);
                     final filterCity = cityProvider.city.where((city) => 
                      city.nameCity.toLowerCase().contains(pattern.toLowerCase())
                    ).toList(); 
    
                    completer.complete(filterCity); 
    
                    });
    
                    return completer.future;
                  },
    
                  
                  itemBuilder: (context, City suggestion){
                    return ListTile(
                      title: Text(suggestion.nameCity),
                    );
                  }, 
                  
                  onSelected: (City suggestion){
                    //actualizar el estado con la seleccion seleccionada
                    setState(() {
                      selectCity = suggestion.nameCity;
                      
                      cityId = suggestion.id ;
                      cityController.text = suggestion.nameCity;
                    });
    
                    
    
                    ScaffoldMessenger.of(context).showSnackBar(
                      SnackBar(content: Text('La ciudad seleccionada fue ${suggestion.nameCity}'))
                    );
                    print('seleccion ${suggestion.id}');
                  }, 
@venkat9507
Copy link

can you explain clearly , previous not loading correctly means ?

@clragon
Copy link
Collaborator

clragon commented Dec 12, 2024

Please seek out alternative resources, as this github is reserved for package issues.
You can find help here: https://discord.gg/rflutterdev

@clragon clragon closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
@clragon clragon added the invalid This doesn't seem right label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants