80 lines
2.8 KiB
Dart
80 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../services/mqtt_service.dart';
|
|
import '../constants/app_colors.dart'; // <-- IMPORT APP COLORS DITAMBAHKAN
|
|
import 'monitoring_screen.dart';
|
|
import 'control_settings_screen.dart';
|
|
import 'recording_screen.dart';
|
|
import 'settings_screen.dart';
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
int _currentIndex = 0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Listen for MQTT connection results to show notifications
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
final mqtt = Provider.of<MqttService>(context, listen: false);
|
|
mqtt.onConnectionResult = (message, isSuccess) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(
|
|
message,
|
|
// Opsional: Teks putih agar selalu kontras dengan warna notifikasi
|
|
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold)
|
|
),
|
|
// --- BERUBAH: Warna Notifikasi Berhasil / Gagal ---
|
|
backgroundColor: isSuccess
|
|
? AppColors.success.withValues(alpha: 0.9)
|
|
: AppColors.error,
|
|
duration: const Duration(seconds: 3),
|
|
),
|
|
);
|
|
}
|
|
};
|
|
});
|
|
}
|
|
|
|
List<Widget> get _screens => [
|
|
MonitoringScreen(onProfileTap: () => setState(() => _currentIndex = 3)),
|
|
const ControlSettingsScreen(),
|
|
const RecordingScreen(),
|
|
const SettingsScreen(),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: _screens[_currentIndex],
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _currentIndex,
|
|
onTap: (index) => setState(() => _currentIndex = index),
|
|
type: BottomNavigationBarType.fixed,
|
|
// --- BERUBAH: Latar Belakang Menu Navigasi Bawah ---
|
|
backgroundColor: AppColors.cardBg,
|
|
// --- BERUBAH: Warna Ikon yang Sedang Dipilih ---
|
|
selectedItemColor: AppColors.primary,
|
|
// --- BERUBAH: Warna Ikon yang Tidak Dipilih ---
|
|
unselectedItemColor: AppColors.textSecondary,
|
|
showSelectedLabels: false,
|
|
showUnselectedLabels: false,
|
|
elevation: 10, // Menambahkan sedikit bayangan agar terpisah dari body
|
|
items: const [
|
|
BottomNavigationBarItem(icon: Icon(Icons.grid_view), label: 'Monitoring'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.tune), label: 'Control'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.access_time), label: 'Recording'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |