Created
April 21, 2022 23:21
-
-
Save fleetimee/96f558a7807c4969c6a5b996e1025664 to your computer and use it in GitHub Desktop.
L
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User{ | |
int id; | |
String username, email, nama_lengkap; | |
User({this.id, this.username, this.email, this.nama_lengkap}); | |
factory User.fromJson(Map<String, dynamic> json){ | |
return User( | |
id: json['id'], | |
username: json['username'], | |
email: json['email'], | |
nama_lengkap: json['nama_lengkap'], | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter_auth/models/User.dart'; | |
import 'api.dart'; | |
import 'dart:convert'; | |
class UserService{ | |
static String baseUrl = "tbluser"; | |
static Future<List<User>> getUser() async { | |
final response = await Network().getData(baseUrl); | |
List<User> list = parseResponse(response.body); | |
return list; | |
} | |
static List<User> parseResponse(String responseBody) { | |
final parsed = json.decode(responseBody).cast<Map<String, dynamic>>(); | |
return parsed.map<User>((json) => User.fromJson(json)).toList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment