TKK_E32221196/lib/app/modules/notifikasi/views/notifikasi_view.dart

120 lines
4.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import '../controllers/notifikasi_controller.dart';
class NotifikasiView extends GetView<NotifikasiController> {
const NotifikasiView({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white, // Light background color for the page
appBar: AppBar(
title: Text(
'Notifikasi',
style: GoogleFonts.poppins(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
centerTitle: true,
backgroundColor: Colors.blue,
elevation: 4, // Slight elevation for the app bar
automaticallyImplyLeading: true,
iconTheme: const IconThemeData(color: Colors.white),
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 16.0),
child: Column(
children: [
// Daftar Notifikasi
Expanded(
child: Obx(() {
final list = controller.notifikasiList;
if (list.isEmpty) {
return const Center(
child: Text(
"Belum ada notifikasi.",
style: TextStyle(fontSize: 16, color: Colors.grey),
),
);
}
return ListView.builder(
itemCount: list.length,
itemBuilder: (context, index) {
final item = list[index];
return Dismissible(
key: Key(item['waktu'] ?? 'unique_key_$index'), // Ensure unique key
background: Container(
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.centerLeft,
child: const Icon(Icons.delete, color: Colors.grey),
),
secondaryBackground: Container(
color: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 20),
alignment: Alignment.centerRight,
child: const Icon(Icons.delete, color: Colors.grey),
),
onDismissed: (_) => controller.hapusNotifikasi(item['waktu'] ?? ''),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 5,
margin: const EdgeInsets.only(bottom: 15),
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item['judul'] ?? 'No Title', // Default value if 'judul' is null
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
const SizedBox(height: 8),
Text(
item['deskripsi'] ?? 'No Description', // Default value if 'deskripsi' is null
style: GoogleFonts.poppins(
fontSize: 14,
color: Colors.grey[700],
),
),
const SizedBox(height: 10),
Align(
alignment: Alignment.bottomRight,
child: Text(
item['waktu'] ?? 'No Time', // Default value if 'waktu' is null
style: GoogleFonts.poppins(
fontSize: 12,
color: Colors.grey[600],
),
),
),
],
),
),
),
);
},
);
}),
),
],
),
),
),
);
}
}