diff options
author | Lisandro Pérez Meyer <lpmeyer@ics.com> | 2023-11-14 17:20:58 -0300 |
---|---|---|
committer | Lisandro Pérez Meyer <lpmeyer@ics.com> | 2023-11-14 17:31:12 -0300 |
commit | 70ec8a79a121471a004e7e4c23157d10157e136f (patch) | |
tree | a4f9c0a4fac4e4274ec4324a289b6ef62e1c5653 /lib/data/models/connections_signals.dart |
Initial cleanup push.
Based on agldemo2024 on commit 2a5dc04d801134338150c3f6afc67eaa65599763
Disable device preview.
Disable Lottie animation.
The original commit was b3c493c340fcb4bb0a937692838fc830bec3e9ea
but I am just keeping this change, because the json did not really
needed to change. I think.
Signed-off-by: Lisandro Pérez Meyer <lpmeyer@ics.com>
Diffstat (limited to 'lib/data/models/connections_signals.dart')
-rw-r--r-- | lib/data/models/connections_signals.dart | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/data/models/connections_signals.dart b/lib/data/models/connections_signals.dart new file mode 100644 index 0000000..cd6d695 --- /dev/null +++ b/lib/data/models/connections_signals.dart @@ -0,0 +1,92 @@ +import 'dart:convert'; + +import 'package:flutter_ics_homescreen/export.dart'; + +@immutable +class Signals { + final bool isBluetoothConnected; + final bool isDataConnected; + final bool isWifiConnected; + final int dataSignalStrenght; + final int wifiSignalStrenght; + const Signals({ + required this.isBluetoothConnected, + required this.isDataConnected, + required this.isWifiConnected, + required this.dataSignalStrenght, + required this.wifiSignalStrenght, + }); + const Signals.initial() + : isBluetoothConnected = false, + isDataConnected = false, + isWifiConnected = false, + dataSignalStrenght = 0, + wifiSignalStrenght = 0; + + Signals copyWith({ + bool? isBluetoothConnected, + bool? isDataConnected, + bool? isWifiConnected, + int? dataSignalStrenght, + int? wifiSignalStrenght, + }) { + return Signals( + isBluetoothConnected: isBluetoothConnected ?? this.isBluetoothConnected, + isDataConnected: isDataConnected ?? this.isDataConnected, + isWifiConnected: isWifiConnected ?? this.isWifiConnected, + dataSignalStrenght: dataSignalStrenght ?? this.dataSignalStrenght, + wifiSignalStrenght: wifiSignalStrenght ?? this.wifiSignalStrenght, + ); + } + + Map<String, dynamic> toMap() { + return { + 'isBluetoothConnected': isBluetoothConnected, + 'isDataConnected': isDataConnected, + 'isWifiConnected': isWifiConnected, + 'dataSignalStrenght': dataSignalStrenght, + 'wifiSignalStrenght': wifiSignalStrenght, + }; + } + + factory Signals.fromMap(Map<String, dynamic> map) { + return Signals( + isBluetoothConnected: map['isBluetoothConnected'] ?? false, + isDataConnected: map['isDataConnected'] ?? false, + isWifiConnected: map['isWifiConnected'] ?? false, + dataSignalStrenght: map['dataSignalStrenght']?.toInt() ?? 0, + wifiSignalStrenght: map['wifiSignalStrenght']?.toInt() ?? 0, + ); + } + + String toJson() => json.encode(toMap()); + + factory Signals.fromJson(String source) => + Signals.fromMap(json.decode(source)); + + @override + String toString() { + return 'Signals(isBluetoothConnected: $isBluetoothConnected, isDataConnected: $isDataConnected, isWifiConnected: $isWifiConnected, dataSignalStrenght: $dataSignalStrenght, wifiSignalStrenght: $wifiSignalStrenght)'; + } + + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + + return other is Signals && + other.isBluetoothConnected == isBluetoothConnected && + other.isDataConnected == isDataConnected && + other.isWifiConnected == isWifiConnected && + other.dataSignalStrenght == dataSignalStrenght && + other.wifiSignalStrenght == wifiSignalStrenght; + } + + @override + int get hashCode { + return isBluetoothConnected.hashCode ^ + isDataConnected.hashCode ^ + isWifiConnected.hashCode ^ + dataSignalStrenght.hashCode ^ + wifiSignalStrenght.hashCode; + } +} |