121 lines
3.6 KiB
Dart
121 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:rkm/widgets/text_default.dart';
|
|
import 'package:sqflite/sqflite.dart';
|
|
import '../screens/registers_citizen/register_citizen_screen.dart';
|
|
import '../service/db/db_sqlite_load.dart';
|
|
import '../config/color_palette.dart';
|
|
import 'input_search_text.dart';
|
|
|
|
class AlertDialogSearchStateful extends StatefulWidget {
|
|
|
|
@override
|
|
State<AlertDialogSearchStateful> createState() => _AlertDialogSearchStatefulState();
|
|
}
|
|
|
|
class _AlertDialogSearchStatefulState extends State<AlertDialogSearchStateful> {
|
|
|
|
List cityDB = [];
|
|
List showResultSearchCity = [];
|
|
var controller = TextEditingController();
|
|
|
|
_searchCityBirth(){
|
|
searchCity();
|
|
}
|
|
getCity()async{
|
|
Database db = await DbSqliteLoad().intialDB();
|
|
var query = "SELECT * FROM MUNICIPIOS ORDER BY NO_MUNICIPIO";
|
|
List list = await db.rawQuery(query);
|
|
// print("SELECT * FROM UNIDADES");
|
|
// print(await db.rawQuery("SELECT * FROM UNIDADES"));
|
|
for(int i=0; list.length > i;i++){
|
|
cityDB.add('${list[i]['NO_MUNICIPIO']} - ${list[i]['UF_ESTADO']}');
|
|
}
|
|
searchCity();
|
|
return 'complete';
|
|
}
|
|
|
|
searchCity()async{
|
|
if(controller.text.isNotEmpty){
|
|
showResultSearchCity =[];
|
|
for (int i =0;cityDB.length>i;i++) {
|
|
String CIDADE = '${cityDB[i]}';
|
|
|
|
if(CIDADE.contains(controller.text.toUpperCase())){
|
|
if(showResultSearchCity.length<10){
|
|
showResultSearchCity.add(cityDB[i]);
|
|
}
|
|
}
|
|
}
|
|
setState(() {
|
|
print(showResultSearchCity);
|
|
});
|
|
}else{
|
|
setState(() {
|
|
for(int i = 0;i<10;i++){
|
|
showResultSearchCity.add(cityDB[i]);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
getCity();
|
|
controller.addListener(_searchCityBirth);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
double width = MediaQuery.of(context).size.width;
|
|
double height = MediaQuery.of(context).size.height;
|
|
|
|
return AlertDialog(
|
|
title: InputSearchText(
|
|
controller: controller,
|
|
width: width*0.3,
|
|
hint: 'Buscar...',
|
|
color: ColorPalette.titleContainer,
|
|
border: false,
|
|
),
|
|
content: Container(
|
|
padding: EdgeInsets.symmetric(vertical: 10),
|
|
width: width*0.8,
|
|
child: Container(
|
|
width: width*0.8,
|
|
height: height*0.8,
|
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
|
child: ListView.separated(
|
|
separatorBuilder:(context,index)=> Divider(color: ColorPalette.black54,height: 5,),
|
|
itemCount: showResultSearchCity.length,
|
|
itemBuilder: (context,index){
|
|
return Container(
|
|
width: width*0.8,
|
|
color: ColorPalette.white,
|
|
child: ListTile(
|
|
onTap: (){
|
|
setState(() {
|
|
controller.text = showResultSearchCity[index];
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => RegisterCitizenScreen(select: controller.text,)),
|
|
);
|
|
});
|
|
},
|
|
title: TextDefault(
|
|
color: ColorPalette.black54,
|
|
text: showResultSearchCity[index],
|
|
fontSize: 16,
|
|
maxLines: 2,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|