I have the following code that logs a user in if successfully authenticated and it will pass a username to the dashboard page. How can I use the transferred username to get only the details of the specific user in mysql and display it in the Dashboard screen?………………………………
`Future login() async {
var url = 'https://xxxxxxxxxxxxxx.com/login.php';
var response = await http.post(Uri.parse(url), body: {
"svcNo": user.text,
"password": pass.text,
});
var data = json.decode(response.body);
if (data.toString() == "Success") {
Fluttertoast.showToast(
msg: 'Login Successful',
backgroundColor: Colors.green,
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
);
// ignore: use_build_context_synchronously
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DashBoard(
svcnoIPPIS: user.text,
),
),
);
} else {
Fluttertoast.showToast(
backgroundColor: Colors.red,
textColor: Colors.white,
msg: 'Svc No and password invalid',
toastLength: Toast.LENGTH_SHORT,
);
}
}
Future<Object> getData() async {
var url = 'https://xxxxxxxxxxxxxxxxx.com/getData.php/';
var response = await http.post(Uri.parse(url), body: {
"svcNo": widget.svcnoIPPIS,
});
final items = json.decode(response.body).cast<Map<String, dynamic>>();
List<Object> user = items.map<User>((json) {
return User.fromJson(json);
}).toList();
return user;
if (response.statusCode == 200) {
return User.fromJson(jsonDecode(response.body));
} else {
throw Exception('Failed to load album');
}
}
<?php
$db = mysqli_connect('localhost','$username','$password','$theDatabase');
$svc_no = $_POST['svcNo'];
$sql = "SELECT name, rank, start_date, SUM(amount) from $table u join $anotherTable c on u.svcNo_IPPIS = c.svcNo_IPPIS WHERE c.svcNo_IPPIS = '.svc_no.'";
$result = mysqli_query($db,$sql);
$finalResult=array();
while($fetchData=$result->fetch_assoc()){
$finalResult[]=$fetchData;
}
echo json_encode($finalResult);
?>`