Hello I am new to flutter and I am tryin to fetch data from MYSQL database based on keyword entered by the user. But the result is empty even though the data is present. I am using msqljocky5 package for MYSQL connection.
Future<Results> getProducts()async{
if(searchValue==""){
ConnectionSettings settings = new ConnectionSettings(
host: '10.0.2.2',
port: 3306,
user: 'root',
password:'',
db: 'master'
);
dynamic db = await MySqlConnection.connect(settings);
try{
Results results = await (await db
.execute('SELECT * from product'))
.deStream();
await db.close();
return (results);
}catch(e){
print("Error01"+e.toString());
}
}else{
ConnectionSettings settings = new ConnectionSettings(
host: '10.0.2.2',
port: 3306,
user: 'root',
password:'',
db: 'master'
);
dynamic db = await MySqlConnection.connect(settings);
try{
print("Serach valuse is "+searchValue);
Results results = await (await db
.prepared('SELECT * from product WHERE productName LIKE "%?%"',[searchValue]))
.deStream();
await db.close();
print("AffectedRows"+results.affectedRows.toString());
print(results);
results.forEach((rw.Row rw) {print(rw[0]); });
return (results);
}catch(e){
print("Error01"+e.toString());
}
}}