You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

102 lines
2.7 KiB

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
enum CounterType {
coldWater(_coldWaterId, Colors.blue, Icons.water_drop),
hotWater(_hotWaterId, Colors.red, Icons.water_drop),
electrisity1rates(_electrisity1rateId, Colors.lightBlue, Icons.tungsten),
electrisity2rates(_electrisity2rateId, Colors.lightBlue, Icons.tungsten),
electrisity3rates(_electrisity3rateId, Colors.lightBlue, Icons.tungsten),
gas(_gasId, Colors.blueAccent, Icons.local_fire_department);
const CounterType(this.id, this.color, this.icon);
static const int _coldWaterId = 0;
static const int _hotWaterId = 1;
static const int _gasId = 2;
static const int _electrisity1rateId = 3;
static const int _electrisity2rateId = 4;
static const int _electrisity3rateId = 5;
final int id;
final Color color;
final IconData icon;
String getLabel(BuildContext context) {
switch (id) {
case _coldWaterId:
return AppLocalizations.of(context)!.cold_water_type_str;
case _hotWaterId:
return AppLocalizations.of(context)!.hot_water_type_str;
case _electrisity1rateId:
return AppLocalizations.of(context)!.electrisity1_type_str;
case _electrisity2rateId:
return AppLocalizations.of(context)!.electrisity2_type_str;
case _electrisity3rateId:
return AppLocalizations.of(context)!.electrisity3_type_str;
case _gasId:
return AppLocalizations.of(context)!.gas_type_str;
default:
}
return AppLocalizations.of(context)!.unknown_type_str;
}
CounterUnits getUnits() {
if (id < _electrisity1rateId) {
return CounterUnits.m3;
}
return CounterUnits.kVt;
}
}
enum CounterUnits {
m3(0),
kVt(1);
const CounterUnits(this.id);
final int id;
String getLabel(BuildContext context) {
switch (id) {
case 0:
return AppLocalizations.of(context)!.m3;
case 1:
return AppLocalizations.of(context)!.kVt;
}
return '';
}
}
class Counter {
final int? id;
final int addressId;
final CounterType counterType;
final String name;
final double? value;
Counter(
{this.id,
required this.addressId,
required this.counterType,
required this.name,
this.value});
factory Counter.fromMap(Map<String, dynamic> json) {
return Counter(
id: json["id"],
addressId: json["address_id"],
counterType: CounterType.values
.firstWhere((element) => element.id == json["counter_type"]),
name: json["name"],
value: json["value"].toDouble());
}
Map<String, dynamic> toMap() => {
"id": id,
"address_id": addressId,
"counter_type": counterType.id,
"name": name
};
}