Skip to content

Instantly share code, notes, and snippets.

@haki-es
Created November 4, 2026 23:23
Show Gist options
  • Select an option

  • Save haki-es/63d3e097f66b1ca6e5f7b9bd41729342 to your computer and use it in GitHub Desktop.

Select an option

Save haki-es/63d3e097f66b1ca6e5f7b9bd41729342 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(const SmartMonitorApp());
/// Palet "midnight neon": navy gelap, ungu, cyan, dan kuning LED.
class AppColors {
static const bg = Color(0xFF0F1226); // latar halaman
static const card = Color(0xFF1A1E3A); // latar kartu
static const cardSoft = Color(0xFF242950);
static const violet = Color(0xFF8B5CF6); // aksen utama
static const text = Color(0xFFFFFFFF); // teks utama
static const muted = Color(0xFF9AA0C3); // teks sekunder
static const heat = Color(0xFFFF6B6B); // suhu
static const water = Color(0xFF22D3EE); // kelembapan
static const led = Color(0xFFFACC15); // LED menyala
static const ok = Color(0xFF4ADE80); // status online
}
class SmartMonitorApp extends StatelessWidget {
const SmartMonitorApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Smart Monitor',
theme: ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(
seedColor: AppColors.violet,
brightness: Brightness.dark,
surface: AppColors.bg,
),
scaffoldBackgroundColor: AppColors.bg,
),
home: const DashboardScreen(),
);
}
}
class DashboardScreen extends StatefulWidget {
const DashboardScreen({super.key});
@override
State<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
bool isLedOn = false;
// Data sensor (nanti bisa diganti data dari ESP32)
final double temperature = 28.5;
final double humidity = 70;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ListView(
padding: const EdgeInsets.fromLTRB(20, 16, 20, 28),
children: [
const _TopBar(),
const SizedBox(height: 24),
const _SectionTitle('Suhu'),
const SizedBox(height: 12),
_TempGauge(
value: temperature,
progress: temperature / 50,
),
const SizedBox(height: 24),
const _SectionTitle('Kelembapan'),
const SizedBox(height: 12),
_HumidityBar(
value: humidity,
progress: humidity / 100,
),
const SizedBox(height: 24),
const _SectionTitle('Jaringan'),
const SizedBox(height: 12),
const _NetworkCard(),
const SizedBox(height: 24),
const _SectionTitle('Kontrol'),
const SizedBox(height: 12),
_LedCard(
isOn: isLedOn,
onChanged: (v) => setState(() => isLedOn = v),
),
],
),
),
);
}
}
// ---------------------------------------------------------------- Top bar
class _TopBar extends StatelessWidget {
const _TopBar();
@override
Widget build(BuildContext context) {
return Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: AppColors.violet.withOpacity(0.2),
borderRadius: BorderRadius.circular(14),
),
child: const Icon(
Icons.sensors_rounded,
color: AppColors.violet,
size: 26,
),
),
const SizedBox(width: 12),
const Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Smart Monitor',
style: TextStyle(
color: AppColors.text,
fontSize: 22,
fontWeight: FontWeight.w800,
),
),
SizedBox(height: 2),
Text(
'Lab IoT sedang terpantau',
style: TextStyle(color: AppColors.muted, fontSize: 13),
),
],
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: AppColors.ok.withOpacity(0.12),
borderRadius: BorderRadius.circular(20),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
_PulseDot(),
SizedBox(width: 6),
Text(
'Online',
style: TextStyle(
color: AppColors.ok,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
],
),
),
],
);
}
}
/// Titik hijau berdenyut: satu-satunya animasi otomatis, menandakan perangkat hidup.
class _PulseDot extends StatefulWidget {
const _PulseDot();
@override
State<_PulseDot> createState() => _PulseDotState();
}
class _PulseDotState extends State<_PulseDot>
with SingleTickerProviderStateMixin {
late final AnimationController _c = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1400),
)..repeat(reverse: true);
@override
void dispose() {
_c.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _c,
builder: (_, __) => Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: AppColors.ok,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: AppColors.ok.withOpacity(0.2 + 0.5 * _c.value),
blurRadius: 3 + 6 * _c.value,
spreadRadius: 1 + 2 * _c.value,
),
],
),
),
);
}
}
// ---------------------------------------------------------------- Komponen
class _SectionTitle extends StatelessWidget {
final String text;
const _SectionTitle(this.text);
@override
Widget build(BuildContext context) {
return Text(
text.toUpperCase(),
style: const TextStyle(
color: AppColors.muted,
fontSize: 12,
letterSpacing: 1.4,
fontWeight: FontWeight.w700,
),
);
}
}
/// Suhu ditampilkan sebagai gauge lingkaran besar.
class _TempGauge extends StatelessWidget {
final double value;
final double progress;
const _TempGauge({required this.value, required this.progress});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: AppColors.card,
borderRadius: BorderRadius.circular(24),
border: Border.all(color: AppColors.heat.withOpacity(0.25)),
),
child: Row(
children: [
SizedBox(
width: 130,
height: 130,
child: Stack(
fit: StackFit.expand,
children: [
CircularProgressIndicator(
value: progress.clamp(0.0, 1.0),
strokeWidth: 10,
strokeCap: StrokeCap.round,
color: AppColors.heat,
backgroundColor: AppColors.heat.withOpacity(0.15),
),
Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
value.toStringAsFixed(1),
style: const TextStyle(
color: AppColors.text,
fontSize: 32,
fontWeight: FontWeight.w800,
height: 1,
),
),
const SizedBox(height: 2),
const Text(
'°C',
style: TextStyle(
color: AppColors.heat,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
],
),
),
],
),
),
const SizedBox(width: 20),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
children: [
Icon(
Icons.device_thermostat_rounded,
color: AppColors.heat,
size: 20,
),
SizedBox(width: 6),
Text(
'Suhu ruangan',
style: TextStyle(color: AppColors.muted, fontSize: 13),
),
],
),
const SizedBox(height: 10),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: AppColors.heat.withOpacity(0.15),
borderRadius: BorderRadius.circular(20),
),
child: const Text(
'Normal',
style: TextStyle(
color: AppColors.heat,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
const SizedBox(height: 10),
const Text(
'Skala 0–50 °C',
style: TextStyle(color: AppColors.muted, fontSize: 12),
),
],
),
),
],
),
);
}
}
/// Kelembapan ditampilkan sebagai kartu lebar dengan bar horizontal.
class _HumidityBar extends StatelessWidget {
final double value;
final double progress;
const _HumidityBar({required this.value, required this.progress});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: AppColors.card,
borderRadius: BorderRadius.circular(24),
border: Border.all(color: AppColors.water.withOpacity(0.25)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: AppColors.water.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(
Icons.opacity_rounded,
color: AppColors.water,
size: 22,
),
),
const SizedBox(width: 12),
const Expanded(
child: Text(
'Kelembapan udara',
style: TextStyle(color: AppColors.muted, fontSize: 13),
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Text(
value.toStringAsFixed(0),
style: const TextStyle(
color: AppColors.text,
fontSize: 30,
fontWeight: FontWeight.w800,
),
),
const SizedBox(width: 2),
const Text(
'%',
style: TextStyle(
color: AppColors.water,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
],
),
],
),
const SizedBox(height: 16),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: LinearProgressIndicator(
value: progress.clamp(0.0, 1.0),
minHeight: 10,
color: AppColors.water,
backgroundColor: AppColors.water.withOpacity(0.15),
),
),
const SizedBox(height: 10),
const Text(
'Agak lembap • ideal 40–60 %',
style: TextStyle(color: AppColors.muted, fontSize: 12),
),
],
),
);
}
}
class _NetworkCard extends StatelessWidget {
const _NetworkCard();
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.card,
borderRadius: BorderRadius.circular(24),
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: AppColors.violet.withOpacity(0.2),
borderRadius: BorderRadius.circular(14),
),
child: const Icon(
Icons.wifi_rounded,
color: AppColors.violet,
size: 26,
),
),
const SizedBox(width: 14),
const Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Wi-Fi Lab IoT',
style: TextStyle(
color: AppColors.text,
fontWeight: FontWeight.w700,
fontSize: 16,
),
),
SizedBox(height: 2),
Text(
'ESP32 terhubung • stabil',
style: TextStyle(color: AppColors.muted, fontSize: 13),
),
],
),
),
const _SignalBars(level: 3),
],
),
);
}
}
/// Indikator sinyal 4 batang.
class _SignalBars extends StatelessWidget {
final int level; // 0..4
const _SignalBars({required this.level});
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: List.generate(4, (i) {
final active = i < level;
return Container(
width: 6,
height: 10.0 + i * 6,
margin: const EdgeInsets.only(left: 3),
decoration: BoxDecoration(
color: active ? AppColors.violet : AppColors.cardSoft,
borderRadius: BorderRadius.circular(3),
),
);
}),
);
}
}
class _LedCard extends StatelessWidget {
final bool isOn;
final ValueChanged<bool> onChanged;
const _LedCard({required this.isOn, required this.onChanged});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => onChanged(!isOn),
child: AnimatedContainer(
duration: const Duration(milliseconds: 250),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: isOn ? AppColors.led.withOpacity(0.15) : AppColors.card,
borderRadius: BorderRadius.circular(24),
border: Border.all(
color: isOn ? AppColors.led : AppColors.cardSoft,
width: isOn ? 1.5 : 1,
),
boxShadow: isOn
? [
BoxShadow(
color: AppColors.led.withOpacity(0.3),
blurRadius: 28,
spreadRadius: 1,
),
]
: [],
),
child: Row(
children: [
AnimatedContainer(
duration: const Duration(milliseconds: 250),
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: isOn ? AppColors.led : AppColors.cardSoft,
borderRadius: BorderRadius.circular(16),
),
child: Icon(
isOn
? Icons.lightbulb_rounded
: Icons.lightbulb_outline_rounded,
color: isOn ? AppColors.bg : AppColors.muted,
size: 30,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'LED Lab',
style: TextStyle(
color: AppColors.text,
fontWeight: FontWeight.w700,
fontSize: 17,
),
),
const SizedBox(height: 2),
Text(
isOn ? 'Menyala' : 'Mati',
style: TextStyle(
color: isOn ? AppColors.led : AppColors.muted,
fontSize: 13,
fontWeight: FontWeight.w600,
),
),
],
),
),
Switch(
value: isOn,
onChanged: onChanged,
activeColor: AppColors.bg,
activeTrackColor: AppColors.led,
inactiveThumbColor: AppColors.muted,
inactiveTrackColor: AppColors.cardSoft,
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment