你可以使用包轻松自动完成
https://pub.dev/packages/easy_autocomplete
像这样:
Container(
padding: EdgeInsets.only(left:10.0),
width: (GeneralUtils.deviceIsTablet? screenWidth*0.35:screenWidth *0.25),
height: 50,
child: FutureBuilder(
future: getPhones(),
builder: (context, AsyncSnapshot snapshot) {
return EasyAutocomplete(
inputTextStyle: TextStyle(
color: CustomColors.textLightPrimaryColor,
fontSize: 14,
fontWeight: FontWeight.w800,
),
controller: _clientPhoneController,
suggestions: _phoneList,
onChanged: (_) => null,
onSubmitted:(_) async{
getDataByPhone(_clientPhoneController.text);
},
decoration: InputDecoration(
hintText:'Enter the phone',
hintStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: CustomColors.textLightPrimaryColor.withOpacity(0.4)
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: CustomColors.textLightPrimaryColor),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: CustomColors.textLightPrimaryColor),
),
),
suggestionBuilder: (data) {
return Text(
data,
style: TextStyle(
color: CustomColors.textLightPrimaryColor,
fontSize: 14,
fontWeight: FontWeight.w600,
),
);
}
);
}),