TKK_E32230176/Source-Code-Web/lib/widgets/control_panel.dart

275 lines
10 KiB
Dart

import 'package:flutter/material.dart';
import '../providers/mqtt_provider.dart';
class ControlPanel extends StatelessWidget {
final MQTTProvider provider;
const ControlPanel({super.key, required this.provider});
@override
Widget build(BuildContext context) {
return Card(
elevation: 4,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Header
const Row(
children: [
Icon(Icons.touch_app, color: Colors.blue, size: 28),
SizedBox(width: 12),
Text(
'Kontrol Manual AC',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 20),
// ==================== STATUS SUHU SAAT INI (DIPERBESAR) ====================
Container(
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Colors.orange.shade50,
Colors.orange.shade100,
],
),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.orange.shade300, width: 2),
boxShadow: [
BoxShadow(
color: Colors.orange.withOpacity(0.2),
blurRadius: 8,
offset: const Offset(0, 4),
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.orange.shade200,
borderRadius: BorderRadius.circular(50),
),
child: const Icon(
Icons.thermostat,
size: 32,
color: Colors.white,
),
),
const SizedBox(width: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'SUHU RUANGAN',
style: TextStyle(
fontSize: 12,
letterSpacing: 1.5,
color: Colors.orange,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
'${provider.currentTemp}',
style: const TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
color: Colors.orange,
),
),
const Text(
'°C',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w500,
color: Colors.orange,
),
),
],
),
const SizedBox(height: 4),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 2,
),
decoration: BoxDecoration(
color: Colors.orange.shade200,
borderRadius: BorderRadius.circular(12),
),
child: Text(
'Mode: ${provider.currentMode.toUpperCase()}',
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: Colors.white,
),
),
),
],
),
],
),
),
// Tombol ON/OFF
Row(
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () {
provider.controlAC("on", manual: true);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('🔄 Menyalakan AC...'),
duration: Duration(seconds: 1),
),
);
},
icon: const Icon(Icons.power_settings_new, size: 24),
label: const Text(
'HIDUPKAN AC',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
const SizedBox(width: 16),
Expanded(
child: ElevatedButton.icon(
onPressed: () {
provider.controlAC("off", manual: true);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('🔄 Mematikan AC...'),
duration: Duration(seconds: 1),
),
);
},
icon: const Icon(Icons.power_off, size: 24),
label: const Text(
'MATIKAN AC',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
],
),
const SizedBox(height: 24),
const Divider(thickness: 1),
const SizedBox(height: 16),
// ==================== KONTROL SUHU ====================
const Row(
children: [
Icon(Icons.thermostat, color: Colors.orange, size: 22),
SizedBox(width: 8),
Text(
'Atur Suhu',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 4),
const Text(
'Pilih suhu yang diinginkan (16°C - 30°C)',
style: TextStyle(fontSize: 12, color: Colors.grey),
),
const SizedBox(height: 16),
Wrap(
spacing: 10,
runSpacing: 10,
children: [16, 18, 20, 22, 24, 25, 26, 28, 30].map((temp) {
final isSelected = provider.currentTemp == temp;
return ElevatedButton(
onPressed: () {
provider.controlAC("set_temp_$temp", manual: true);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('🌡️ Set suhu ke $temp°C'),
duration: const Duration(seconds: 1),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: isSelected ? Colors.orange : Colors.grey.shade200,
foregroundColor: isSelected ? Colors.white : Colors.black87,
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
elevation: isSelected ? 4 : 1,
),
child: Text(
'$temp°C',
style: TextStyle(
fontSize: 16,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
),
);
}).toList(),
),
// Pesan error jika koneksi putus
if (provider.connectionStatus != "Connected") ...[
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.red),
),
child: const Row(
children: [
Icon(Icons.wifi_off, color: Colors.red),
SizedBox(width: 8),
Expanded(
child: Text(
'Tidak terhubung ke MQTT. Periksa koneksi broker.',
style: TextStyle(color: Colors.red),
),
),
],
),
),
],
],
),
),
);
}
}