Error with getting login with user.text

Having practice with login to DB with php, there was some error that i cant fix.

when i get connected to maria DB, php shows up ‘get connected’ whether ID is correct or not.

please help me how i could fix this syntex

i just want to make it login with right ID and PW


Future _login() async{

var username = user.text;
var password = pass.text;
var url = "http://14.34.80.72/dbconnection.php";

final response = await http.post(url, body: {"username" : '$username', "password" : '$password'},
encoding: Encoding.getByName(("utf-8")));

List datauser = json.decode(response.body);

if(datauser.length==0){
  DeniedAlertDialog(context);
}
else{
  loginAlertDialog(context);

  setState(() {
    username= datauser[0]['username'];
  });
}
return datauser;

}
// this is how method goes on

Widget build(BuildContext context) {
final _IDField = TextField(controller: user,
obscureText: false,
style: style,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: “Username”,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(32.0))),
);

      final _passwordField = TextField(controller: pass,
        obscureText: true,
        style: style,
        decoration: InputDecoration(
            contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
            hintText: "Password",
            border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(32.0))),
      );

      final _loginButton = Material(
          elevation: 5.0,
          borderRadius: BorderRadius.circular(30.0),
          color: Color(0xff01A0C7),
          child: FlatButton(
              padding: EdgeInsets.fromLTRB(55.0, 15.0, 55.0, 15.0),
              onPressed:() {loginAlertDialog;},
              child: Text("Login",
                  textAlign: TextAlign.center,
                  style: style.copyWith(
                      color: Colors.white,
                      fontWeight: FontWeight.bold))));

//this is the widget i’d like to display with

<?php $server="localhost"; $username=$_POST['username']; $password=$_POST['password']; $database = "itemlist"; $connect=new mysqli($servername,$username,$password,$database); /* Check the connection is created properly or not */ if($connect->connect_error) echo "Connection error:" .$connect->connect_error; else echo "Connection is created successfully"; ?>

//this is the php file

i solved it by using mysql1 package

here is the code for mysql1
Future _login() async{

  var username = user.text;
  var password = pass.text;

  final connection = await MYSQL1.MySqlConnection.connect(new MYSQL1.ConnectionSettings(host: , port: , user: '$username', password: '$password', db: 'Test01'));
  var _SQLError = MYSQL1.MySqlClientError(this.msg);

  if(_SQLError != 0) {
    loginAlertDialog(context);
  }
  else {
    DeniedAlertDialog(context);
  }
2 Likes

Great! thanks for sharing the solution. I am sure it will help someone else.