Untitled
raw download clone
DART
views 12
,
size 2162 b
Future<Null> _login() async {
    print("Login");
    try {
      _showLoading("Please Wait...");
      SharedPreferences prefs = await SharedPreferences.getInstance();
      var dtUname = usernameController.text;
      var dtPass = passwordHash;

      return http.post(await Env().postLoginCluster(), body: {
        "username": dtUname,
        "password": dtPass,
      }).then((response) {
        // print("Response");
        print(response.body);

        final body = jsonDecode(response.body);

        if (body["code"] == "00") {
          prefs.setString("userId", body['data']['userid']);
          prefs.setString("canvaserId", body['data']['canvaserid']);
          prefs.setString("userName", body['data']['name']);
          prefs.setInt("userRole", body['data']['role']);
          prefs.setInt("userClusterId", body['data']['cluster']);
          prefs.setString("userClusterName", body['data']['cluster_name']);
          prefs.setString("userReffCode", body['data']['reff_code']);

          setState(() {
            Navigator.pop(context);
            Navigator.pushReplacement(
              context,
              MaterialPageRoute(
                builder: (context) => MainScreen(),
              ),
            );
          });
        } else {
          setState(() {
            Navigator.pop(context);
          });
          showDialog(
            barrierDismissible: false,
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: Text(body['data']['message']),
                // content: Text(body['data']),
                actions: <Widget>[
                  new RaisedButton(
                    child: Text('Ok'),
                    textColor: Colors.grey,
                    onPressed: () {
                      Navigator.pop(context);
                    },
                  ),
                ],
              );
            },
          );
        }
      }).catchError((error) {
        print(error);
      });
    } catch (e) {
      print(e);
    }
    return null;
  }
close fullscreen
Login or Register to edit or fork this paste. It's free.