added Home and Produk Page
This commit is contained in:
85
boss_app/lib/controller/boss_controller.dart
Normal file
85
boss_app/lib/controller/boss_controller.dart
Normal file
@ -0,0 +1,85 @@
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
// ignore: unused_import
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
//create class LoginController extends ChangeNotifier
|
||||
class BossController extends ChangeNotifier {
|
||||
//create future string login , parameter is String username and password
|
||||
Future<Map> ambilLaporan(
|
||||
String tanggal, String bulan, String tahun, String filter) async {
|
||||
//create string result
|
||||
Map<String, dynamic> result;
|
||||
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
"http://192.168.43.125/ilham/server2/api/ambil_laporan?tanggal=$tanggal&bulan=$bulan&tahun=$tahun&filter=$filter"),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"authorization":
|
||||
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
|
||||
"crossDomain": "true"
|
||||
});
|
||||
final data = jsonDecode(response.body);
|
||||
result = data;
|
||||
// print(result);
|
||||
} catch (e) {
|
||||
result = {"status": "error", "message": e.toString()};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Map> ambilLaporanDetail(String no_log) async {
|
||||
//create string result
|
||||
Map<String, dynamic> result;
|
||||
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
"http://192.168.43.125/ilham/server2/api/ambil_laporan_detail?no_log=$no_log"),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"authorization":
|
||||
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
|
||||
"crossDomain": "true"
|
||||
});
|
||||
|
||||
final data = jsonDecode(response.body);
|
||||
// print(data);
|
||||
result = data;
|
||||
} catch (e) {
|
||||
result = {"status": "error", "message": e.toString()};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Map> ambilProdukAll(int pageNumber, String filter) async {
|
||||
Map<String, dynamic> result;
|
||||
|
||||
try {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
"http://192.168.43.125/ilham/server2/api/ambil_produk_all?page=$pageNumber&filter=$filter"),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"authorization":
|
||||
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
|
||||
"crossDomain": "true"
|
||||
});
|
||||
|
||||
final data = jsonDecode(response.body);
|
||||
// print(data['data2']);
|
||||
result = data;
|
||||
} catch (e) {
|
||||
result = {"status": "error", "message": e.toString()};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
30
boss_app/lib/controller/datatables_laporan.dart
Normal file
30
boss_app/lib/controller/datatables_laporan.dart
Normal file
@ -0,0 +1,30 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyData extends DataTableSource {
|
||||
// Generate some made-up data
|
||||
final List<Map<String, dynamic>> _data = List.generate(
|
||||
200,
|
||||
(index) => {
|
||||
"id": index,
|
||||
"title": "Item $index",
|
||||
"price": Random().nextInt(10000),
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
bool get isRowCountApproximate => false;
|
||||
@override
|
||||
int get rowCount => _data.length;
|
||||
@override
|
||||
int get selectedRowCount => 0;
|
||||
@override
|
||||
DataRow getRow(int index) {
|
||||
return DataRow(cells: [
|
||||
DataCell(Text(_data[index]['id'].toString())),
|
||||
DataCell(Text(_data[index]["title"])),
|
||||
DataCell(Text(_data[index]["price"].toString())),
|
||||
]);
|
||||
}
|
||||
}
|
||||
82
boss_app/lib/controller/login_controller.dart
Normal file
82
boss_app/lib/controller/login_controller.dart
Normal file
@ -0,0 +1,82 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
//create class LoginController extends ChangeNotifier
|
||||
class LoginController extends ChangeNotifier {
|
||||
//create future string login , parameter is String username and password
|
||||
Future<String> login(String username, String password) async {
|
||||
late String _returnString;
|
||||
// print("sini dia");
|
||||
|
||||
try {
|
||||
//create final sharedPreferences
|
||||
final sharedPreferences = await SharedPreferences.getInstance();
|
||||
|
||||
//create http get wih basic auth
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
"http://192.168.43.125/ilham/server2/api/login_user?username=$username&password=$password"),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"authorization":
|
||||
"Basic ${base64Encode(utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73"))}",
|
||||
"crossDomain": "true"
|
||||
});
|
||||
final data = jsonDecode(response.body);
|
||||
// print(response.statusCode);
|
||||
if (response.statusCode == 200) {
|
||||
if (data['data']['level'] == '0') {
|
||||
sharedPreferences.setString('level', 'Superadmin');
|
||||
} else if (data['data']['level'] == '1') {
|
||||
sharedPreferences.setString('level', 'Boss');
|
||||
}
|
||||
_returnString = "1";
|
||||
sharedPreferences.setString('data', jsonEncode(data['data']));
|
||||
} else if (response.statusCode == 401) {
|
||||
_returnString = "2";
|
||||
}
|
||||
} catch (e) {
|
||||
// print(e);
|
||||
_returnString = "3";
|
||||
}
|
||||
|
||||
//return result
|
||||
return _returnString;
|
||||
}
|
||||
|
||||
// Future<Map> login(String username, String password) async {
|
||||
// //create string result
|
||||
// // String result = "try";
|
||||
// //create map data
|
||||
// Map datanya;
|
||||
// //create http get wih basic auth
|
||||
// var response = await http.get(
|
||||
// Uri.parse(
|
||||
// "http://192.168.43.125/ilham/server2/api/login_user?username=$username&password=$password"),
|
||||
// headers: {
|
||||
// "Accept": "application/json",
|
||||
// "authorization": "Basic " +
|
||||
// base64Encode(
|
||||
// utf8.encode("Kicap_karan:bb10c6d9f01ec0cb16726b59e36c2f73")),
|
||||
// "crossDomain": "true"
|
||||
// });
|
||||
// final data = jsonDecode(response.body);
|
||||
// // print(data["message"][0]['username']);
|
||||
// datanya = data;
|
||||
// print(response.statusCode);
|
||||
// // switch (response.statusCode) {
|
||||
// // case 200:
|
||||
// // final data = response.body;
|
||||
// // print(data);
|
||||
// // break;
|
||||
// // default:
|
||||
// // }
|
||||
|
||||
//return result
|
||||
// return datanya;
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user