From 65b9990394d98e5af396a4bfe2876b73339ed9c1 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Fri, 13 Oct 2023 11:50:50 +0200 Subject: [PATCH] QoL improvements --- frontend/lib/constants.dart | 3 +++ frontend/lib/devices.dart | 21 ++++++++++++--------- frontend/lib/main.dart | 15 ++++++++++----- frontend/pubspec.yaml | 1 + src/devices.rs | 4 ++++ 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/frontend/lib/constants.dart b/frontend/lib/constants.dart index 5cdd1ca..50da5f0 100644 --- a/frontend/lib/constants.dart +++ b/frontend/lib/constants.dart @@ -1,4 +1,7 @@ +import 'package:flutter/material.dart'; + class Constants { static const String BASE_URL = "http://127.0.0.1:8062"; // static const String BASE_URL = "http://smart.gavania.de"; + static const Color MAIN_COLOR = Colors.deepPurple; } diff --git a/frontend/lib/devices.dart b/frontend/lib/devices.dart index 5764f3d..7c60bc9 100644 --- a/frontend/lib/devices.dart +++ b/frontend/lib/devices.dart @@ -69,14 +69,17 @@ class CategoryWidget extends StatelessWidget { CategoryWidget({super.key, required this.category}); String Name() { - var s = category.name; - return "${s[0].toUpperCase()}${s.substring(1)}"; + return category.name + .split('_') + .map((s) => "${s[0].toUpperCase()}${s.substring(1)}") + .join(' '); } @override Widget build(BuildContext context) { - final double header_height = 40; - final double info_height = 30; + const double header_height = 40; + const double info_height = 30; + const double x_offset = 0.6; return Wrap( spacing: 25, @@ -91,8 +94,8 @@ class CategoryWidget extends StatelessWidget { }, children: [ TableRow( - decoration: const BoxDecoration( - color: Colors.blueGrey, + decoration: BoxDecoration( + color: Colors.deepPurple[200], ), children: [ SizedBox( @@ -124,7 +127,7 @@ class CategoryWidget extends StatelessWidget { textAlign: TextAlign.center, "LED")), Align( - alignment: const Alignment(0.5, 0.0), + alignment: const Alignment(x_offset + 0.025, 0.0), child: DeviceLed( device_id: device.device_id, led_state: device.led_state)), @@ -141,7 +144,7 @@ class CategoryWidget extends StatelessWidget { textAlign: TextAlign.center, "Power")), Align( - alignment: const Alignment(0.4, 0.0), + alignment: const Alignment(x_offset - 0.1, 0.0), child: DevicePower( device_id: device.device_id, power_state: device.power_state, @@ -159,7 +162,7 @@ class CategoryWidget extends StatelessWidget { textAlign: TextAlign.center, "Power Draw")), Align( - alignment: const Alignment(0.5, 0.0), + alignment: const Alignment(x_offset, 0.0), child: Text( textAlign: TextAlign.center, "${device.power_draw} W")) diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index 7429e9c..0dcfe1a 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; +import 'constants.dart'; import 'devices.dart'; void main() { @@ -13,12 +15,12 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'SmartHome', + title: 'Home Server', theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + colorScheme: ColorScheme.fromSeed(seedColor: Constants.MAIN_COLOR), useMaterial3: true, ), - home: const MyHomePage(title: 'SmartHome Main Page'), + home: const MyHomePage(title: 'Home Server'), ); } } @@ -41,7 +43,10 @@ class _MyHomePageState extends State { future: Category.fetch(), builder: (context, AsyncSnapshot> categories) { if (!categories.hasData) { - return const Text("still loading"); + return SpinKitWanderingCubes( + color: Colors.deepPurple[100], + size: 80.0, + ); } final data = categories.data!; @@ -85,7 +90,7 @@ class _MyHomePageState extends State { }, body: widget, isExpanded: expanded[category.key], - backgroundColor: Colors.grey[200], + backgroundColor: Colors.deepPurple[100], canTapOnHeader: true, ); }, diff --git a/frontend/pubspec.yaml b/frontend/pubspec.yaml index 43f1468..61e7394 100644 --- a/frontend/pubspec.yaml +++ b/frontend/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: cupertino_icons: ^1.0.2 http: ^1.1.0 + flutter_spinkit: ^5.2.0 dev_dependencies: flutter_test: diff --git a/src/devices.rs b/src/devices.rs index 1ca757b..56af52f 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -34,6 +34,10 @@ pub struct DeviceWithName { #[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct DevicesWithName { pub plugs: Vec, + pub thermostat: Vec, + pub temperature_and_humidity: Vec, + pub dish_washer: Vec, + pub washing_machines: Vec, } impl DevicesWithName {