update
This commit is contained in:
parent
c90c5356e5
commit
1ff6fc584e
|
|
@ -1,2 +1,2 @@
|
||||||
const String baseUrl = 'http://192.168.1.6:8000/api';
|
const String baseUrl = 'http://192.168.0.118:8000/api';
|
||||||
const String baseImageurl = 'http://192.168.1.6:8000/';
|
const String baseImageurl = 'http://192.168.0.118:8000/';
|
||||||
|
|
@ -55,7 +55,7 @@ class _DashboardPageState extends State<DashboardPage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse('http://192.168.1.6:8000/api/dashboard/$userId'),
|
Uri.parse('http://192.168.0.118:8000/api/dashboard/$userId'),
|
||||||
);
|
);
|
||||||
|
|
||||||
print("STATUS: ${response.statusCode}");
|
print("STATUS: ${response.statusCode}");
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||||
|
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
|
|
||||||
final String apiUrl = "http://192.168.1.6:8000/api/laporan";
|
final String apiUrl = "http://192.168.0.118:8000/api/laporan";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,9 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
// GET PROFILE
|
// GET PROFILE
|
||||||
// ==========================
|
// ==========================
|
||||||
Future getProfile() async {
|
Future getProfile() async {
|
||||||
|
try {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse("http://192.168.1.6:8000/api/profile"),
|
Uri.parse("http://192.168.0.118:8000/api/profile?user_id=4"),
|
||||||
headers: {"Accept": "application/json"},
|
headers: {"Accept": "application/json"},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -40,15 +41,25 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
print("Error API");
|
print("Error API");
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
print("Error: $e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================
|
// ==========================
|
||||||
// PICK IMAGE
|
// PICK IMAGE
|
||||||
// ==========================
|
// ==========================
|
||||||
Future<void> _pickImage() async {
|
Future<void> _pickImage() async {
|
||||||
final XFile? picked = await _picker.pickImage(source: ImageSource.gallery);
|
final XFile? picked =
|
||||||
|
await _picker.pickImage(source: ImageSource.gallery);
|
||||||
|
|
||||||
if (picked != null) {
|
if (picked != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
@ -63,26 +74,49 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
// UPLOAD PHOTO
|
// UPLOAD PHOTO
|
||||||
// ==========================
|
// ==========================
|
||||||
Future uploadPhoto() async {
|
Future uploadPhoto() async {
|
||||||
|
try {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
var request = http.MultipartRequest(
|
var request = http.MultipartRequest(
|
||||||
"POST",
|
"POST",
|
||||||
Uri.parse("http://192.168.1.6:8000/api/upload-photo"),
|
Uri.parse("http://192.168.0.118:8000/api/upload-photo"),
|
||||||
);
|
);
|
||||||
|
|
||||||
request.headers['Accept'] = 'application/json';
|
request.headers['Accept'] = 'application/json';
|
||||||
|
request.fields['user_id'] = user?['id'].toString() ?? "0";
|
||||||
request.fields['user_id'] = user!['id'].toString();
|
|
||||||
|
|
||||||
request.files.add(
|
request.files.add(
|
||||||
await http.MultipartFile.fromPath('profile_photo', _imageFile!.path),
|
await http.MultipartFile.fromPath(
|
||||||
|
'profile_photo',
|
||||||
|
_imageFile!.path,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
var response = await request.send();
|
var streamedResponse = await request.send();
|
||||||
|
var response = await http.Response.fromStream(streamedResponse);
|
||||||
|
|
||||||
|
print(response.statusCode);
|
||||||
|
print(response.body);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_imageFile = null; // reset biar ambil dari server
|
_imageFile = null;
|
||||||
});
|
});
|
||||||
getProfile();
|
|
||||||
|
await getProfile(); // refresh
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
print("Upload gagal");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
print("Error upload: $e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,20 +126,17 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
getProfile();
|
getProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔥 Tambahan supaya refresh saat balik ke halaman ini
|
|
||||||
@override
|
|
||||||
void didChangeDependencies() {
|
|
||||||
super.didChangeDependencies();
|
|
||||||
getProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (isLoading) {
|
// 🔥 ANTI CRASH
|
||||||
return const Center(child: CircularProgressIndicator());
|
if (isLoading || user == null) {
|
||||||
|
return const Scaffold(
|
||||||
|
body: Center(child: CircularProgressIndicator()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return Scaffold(
|
||||||
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -128,14 +159,14 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
backgroundImage: _imageFile != null
|
backgroundImage: _imageFile != null
|
||||||
? FileImage(File(_imageFile!.path))
|
? FileImage(File(_imageFile!.path))
|
||||||
: user!['photo_url'] != null
|
: (user?['photo_url'] != null
|
||||||
// 🔥 CACHE BUSTER DI SINI
|
|
||||||
? NetworkImage(
|
? NetworkImage(
|
||||||
user!['photo_url'] +
|
user!['photo_url'] +
|
||||||
"?t=${DateTime.now().millisecondsSinceEpoch}",
|
"?t=${DateTime.now().millisecondsSinceEpoch}",
|
||||||
)
|
)
|
||||||
: null,
|
: null),
|
||||||
child: user!['photo_url'] == null && _imageFile == null
|
child: (user?['photo_url'] == null &&
|
||||||
|
_imageFile == null)
|
||||||
? const Icon(Icons.person, size: 60)
|
? const Icon(Icons.person, size: 60)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
|
|
@ -143,7 +174,7 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
user!['name'],
|
user?['name'] ?? "-",
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 22,
|
fontSize: 22,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
|
@ -154,7 +185,7 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
user!['role'],
|
user?['role'] ?? "-",
|
||||||
style: const TextStyle(color: Colors.white70),
|
style: const TextStyle(color: Colors.white70),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
@ -184,15 +215,13 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.email),
|
leading: const Icon(Icons.email),
|
||||||
title: const Text("Email"),
|
title: const Text("Email"),
|
||||||
subtitle: Text(user!['email']),
|
subtitle: Text(user?['email'] ?? "-"),
|
||||||
),
|
),
|
||||||
|
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.home),
|
leading: const Icon(Icons.home),
|
||||||
title: const Text("Alamat"),
|
title: const Text("Alamat"),
|
||||||
subtitle: Text(user!['address'] ?? "-"),
|
subtitle: Text(user?['address'] ?? "-"),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
@ -206,11 +235,16 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
Card(
|
Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: const Icon(Icons.logout, color: Colors.red),
|
leading: const Icon(Icons.logout, color: Colors.red),
|
||||||
title: const Text("Logout", style: TextStyle(color: Colors.red)),
|
title: const Text(
|
||||||
|
"Logout",
|
||||||
|
style: TextStyle(color: Colors.red),
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pushAndRemoveUntil(
|
Navigator.pushAndRemoveUntil(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const LoginPage()),
|
MaterialPageRoute(
|
||||||
|
builder: (context) => const LoginPage(),
|
||||||
|
),
|
||||||
(route) => false,
|
(route) => false,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -218,6 +252,7 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue