@@ -27,8 +27,8 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
27
27
int batteryLevel = - 1 ;
28
28
bool _hasLowBatteryAlerted = false ;
29
29
Timer ? _reconnectionTimer;
30
- int connectionCheckSeconds = 7 ;
31
30
DateTime ? _reconnectAt;
31
+ final int _connectionCheckSeconds = 7 ;
32
32
33
33
bool _havingNewFirmware = false ;
34
34
bool get havingNewFirmware => _havingNewFirmware && pairedDevice != null && isConnected;
@@ -140,8 +140,8 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
140
140
141
141
Future periodicConnect (String printer) async {
142
142
_reconnectionTimer? .cancel ();
143
- _reconnectionTimer = Timer .periodic (Duration (seconds: connectionCheckSeconds ), (t) async {
144
- debugPrint ("Period connect seconds: $connectionCheckSeconds , triggered timer at ${DateTime .now ()}" );
143
+ _reconnectionTimer = Timer .periodic (Duration (seconds: _connectionCheckSeconds ), (t) async {
144
+ debugPrint ("Period connect seconds: $_connectionCheckSeconds , triggered timer at ${DateTime .now ()}" );
145
145
if (SharedPreferencesUtil ().btDevice.id.isEmpty) {
146
146
t.cancel ();
147
147
return ;
@@ -186,30 +186,31 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
186
186
if (isConnected) {
187
187
if (connectedDevice == null ) {
188
188
connectedDevice = await _getConnectedDevice ();
189
- // SharedPreferencesUtil().btDevice = connectedDevice!;
190
189
SharedPreferencesUtil ().deviceName = connectedDevice! .name;
191
190
MixpanelManager ().deviceConnected ();
192
191
}
193
192
194
193
setIsConnected (true );
195
194
updateConnectingStatus (false );
196
- } else {
197
- var device = await _scanAndConnectDevice ();
198
- print ('inside scanAndConnectToDevice $device in device_provider' );
199
- if (device != null ) {
200
- var cDevice = await _getConnectedDevice ();
201
- if (cDevice != null ) {
202
- setConnectedDevice (cDevice);
203
- setIsDeviceV2Connected ();
204
- // SharedPreferencesUtil().btDevice = cDevice;
205
- SharedPreferencesUtil ().deviceName = cDevice.name;
206
- MixpanelManager ().deviceConnected ();
207
- setIsConnected (true );
208
- }
209
- print ('device is not null $cDevice ' );
195
+ notifyListeners ();
196
+ return ;
197
+ }
198
+
199
+ // else
200
+ var device = await _scanAndConnectDevice ();
201
+ debugPrint ('inside scanAndConnectToDevice $device in device_provider' );
202
+ if (device != null ) {
203
+ var cDevice = await _getConnectedDevice ();
204
+ if (cDevice != null ) {
205
+ setConnectedDevice (cDevice);
206
+ setIsDeviceV2Connected ();
207
+ SharedPreferencesUtil ().deviceName = cDevice.name;
208
+ MixpanelManager ().deviceConnected ();
209
+ setIsConnected (true );
210
210
}
211
- updateConnectingStatus ( false );
211
+ debugPrint ( 'device is not null $ cDevice ' );
212
212
}
213
+ updateConnectingStatus (false );
213
214
214
215
notifyListeners ();
215
216
}
@@ -222,10 +223,7 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
222
223
void setIsConnected (bool value) {
223
224
isConnected = value;
224
225
if (isConnected) {
225
- connectionCheckSeconds = 8 ;
226
226
_reconnectionTimer? .cancel ();
227
- } else {
228
- connectionCheckSeconds = 4 ;
229
227
}
230
228
notifyListeners ();
231
229
}
0 commit comments