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 {
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;
}

View file

@ -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"))

View file

@ -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<MyHomePage> {
future: Category.fetch(),
builder: (context, AsyncSnapshot<List<Category>> 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<MyHomePage> {
},
body: widget,
isExpanded: expanded[category.key],
backgroundColor: Colors.grey[200],
backgroundColor: Colors.deepPurple[100],
canTapOnHeader: true,
);
},

View file

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

View file

@ -34,6 +34,10 @@ pub struct DeviceWithName {
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct DevicesWithName {
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 {