I have a php mvc website that contain controller - model - view

How I can call a function in flutter. fo example the login form of the website has:

controller function:

function checkuser()
    $form= $_POST;

    if ($userId==false )
        // header('location:'.URL.'login');
        echo '<script>console.log("invalid username or password")</script>';
        // header('location:'.URL.'userpanel');
        echo '<script>console.log("successfull... you are in.")</script>';
    if ($error !='')
        echo '<script>console.log("there is some error")</script>';
        // $data=['error'=>$error];
        // $this->view('login/index',$data);

and the model is:

 function checkUser($form)

        $sql= "select * from tbl_users WHERE email=? and password=?";
        if (sizeof($result)>0 and !empty($email) and !empty($password))
            if ($remember=='on')
                $expiry = time() + (86400 * 7);
        else {
            $error='not found user.';
    return $error;

the link of the controller will be /login/checkuser

I try to send request from flutter with http package but can not give a good result.

please help me about the structure of the code in flutter and how to send the data username and password to server and give feedback from there.

thanks so much. best regards

Solution 1: erpExpert

try something like below

import 'package:http/http.dart' as http;
import 'dart:convert';

userLogin() async {
Map<String, String?> userData = {
  'username': 'username',
  'password': 'password'
http.Response response = await http.post(
  headers: {'youHeader'},
  body: json.encode(userData),

String jsonStr = (response.body);
try {
  final mapData = jsonDecode(jsonStr);
  if (mapData is Map) {
   // var  loginSuccess =  await(AfterLogin.updatesAfterLogin(mapData)); //do other stuffs
  } else {
    return false;
} catch (e, trace) {
  debugPrint("error $e, ${trace.toString()}");
  return false;