fix: passing data latihan ke pelafalan & delete all komen
This commit is contained in:
parent
76710e8216
commit
b2bde219ae
|
@ -49,13 +49,13 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
|
|
||||||
|
|
||||||
if (peran == 'santri') {
|
if (peran == 'santri') {
|
||||||
router.push("/navigasi"); // Arahkan ke route santri
|
router.push("/navigasi");
|
||||||
} else if (peran == 'pengajar') {
|
} else if (peran == 'pengajar') {
|
||||||
router.push("/navigasiPengajar"); // Arahkan ke route pengajar
|
router.push("/navigasiPengajar");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debugPrint("anjing");
|
debugPrint("anjing");
|
||||||
// Tampilkan error jika login gagal
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('Login Failed: ${response.body}')),
|
SnackBar(content: Text('Login Failed: ${response.body}')),
|
||||||
);
|
);
|
||||||
|
@ -95,30 +95,18 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
// TextField(
|
|
||||||
// controller: emailController,
|
|
||||||
// keyboardType: TextInputType.number,
|
|
||||||
// inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
|
||||||
// decoration: InputDecoration(
|
|
||||||
// prefixIcon: const Icon(Icons.phone, color: Colors.grey),
|
|
||||||
// hintText: "Masukan No Telp",
|
|
||||||
// border: OutlineInputBorder(
|
|
||||||
// borderRadius: BorderRadius.circular(10),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
TextField(
|
TextField(
|
||||||
controller: emailController,
|
controller: emailController,
|
||||||
keyboardType:
|
keyboardType:
|
||||||
TextInputType
|
TextInputType
|
||||||
.emailAddress, // Mengubah keyboard untuk email
|
.emailAddress,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
prefixIcon: const Icon(
|
prefixIcon: const Icon(
|
||||||
Icons.email,
|
Icons.email,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
), // Ikon email
|
),
|
||||||
hintText:
|
hintText:
|
||||||
"Masukkan Email", // Ganti hint text menjadi Masukkan Email
|
"Masukkan Email",
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
|
@ -154,7 +142,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Navigasi ke halaman lupa password
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
"Lupa password?",
|
"Lupa password?",
|
||||||
|
|
|
@ -22,15 +22,15 @@ class _BelajarPageState extends State<BelajarPage> {
|
||||||
_fetchMateri();
|
_fetchMateri();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk mengambil data materi dari API
|
|
||||||
Future<void> _fetchMateri() async {
|
Future<void> _fetchMateri() async {
|
||||||
final response = await http.get(Uri.parse('${BaseUrl.baseUrl}/materi'));
|
final response = await http.get(Uri.parse('${BaseUrl.baseUrl}/materi'));
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
// Mengubah format response JSON yang berisi objek dengan data dalam properti 'data'
|
|
||||||
final Map<String, dynamic> data = json.decode(response.body);
|
final Map<String, dynamic> data = json.decode(response.body);
|
||||||
setState(() {
|
setState(() {
|
||||||
materiList = data['data']; // Mengambil data dari properti 'data'
|
materiList = data['data'];
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,7 +47,7 @@ class _BelajarPageState extends State<BelajarPage> {
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Center(
|
||||||
child: isLoading
|
child: isLoading
|
||||||
? const CircularProgressIndicator() // Menampilkan loading saat data masih dimuat
|
? const CircularProgressIndicator()
|
||||||
: SingleChildScrollView(
|
: SingleChildScrollView(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
|
@ -91,7 +91,7 @@ class _BelajarPageState extends State<BelajarPage> {
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: Container()),
|
Expanded(child: Container()),
|
||||||
Text(
|
Text(
|
||||||
materi['title'], // Menampilkan judul materi
|
materi['title'],
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
@ -99,7 +99,7 @@ class _BelajarPageState extends State<BelajarPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
materi['subtitle'], // Menampilkan subtitle materi
|
materi['subtitle'],
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
|
|
@ -3,13 +3,13 @@ import 'package:go_router/go_router.dart';
|
||||||
import 'package:ta_tahsin/core/baseurl/base_url.dart';
|
import 'package:ta_tahsin/core/baseurl/base_url.dart';
|
||||||
import 'package:ta_tahsin/core/theme.dart';
|
import 'package:ta_tahsin/core/theme.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'dart:convert'; // Untuk parsing JSON
|
import 'dart:convert';
|
||||||
import 'dart:async'; // Untuk timer
|
import 'dart:async';
|
||||||
import 'package:audioplayers/audioplayers.dart'; // Tambahkan audioplayers
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
|
|
||||||
class LatihanPage extends StatefulWidget {
|
class LatihanPage extends StatefulWidget {
|
||||||
final int id; // ID yang diteruskan dari halaman sebelumnya
|
final int id;
|
||||||
final int currentStep; // Menambahkan parameter currentStep
|
final int currentStep;
|
||||||
|
|
||||||
const LatihanPage({super.key, required this.id, required this.currentStep});
|
const LatihanPage({super.key, required this.id, required this.currentStep});
|
||||||
|
|
||||||
|
@ -18,37 +18,46 @@ class LatihanPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _LatihanPageState extends State<LatihanPage> {
|
class _LatihanPageState extends State<LatihanPage> {
|
||||||
late Future<List<dynamic>> latihanData; // Data latihan berdasarkan id_submateri
|
late Future<List<dynamic>> latihanData;
|
||||||
bool isRecording = false; // Menandakan apakah sedang merekam
|
bool isRecording = false;
|
||||||
int timer = 10; // Timer dimulai dari 10 detik
|
int timer = 10;
|
||||||
late Timer countdownTimer; // Timer untuk countdown
|
late Timer countdownTimer;
|
||||||
String timerText = "10"; // Menampilkan countdown timer dalam teks
|
String timerText = "10";
|
||||||
final AudioPlayer _audioPlayer = AudioPlayer(); // Inisialisasi Audioplayer
|
final AudioPlayer _audioPlayer = AudioPlayer();
|
||||||
|
bool isAudioPlaying = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
latihanData = fetchLatihanData(widget.id); // Ambil data latihan berdasarkan id_submateri yang diteruskan
|
latihanData = fetchLatihanData(widget.id);
|
||||||
|
|
||||||
|
_audioPlayer.onPlayerStateChanged.listen((PlayerState state) {
|
||||||
|
if (state == PlayerState.completed) {
|
||||||
|
setState(() {
|
||||||
|
isAudioPlaying = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk mengambil data latihan dari API
|
|
||||||
Future<List<dynamic>> fetchLatihanData(int id_submateri) async {
|
Future<List<dynamic>> fetchLatihanData(int id_submateri) async {
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse('${BaseUrl.baseUrl}/latihan/$id_submateri'), // Gantilah dengan URL API yang sesuai
|
Uri.parse('${BaseUrl.baseUrl}/latihan/$id_submateri'),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return json.decode(response.body)['data']; // Parse data latihan dari API
|
return json.decode(response.body)['data'];
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Failed to load latihan');
|
throw Exception('Failed to load latihan');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk mulai countdown timer
|
|
||||||
void startTimer() {
|
void startTimer() {
|
||||||
setState(() {
|
setState(() {
|
||||||
isRecording = true; // Set to true when starting to record
|
isRecording = true;
|
||||||
timer = 10; // Reset timer to 10 seconds
|
timer = 10;
|
||||||
timerText = timer.toString();
|
timerText = timer.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,28 +70,31 @@ class _LatihanPageState extends State<LatihanPage> {
|
||||||
} else {
|
} else {
|
||||||
countdownTimer.cancel();
|
countdownTimer.cancel();
|
||||||
setState(() {
|
setState(() {
|
||||||
isRecording = false; // Stop recording after timer ends
|
isRecording = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk menghentikan timer dan reset ke kondisi semula
|
|
||||||
void stopTimer() {
|
void stopTimer() {
|
||||||
countdownTimer.cancel();
|
countdownTimer.cancel();
|
||||||
setState(() {
|
setState(() {
|
||||||
isRecording = false; // Stop recording
|
isRecording = false;
|
||||||
timer = 10; // Reset timer
|
timer = 10;
|
||||||
timerText = timer.toString();
|
timerText = timer.toString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk memutar audio dari asset berdasarkan URL yang diterima
|
|
||||||
void playAudio(String audioUrl) async {
|
void playAudio(String audioUrl) async {
|
||||||
// Menggunakan AssetSource untuk memutar audio dari asset
|
|
||||||
await _audioPlayer.play(AssetSource(audioUrl)); // Gunakan AssetSource untuk audio lokal
|
await _audioPlayer.play(AssetSource(audioUrl));
|
||||||
print("Audio playing...");
|
setState(() {
|
||||||
}
|
isAudioPlaying = true;
|
||||||
|
});
|
||||||
|
print("Audio playing...");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -92,7 +104,7 @@ void playAudio(String audioUrl) async {
|
||||||
leading: IconButton(
|
leading: IconButton(
|
||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.go('/navigasi'); // Navigasi kembali ke halaman utama
|
context.go('/navigasi');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
@ -120,16 +132,16 @@ void playAudio(String audioUrl) async {
|
||||||
future: latihanData,
|
future: latihanData,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return Center(child: CircularProgressIndicator()); // Tampilkan loading selama data dimuat
|
return Center(child: CircularProgressIndicator());
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
return Center(child: Text('Error: ${snapshot.error}')); // Menampilkan pesan error
|
return Center(child: Text('Error: ${snapshot.error}'));
|
||||||
} else if (!snapshot.hasData || snapshot.data == null || snapshot.data!.isEmpty) {
|
} else if (!snapshot.hasData || snapshot.data == null || snapshot.data!.isEmpty) {
|
||||||
return Center(child: Text('Tidak ada latihan tersedia')); // Menampilkan pesan jika tidak ada data latihan
|
return Center(child: Text('Tidak ada latihan tersedia'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ambil data latihan berdasarkan currentStep
|
|
||||||
final latihanList = snapshot.data!;
|
final latihanList = snapshot.data!;
|
||||||
final latihan = latihanList[widget.currentStep]; // Ambil data latihan untuk currentStep
|
final latihan = latihanList[widget.currentStep];
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
|
||||||
|
@ -211,7 +223,7 @@ void playAudio(String audioUrl) async {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
latihan['potongan_ayat'], // Menampilkan potongan ayat dari data latihan
|
latihan['potongan_ayat'],
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 30,
|
fontSize: 30,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
|
@ -221,7 +233,7 @@ void playAudio(String audioUrl) async {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Text(
|
Text(
|
||||||
latihan['latin_text'], // Menampilkan teks latin dari data latihan
|
latihan['latin_text'],
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
|
@ -230,14 +242,14 @@ void playAudio(String audioUrl) async {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: isRecording ? null : () {
|
||||||
// Memutar audio dari asset sesuai dengan URL yang ada pada `correct_audio`
|
|
||||||
playAudio('audio/${latihan['correct_audio']}');
|
playAudio('audio/${latihan['correct_audio']}');
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.volume_up,
|
isAudioPlaying ? Icons.volume_up : Icons.volume_down,
|
||||||
size: 50,
|
size: 50,
|
||||||
color: secondPrimaryColor,
|
color: isRecording ? greysColor : secondPrimaryColor,
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 5.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 5.0),
|
||||||
)
|
)
|
||||||
|
@ -250,29 +262,29 @@ void playAudio(String audioUrl) async {
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: isAudioPlaying ? null : () {
|
||||||
if (!isRecording) {
|
if (!isRecording) {
|
||||||
startTimer(); // Start timer and change to stop icon
|
startTimer();
|
||||||
} else {
|
} else {
|
||||||
stopTimer(); // Stop timer and reset the button
|
stopTimer();
|
||||||
// Pass data to PelafalanPage after recording
|
|
||||||
context.go(
|
context.go(
|
||||||
'/pelafalan',
|
'/pelafalan',
|
||||||
extra: {
|
extra: {
|
||||||
'id': widget.id,
|
'id': widget.id,
|
||||||
'currentStep': widget.currentStep,
|
'currentStep': widget.currentStep,
|
||||||
'latihanData': snapshot.data, // Mengirimkan data latihan yang sudah di-fetch
|
'latihanData': snapshot.data,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: secondPrimaryColor,
|
backgroundColor: isAudioPlaying ? greysColor : secondPrimaryColor,
|
||||||
shape: const CircleBorder(),
|
shape: const CircleBorder(),
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(10),
|
||||||
),
|
),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
isRecording ? Icons.stop : Icons.mic, // Toggle between mic and stop icon
|
isRecording ? Icons.stop : Icons.mic,
|
||||||
size: 40,
|
size: 40,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
|
@ -280,6 +292,7 @@ void playAudio(String audioUrl) async {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -291,7 +304,7 @@ void playAudio(String audioUrl) async {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_audioPlayer.dispose(); // Jangan lupa untuk melepaskan player
|
_audioPlayer.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import 'package:ta_tahsin/core/theme.dart';
|
||||||
class PelafalanPage extends StatelessWidget {
|
class PelafalanPage extends StatelessWidget {
|
||||||
final int id;
|
final int id;
|
||||||
final int currentStep;
|
final int currentStep;
|
||||||
final List<dynamic> latihanData; // Menerima semua data latihan
|
final List<dynamic> latihanData;
|
||||||
|
|
||||||
const PelafalanPage({
|
const PelafalanPage({
|
||||||
super.key,
|
super.key,
|
||||||
|
@ -16,7 +16,7 @@ class PelafalanPage extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Ambil data latihan berdasarkan currentStep
|
|
||||||
final latihan = latihanData[currentStep];
|
final latihan = latihanData[currentStep];
|
||||||
|
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ class PelafalanPage extends StatelessWidget {
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Logic to view video
|
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Lihat Video',
|
'Lihat Video',
|
||||||
|
@ -165,7 +165,7 @@ class PelafalanPage extends StatelessWidget {
|
||||||
context.go(
|
context.go(
|
||||||
'/latihan',
|
'/latihan',
|
||||||
extra: {
|
extra: {
|
||||||
'id': id, // ganti sesuai kebutuhan
|
'id': id,
|
||||||
'currentStep': currentStep + 1,
|
'currentStep': currentStep + 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -196,9 +196,9 @@ class PelafalanPage extends StatelessWidget {
|
||||||
context.go(
|
context.go(
|
||||||
'/latihan',
|
'/latihan',
|
||||||
extra: {
|
extra: {
|
||||||
'id': 1, // Ganti sesuai kebutuhan
|
'id': id,
|
||||||
'currentStep': currentStep,
|
'currentStep': currentStep,
|
||||||
'latihanData': latihanData, // Mengirimkan data latihan yang sesuai
|
'latihanData': latihanData,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,34 +23,34 @@ class MateriPage extends StatefulWidget {
|
||||||
|
|
||||||
class _MateriPageState extends State<MateriPage> {
|
class _MateriPageState extends State<MateriPage> {
|
||||||
late Future<List<dynamic>> kategoriData;
|
late Future<List<dynamic>> kategoriData;
|
||||||
bool isLoading = true; // Variabel untuk mengatur status loading
|
bool isLoading = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
kategoriData = fetchKategoriData(widget.id); // Ambil kategori berdasarkan id materi
|
kategoriData = fetchKategoriData(widget.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk mengambil kategori berdasarkan id_materi
|
|
||||||
Future<List<dynamic>> fetchKategoriData(int id_materi) async {
|
Future<List<dynamic>> fetchKategoriData(int id_materi) async {
|
||||||
final response = await http.get(Uri.parse('${BaseUrl.baseUrl}/kategori/$id_materi'));
|
final response = await http.get(Uri.parse('${BaseUrl.baseUrl}/kategori/$id_materi'));
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoading = false; // Set isLoading ke false setelah data kategori berhasil diambil
|
isLoading = false;
|
||||||
});
|
});
|
||||||
return json.decode(response.body)['data']; // Parse JSON response ke List kategori
|
return json.decode(response.body)['data'];
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Failed to load kategori');
|
throw Exception('Failed to load kategori');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fungsi untuk mengambil sub-materi berdasarkan id_kategori
|
|
||||||
Future<List<dynamic>> fetchSubMateriData(int id_kategori) async {
|
Future<List<dynamic>> fetchSubMateriData(int id_kategori) async {
|
||||||
final response = await http.get(Uri.parse('${BaseUrl.baseUrl}/sub_materi/$id_kategori'));
|
final response = await http.get(Uri.parse('${BaseUrl.baseUrl}/sub_materi/$id_kategori'));
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return json.decode(response.body)['data']['sub_materi']; // Parse JSON response ke List sub-materi
|
return json.decode(response.body)['data']['sub_materi'];
|
||||||
} else {
|
} else {
|
||||||
throw Exception('Failed to load sub-materi');
|
throw Exception('Failed to load sub-materi');
|
||||||
}
|
}
|
||||||
|
@ -60,15 +60,15 @@ class _MateriPageState extends State<MateriPage> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: PreferredSize(
|
appBar: PreferredSize(
|
||||||
preferredSize: Size.fromHeight(50), // Ukuran tinggi AppBar
|
preferredSize: Size.fromHeight(50),
|
||||||
child: Card(
|
child: Card(
|
||||||
elevation: 4, // Menambahkan shadow
|
elevation: 4,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.zero, // Tidak ada radius, sudut tajam
|
borderRadius: BorderRadius.zero,
|
||||||
),
|
),
|
||||||
margin: EdgeInsets.zero, // Menghilangkan margin Card
|
margin: EdgeInsets.zero,
|
||||||
child: AppBar(
|
child: AppBar(
|
||||||
backgroundColor: secondPrimaryColor, // Warna AppBar (sesuaikan dengan secondPrimaryColor)
|
backgroundColor: secondPrimaryColor,
|
||||||
title: Text(
|
title: Text(
|
||||||
widget.title,
|
widget.title,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
@ -88,16 +88,16 @@ class _MateriPageState extends State<MateriPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
body: isLoading
|
body: isLoading
|
||||||
? Center(child: CircularProgressIndicator()) // Tampilkan loading spinner selama proses loading
|
? Center(child: CircularProgressIndicator())
|
||||||
: FutureBuilder<List<dynamic>>(
|
: FutureBuilder<List<dynamic>>(
|
||||||
future: kategoriData,
|
future: kategoriData,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return Center(child: CircularProgressIndicator()); // Tampilkan loading saat menunggu
|
return Center(child: CircularProgressIndicator());
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
return Center(child: Text('Error: ${snapshot.error}')); // Tampilkan error jika ada masalah
|
return Center(child: Text('Error: ${snapshot.error}'));
|
||||||
} else if (!snapshot.hasData || snapshot.data == null) {
|
} else if (!snapshot.hasData || snapshot.data == null) {
|
||||||
return Center(child: Text('Tidak ada data tersedia')); // Tampilkan jika data kosong
|
return Center(child: Text('Tidak ada data tersedia'));
|
||||||
}
|
}
|
||||||
|
|
||||||
final kategoriList = snapshot.data!;
|
final kategoriList = snapshot.data!;
|
||||||
|
@ -126,13 +126,13 @@ class _MateriPageState extends State<MateriPage> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// SliverList untuk kategori dan sub-materi
|
|
||||||
for (var kategori in kategoriList)
|
for (var kategori in kategoriList)
|
||||||
FutureBuilder<List<dynamic>>(
|
FutureBuilder<List<dynamic>>(
|
||||||
future: fetchSubMateriData(kategori['id']), // Ambil submateri untuk kategori ini
|
future: fetchSubMateriData(kategori['id']),
|
||||||
builder: (context, subMateriSnapshot) {
|
builder: (context, subMateriSnapshot) {
|
||||||
if (subMateriSnapshot.connectionState == ConnectionState.waiting) {
|
if (subMateriSnapshot.connectionState == ConnectionState.waiting) {
|
||||||
return SliverToBoxAdapter(child: SizedBox()); // Tidak ada loading spinner lagi
|
return SliverToBoxAdapter(child: SizedBox());
|
||||||
} else if (subMateriSnapshot.hasError) {
|
} else if (subMateriSnapshot.hasError) {
|
||||||
return SliverToBoxAdapter(child: Center(child: Text('Error: ${subMateriSnapshot.error}')));
|
return SliverToBoxAdapter(child: Center(child: Text('Error: ${subMateriSnapshot.error}')));
|
||||||
} else if (!subMateriSnapshot.hasData || subMateriSnapshot.data == null) {
|
} else if (!subMateriSnapshot.hasData || subMateriSnapshot.data == null) {
|
||||||
|
@ -144,11 +144,11 @@ class _MateriPageState extends State<MateriPage> {
|
||||||
return SliverList(
|
return SliverList(
|
||||||
delegate: SliverChildListDelegate(
|
delegate: SliverChildListDelegate(
|
||||||
[
|
[
|
||||||
// Menampilkan nama kategori sekali
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 5.0),
|
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 5.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
kategori['nama_kategori'], // Menampilkan nama kategori
|
kategori['nama_kategori'],
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
@ -156,7 +156,7 @@ class _MateriPageState extends State<MateriPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Menampilkan sub-materi yang terkait dengan kategori ini
|
|
||||||
for (var submateri in subMateriList)
|
for (var submateri in subMateriList)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 0),
|
padding: const EdgeInsets.only(bottom: 0),
|
||||||
|
@ -198,7 +198,7 @@ class _MateriPageState extends State<MateriPage> {
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.push(
|
context.push(
|
||||||
'/submateri', // Gantilah dengan rute yang sesuai
|
'/submateri',
|
||||||
extra: {
|
extra: {
|
||||||
'id': submateri['id'],
|
'id': submateri['id'],
|
||||||
'title': submateri['title'],
|
'title': submateri['title'],
|
||||||
|
|
|
@ -9,38 +9,38 @@ class ProfilePage extends StatelessWidget {
|
||||||
const ProfilePage({super.key});
|
const ProfilePage({super.key});
|
||||||
|
|
||||||
Future<void> logout(BuildContext context) async {
|
Future<void> logout(BuildContext context) async {
|
||||||
// Ambil token yang ada di SharedPreferences
|
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
String? token = prefs.getString('token');
|
String? token = prefs.getString('token');
|
||||||
|
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
// Panggil API logout untuk menghapus token di server
|
|
||||||
final response = await http.post(
|
final response = await http.post(
|
||||||
Uri.parse('${BaseUrl.baseUrl}/logout'), // Ganti dengan URL API logout
|
Uri.parse('${BaseUrl.baseUrl}/logout'),
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': 'Bearer $token', // Kirim token di header
|
'Authorization': 'Bearer $token',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
// Jika berhasil logout, hapus token dari SharedPreferences
|
|
||||||
prefs.remove('token');
|
prefs.remove('token');
|
||||||
|
|
||||||
// Arahkan pengguna ke halaman login atau halaman lain setelah logout
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('Berhasil logout!')),
|
SnackBar(content: Text('Berhasil logout!')),
|
||||||
);
|
);
|
||||||
|
|
||||||
// ignore: use_build_context_synchronously
|
|
||||||
context.go('/login');
|
context.go('/login');
|
||||||
} else {
|
} else {
|
||||||
// Jika ada error dari server
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('Gagal logout: ${response.body}')),
|
SnackBar(content: Text('Gagal logout: ${response.body}')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Jika tidak ada token yang tersimpan
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('Token tidak ditemukan')),
|
SnackBar(content: Text('Token tidak ditemukan')),
|
||||||
);
|
);
|
||||||
|
@ -64,7 +64,7 @@ class ProfilePage extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
// Profile Section with Gradient Card
|
|
||||||
Card(
|
Card(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
|
@ -85,7 +85,7 @@ class ProfilePage extends StatelessWidget {
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
// Profile Avatar
|
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
radius: 50,
|
radius: 50,
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
|
@ -93,7 +93,7 @@ class ProfilePage extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
|
|
||||||
// Name and Phone Number to the right
|
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
@ -118,7 +118,7 @@ class ProfilePage extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|
||||||
// "Hasil Placement Test" Section with Gradient Card
|
|
||||||
Card(
|
Card(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
|
@ -141,11 +141,11 @@ class ProfilePage extends StatelessWidget {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
_buildTestResultSection("Tgl Lahir", "-"),
|
_buildTestResultSection("Tgl Lahir", "-"),
|
||||||
Divider(color: Colors.white), // White Divider for contrast
|
Divider(color: Colors.white),
|
||||||
_buildTestResultSection("Alamat", "-"),
|
_buildTestResultSection("Alamat", "-"),
|
||||||
Divider(color: Colors.white), // White Divider for contrast
|
Divider(color: Colors.white),
|
||||||
_buildTestResultSection("Nama Orang Tua", "-"),
|
_buildTestResultSection("Nama Orang Tua", "-"),
|
||||||
Divider(color: Colors.white), // White Divider for contrast
|
Divider(color: Colors.white),
|
||||||
_buildTestResultSection("email", "-"),
|
_buildTestResultSection("email", "-"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -177,7 +177,7 @@ class ProfilePage extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to build test result sections
|
|
||||||
Widget _buildTestResultSection(String label, String value) {
|
Widget _buildTestResultSection(String label, String value) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5),
|
padding: const EdgeInsets.symmetric(vertical: 5),
|
||||||
|
@ -188,7 +188,7 @@ class ProfilePage extends StatelessWidget {
|
||||||
label,
|
label,
|
||||||
style: TextStyle(fontSize: 16, color: Colors.white),
|
style: TextStyle(fontSize: 16, color: Colors.white),
|
||||||
),
|
),
|
||||||
SizedBox(height: 6), // Space between label and value
|
SizedBox(height: 6),
|
||||||
Text(
|
Text(
|
||||||
value,
|
value,
|
||||||
style: TextStyle(fontSize: 16, color: Colors.white),
|
style: TextStyle(fontSize: 16, color: Colors.white),
|
||||||
|
@ -198,7 +198,7 @@ class ProfilePage extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to create info links
|
|
||||||
Widget _buildInfoLink(String label) {
|
Widget _buildInfoLink(String label) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5),
|
padding: const EdgeInsets.symmetric(vertical: 5),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:ta_tahsin/core/theme.dart';
|
import 'package:ta_tahsin/core/theme.dart';
|
||||||
import 'package:youtube_player_flutter/youtube_player_flutter.dart'; // Import youtube_player_flutter
|
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
|
||||||
|
|
||||||
class SubMateriPage extends StatefulWidget {
|
class SubMateriPage extends StatefulWidget {
|
||||||
final int id;
|
final int id;
|
||||||
|
@ -39,16 +39,16 @@ class _SubMateriPageState extends State<SubMateriPage> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: PreferredSize(
|
appBar: PreferredSize(
|
||||||
preferredSize: Size.fromHeight(50), // Ukuran tinggi AppBar
|
preferredSize: Size.fromHeight(50),
|
||||||
child: Card(
|
child: Card(
|
||||||
elevation: 4, // Menambahkan shadow
|
elevation: 4,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.zero, // Tidak ada radius, sudut tajam
|
borderRadius: BorderRadius.zero,
|
||||||
),
|
),
|
||||||
margin: EdgeInsets.zero, // Menghilangkan margin Card
|
margin: EdgeInsets.zero,
|
||||||
child: AppBar(
|
child: AppBar(
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
secondPrimaryColor, // Warna AppBar (sesuaikan dengan secondPrimaryColor)
|
secondPrimaryColor,
|
||||||
title: Text(
|
title: Text(
|
||||||
widget.title,
|
widget.title,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
|
@ -61,7 +61,7 @@ class _SubMateriPageState extends State<SubMateriPage> {
|
||||||
icon: const Icon(Icons.arrow_back),
|
icon: const Icon(Icons.arrow_back),
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context); // Aksi kembali
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -129,8 +129,8 @@ class _SubMateriPageState extends State<SubMateriPage> {
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.go(
|
context.go(
|
||||||
'/latihan', // Gantilah dengan rute yang sesuai
|
'/latihan',
|
||||||
extra: {'id': widget.id}, // Mengirimkan id dari halaman sebelumnya
|
extra: {'id': widget.id},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|
Loading…
Reference in New Issue