Skip to content

Commit

Permalink
page cek ongkir
Browse files Browse the repository at this point in the history
  • Loading branch information
vandyahmad24 committed Jul 21, 2024
1 parent 5396d7e commit f9af3de
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

.env
8 changes: 8 additions & 0 deletions assets/models/city.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"city_id": "39",
"province_id": "5",
"province": "DI Yogyakarta",
"type": "Kabupaten",
"city_name": "Bantul",
"postal_code": "55700"
}
4 changes: 4 additions & 0 deletions assets/models/province.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"province_id": "12",
"province": "Kalimantan Barat"
}
4 changes: 4 additions & 0 deletions assets/models/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"province_id": "12",
"province": "Kalimantan Barat"
}
7 changes: 7 additions & 0 deletions lib/app/config/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:flutter_dotenv/flutter_dotenv.dart';

class Config {
// Inisialisasi variabel yang diambil dari .env
static String get apiUrl => dotenv.env['API_URL'] ?? '';
static String get apiKey => dotenv.env['API_KEY'] ?? '';
}
41 changes: 41 additions & 0 deletions lib/app/data/models/city_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class City {
String? cityId;
String? provinceId;
String? province;
String? type;
String? cityName;
String? postalCode;

City(
{this.cityId,
this.provinceId,
this.province,
this.type,
this.cityName,
this.postalCode});

City.fromJson(Map<String, dynamic> json) {
cityId = json['city_id'];
provinceId = json['province_id'];
province = json['province'];
type = json['type'];
cityName = json['city_name'];
postalCode = json['postal_code'];
}

Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['city_id'] = cityId;
data['province_id'] = provinceId;
data['province'] = province;
data['type'] = type;
data['city_name'] = cityName;
data['postal_code'] = postalCode;
return data;
}

static List<City> fromJsonList(List? data){
if(data == null || data.isEmpty) return [];
return data.map((e)=>City.fromJson(e)).toList();
}
}
26 changes: 26 additions & 0 deletions lib/app/data/models/province_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Province {
String? provinceId;
String? province;

Province({this.provinceId, this.province});

Province.fromJson(Map<String, dynamic> json) {
provinceId = json['province_id'];
province = json['province'];
}

Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['province_id'] = provinceId;
data['province'] = province;
return data;
}

static List<Province> fromJsonList(List? data){
if(data == null || data.isEmpty) return [];
return data.map((e)=>Province.fromJson(e)).toList();
}

@override
String toString() => province!;
}
22 changes: 22 additions & 0 deletions lib/app/data/providers/city_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:get/get.dart';

import '../models/city_model.dart';

class CityProvider extends GetConnect {
@override
void onInit() {
httpClient.defaultDecoder = (map) {
if (map is Map<String, dynamic>) return City.fromJson(map);
if (map is List) return map.map((item) => City.fromJson(item)).toList();
};
httpClient.baseUrl = 'YOUR-API-URL';
}

Future<City?> getCity(int id) async {
final response = await get('city/$id');
return response.body;
}

Future<Response<City>> postCity(City city) async => await post('city', city);
Future<Response> deleteCity(int id) async => await delete('city/$id');
}
24 changes: 24 additions & 0 deletions lib/app/data/providers/province_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:get/get.dart';

import '../models/province_model.dart';

class ProvinceProvider extends GetConnect {
@override
void onInit() {
httpClient.defaultDecoder = (map) {
if (map is Map<String, dynamic>) return Province.fromJson(map);
if (map is List)
return map.map((item) => Province.fromJson(item)).toList();
};
httpClient.baseUrl = 'YOUR-API-URL';
}

Future<Province?> getProvince(int id) async {
final response = await get('province/$id');
return response.body;
}

Future<Response<Province>> postProvince(Province province) async =>
await post('province', province);
Future<Response> deleteProvince(int id) async => await delete('province/$id');
}
24 changes: 5 additions & 19 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import 'package:get/get.dart';
import 'package:get/get_rx/get_rx.dart';

class HomeController extends GetxController {
//TODO: Implement HomeController

final count = 0.obs;
@override
void onInit() {
super.onInit();
}

@override
void onReady() {
super.onReady();
}

@override
void onClose() {
super.onClose();
}

void increment() => count.value++;
RxString provAsalId="".obs;
RxString cityAsalId="".obs;
RxString provTujuanId="".obs;
RxString cityTujuanId="".obs;
}
Loading

0 comments on commit f9af3de

Please sign in to comment.