81 lines
2.6 KiB
Dart
81 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
|
import 'package:rkm/models/pais_modelo.dart';
|
|
import 'package:rkm/widgets/text_default.dart';
|
|
import '../config/color_palette.dart';
|
|
import '../config/const_variable.dart';
|
|
import 'input_search_text.dart';
|
|
|
|
class DropDownButtonComPesquisaPaises extends StatelessWidget {
|
|
var onChanged;
|
|
PaisModelo? select;
|
|
String title;
|
|
double fontSize;
|
|
List<PaisModelo> list;
|
|
double width;
|
|
double heightDinamic;
|
|
double widthContainer;
|
|
|
|
DropDownButtonComPesquisaPaises({
|
|
required this.onChanged,
|
|
required this.select,
|
|
required this.title,
|
|
required this.list,
|
|
required this.width,
|
|
this.heightDinamic = 0.2,
|
|
this.fontSize = 15,
|
|
this.widthContainer = 300,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
double height = MediaQuery.of(context).size.height;
|
|
|
|
return
|
|
Container(
|
|
width: width,
|
|
height: height*heightDinamic,
|
|
margin: ConstVariable().marginHightInput,
|
|
color: ColorPalette.white,
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
children: [
|
|
TypeAheadField(
|
|
controller: TextEditingController(),
|
|
suggestionsCallback: (pattern) {
|
|
if (list != null) {
|
|
return list.where((value) => value.PAIS.toLowerCase().contains(pattern.toLowerCase())).toList();
|
|
} else {
|
|
return Future.value([]);
|
|
}
|
|
},
|
|
emptyBuilder: (context) {
|
|
return ListTile(
|
|
title: Text('Nenhum resultado encontrado'),
|
|
);
|
|
},
|
|
itemBuilder: (context, suggestion) {
|
|
// Aqui, o tipo de 'suggestion' é dinâmico, pois a lista retornada
|
|
// por suggestionsCallback pode conter diferentes tipos de objetos.
|
|
// Você pode usar a notação de tipo dinâmico ou verificar o tipo do
|
|
// objeto e fazer o cast para 'PaisModelo' antes de usar.
|
|
if (suggestion is PaisModelo) {
|
|
// Faz o cast para 'PaisModelo' se necessário
|
|
final paisModelo = suggestion as PaisModelo;
|
|
return ListTile(
|
|
title: Text(paisModelo.PAIS),
|
|
);
|
|
}
|
|
// Se o objeto não for do tipo 'PaisModelo', retorne um widget vazio
|
|
return SizedBox.shrink();
|
|
},
|
|
onSelected: onChanged,
|
|
)
|
|
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|