Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:http/http.dart' as http;
- class LoginModel {
- String message;
- String profileid;
- String username;
- String namaumkm;
- String email;
- String statususer;
- LoginModel(
- {this.message,
- this.profileid,
- this.username,
- this.namaumkm,
- this.email,
- this.statususer});
- //return data from json
- factory LoginModel.resultLogin(Map<String, dynamic> obj) {
- return LoginModel(
- message: obj['message'],
- profileid: obj['PROFILEUSERS_ID'],
- username: obj['USERNAME'],
- namaumkm: obj['NAMAUMKM'],
- email: obj['email'],
- statususer: obj['STATUSUSER']);
- }
- //method to API
- static Future<LoginModel> connectLoginAPI(
- String email, String password) async {
- String url = "http://10.0.2.2:8000/api/login";
- var apiResult = await http.post(url, headers: {
- 'accept': 'application/json'
- }, body: {
- "email": email,
- "password": password,
- });
- var jsonObject = json.decode(apiResult.body);
- if (jsonObject['success']) {
- return LoginModel.resultLogin(jsonObject);
- } else {
- return LoginModel.resultLogin(jsonObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement