69 lines
2.1 KiB
Dart
69 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../services/mqtt_service.dart';
|
|
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),
|
|
backgroundColor: isSuccess ? Colors.green.withOpacity(0.8) : Colors.redAccent,
|
|
duration: const Duration(seconds: 3),
|
|
),
|
|
);
|
|
}
|
|
};
|
|
});
|
|
}
|
|
|
|
final List<Widget> _screens = [
|
|
const MonitoringScreen(),
|
|
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,
|
|
backgroundColor: Colors.black,
|
|
selectedItemColor: Colors.green,
|
|
unselectedItemColor: Colors.grey,
|
|
showSelectedLabels: false,
|
|
showUnselectedLabels: false,
|
|
items: const [
|
|
BottomNavigationBarItem(icon: Icon(Icons.grid_view), label: 'Monitoring'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.build), label: 'Control'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.access_time), label: 'Recording'),
|
|
BottomNavigationBarItem(icon: Icon(Icons.person), label: 'Profile'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|