Advertisement
Guest User

Untitled

a guest
Jan 10th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.93 KB | None | 0 0
  1. // bagian providers file DataServices.dart
  2.  
  3. import '../utils/config.dart';
  4. import 'dart:convert';
  5. import 'package:http/http.dart' as http;
  6.  
  7.  
  8. class DataServices {
  9.  
  10.   TokenStore(String token){
  11.     Map headers = {
  12.       'X-Authorization': 'Bearer ${token}'
  13.     };
  14.     return headers;
  15.   }
  16.  
  17.   LoginAuthentication(Map credentials) {
  18.     print(credentials);
  19.     return http.post(
  20.       '${Config.baseUrl}/auth/login',
  21.       headers: {
  22.         'X-Requested-With':'XMLHttpRequest',
  23.         'Content-Type':'application/json',
  24.         'Cache-Control':'no-cache'
  25.       },
  26.       body: json.encode(credentials)
  27.     );
  28.   }
  29.  
  30.  
  31. //bagian screen
  32.  
  33.  
  34. void submit() {
  35.     if (this._formKey.currentState.validate()) {
  36.       _formKey.currentState.save();
  37.  
  38.     DataServices().LoginAuthentication({
  39.       "username":_data.email,
  40.       "password": _data.password
  41.     })
  42.     .then((response) => print(json.decode(response.body)));
  43.     }
  44.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement