summaryrefslogtreecommitdiffstats
path: root/lib/data/models/connections_signals.dart
blob: cd6d6957342478f3fa7a5f5f8c25bdcc7daf38d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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;
  }
}