QoL improvements

This commit is contained in:
hodasemi 2023-10-13 11:50:50 +02:00
parent ff40fc3662
commit 65b9990394
5 changed files with 30 additions and 14 deletions

View file

@ -1,4 +1,7 @@
import 'package:flutter/material.dart';
class Constants { class Constants {
static const String BASE_URL = "http://127.0.0.1:8062"; static const String BASE_URL = "http://127.0.0.1:8062";
// static const String BASE_URL = "http://smart.gavania.de"; // static const String BASE_URL = "http://smart.gavania.de";
static const Color MAIN_COLOR = Colors.deepPurple;
} }

View file

@ -69,14 +69,17 @@ class CategoryWidget extends StatelessWidget {
CategoryWidget({super.key, required this.category}); CategoryWidget({super.key, required this.category});
String Name() { String Name() {
var s = category.name; return category.name
return "${s[0].toUpperCase()}${s.substring(1)}"; .split('_')
.map((s) => "${s[0].toUpperCase()}${s.substring(1)}")
.join(' ');
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final double header_height = 40; const double header_height = 40;
final double info_height = 30; const double info_height = 30;
const double x_offset = 0.6;
return Wrap( return Wrap(
spacing: 25, spacing: 25,
@ -91,8 +94,8 @@ class CategoryWidget extends StatelessWidget {
}, },
children: [ children: [
TableRow( TableRow(
decoration: const BoxDecoration( decoration: BoxDecoration(
color: Colors.blueGrey, color: Colors.deepPurple[200],
), ),
children: [ children: [
SizedBox( SizedBox(
@ -124,7 +127,7 @@ class CategoryWidget extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
"LED")), "LED")),
Align( Align(
alignment: const Alignment(0.5, 0.0), alignment: const Alignment(x_offset + 0.025, 0.0),
child: DeviceLed( child: DeviceLed(
device_id: device.device_id, device_id: device.device_id,
led_state: device.led_state)), led_state: device.led_state)),
@ -141,7 +144,7 @@ class CategoryWidget extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
"Power")), "Power")),
Align( Align(
alignment: const Alignment(0.4, 0.0), alignment: const Alignment(x_offset - 0.1, 0.0),
child: DevicePower( child: DevicePower(
device_id: device.device_id, device_id: device.device_id,
power_state: device.power_state, power_state: device.power_state,
@ -159,7 +162,7 @@ class CategoryWidget extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
"Power Draw")), "Power Draw")),
Align( Align(
alignment: const Alignment(0.5, 0.0), alignment: const Alignment(x_offset, 0.0),
child: Text( child: Text(
textAlign: TextAlign.center, textAlign: TextAlign.center,
"${device.power_draw} W")) "${device.power_draw} W"))

View file

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'constants.dart';
import 'devices.dart'; import 'devices.dart';
void main() { void main() {
@ -13,12 +15,12 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'SmartHome', title: 'Home Server',
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), colorScheme: ColorScheme.fromSeed(seedColor: Constants.MAIN_COLOR),
useMaterial3: true, useMaterial3: true,
), ),
home: const MyHomePage(title: 'SmartHome Main Page'), home: const MyHomePage(title: 'Home Server'),
); );
} }
} }
@ -41,7 +43,10 @@ class _MyHomePageState extends State<MyHomePage> {
future: Category.fetch(), future: Category.fetch(),
builder: (context, AsyncSnapshot<List<Category>> categories) { builder: (context, AsyncSnapshot<List<Category>> categories) {
if (!categories.hasData) { if (!categories.hasData) {
return const Text("still loading"); return SpinKitWanderingCubes(
color: Colors.deepPurple[100],
size: 80.0,
);
} }
final data = categories.data!; final data = categories.data!;
@ -85,7 +90,7 @@ class _MyHomePageState extends State<MyHomePage> {
}, },
body: widget, body: widget,
isExpanded: expanded[category.key], isExpanded: expanded[category.key],
backgroundColor: Colors.grey[200], backgroundColor: Colors.deepPurple[100],
canTapOnHeader: true, canTapOnHeader: true,
); );
}, },

View file

@ -37,6 +37,7 @@ dependencies:
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
http: ^1.1.0 http: ^1.1.0
flutter_spinkit: ^5.2.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -34,6 +34,10 @@ pub struct DeviceWithName {
#[derive(Debug, Clone, Deserialize, Serialize, Default)] #[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct DevicesWithName { pub struct DevicesWithName {
pub plugs: Vec<DeviceWithName>, pub plugs: Vec<DeviceWithName>,
pub thermostat: Vec<DeviceWithName>,
pub temperature_and_humidity: Vec<DeviceWithName>,
pub dish_washer: Vec<DeviceWithName>,
pub washing_machines: Vec<DeviceWithName>,
} }
impl DevicesWithName { impl DevicesWithName {