0

我想自动完成FormBuilderDropdown. 当我写一封信时,项目列表会更改以显示包含该字母的项目。

FormBuilderDropdown(
                attribute: 'field_city',
                decoration: LikpechInputDecoration(_isLoading, 'Selectionnez une ville'),
                items:  _buildListCities(),
                /*initialValue: DropdownMenuItem(
                  value: _selectedCity,
                  child: Text(_listCities[_selectedCity]['name']),
                ),*/
                onChanged: (index) {
                  setState(() {
                    _selectedCity = index;
                  });
                  fetchAgences(index);
                },
              validators: [
                FormBuilderValidators.required(errorText: '')
              ],
            ) : Center(child: CupertinoActivityIndicator()),
4

1 回答 1

0

使用 typehead 插件typehead flutter

在此处输入图像描述

import 'package:flutter_typeahead/flutter_typeahead.dart';

.
.
.
TypeAheadField(
  textFieldConfiguration: TextFieldConfiguration(
    autofocus: true,
    style: DefaultTextStyle.of(context).style.copyWith(
      fontStyle: FontStyle.italic
    ),
    decoration: InputDecoration(
      border: OutlineInputBorder()
    )
  ),
  suggestionsCallback: (pattern) async {
    return await BackendService.getSuggestions(pattern);
  },
  itemBuilder: (context, suggestion) {
    return ListTile(
      leading: Icon(Icons.shopping_cart),
      title: Text(suggestion['name']),
      subtitle: Text('\$${suggestion['price']}'),
    );
  },
  onSuggestionSelected: (suggestion) {
    Navigator.of(context).push(MaterialPageRoute(
      builder: (context) => ProductPage(product: suggestion)
    ));
  },
)
.
.
.
于 2020-09-22T11:54:20.793 回答