1
1
import 'package:badgemagic/bademagic_module/bluetooth/datagenerator.dart' ;
2
2
import 'package:badgemagic/bademagic_module/bluetooth/write_state.dart' ;
3
3
import 'package:flutter_blue_plus/flutter_blue_plus.dart' ;
4
+ import 'package:badgemagic/providers/BadgeAliasProvider.dart' ;
5
+ import 'package:get_it/get_it.dart' ;
4
6
import 'base_ble_state.dart' ;
5
7
6
8
class ConnectState extends RetryBleState {
@@ -26,12 +28,20 @@ class ConnectState extends RetryBleState {
26
28
if (connectionState == BluetoothConnectionState .connected) {
27
29
connected = true ;
28
30
31
+ String alias = displayName;
32
+ final aliasProvider = GetIt .I <BadgeAliasProvider >();
33
+ final maybeAlias = aliasProvider.getAlias (displayName);
34
+ if (maybeAlias != null && maybeAlias.trim ().isNotEmpty) {
35
+ alias = maybeAlias;
36
+ }
37
+
29
38
logger.d ("Device '$displayName ' connected" );
30
- toast.showToast ('Device "$ displayName " connected successfully .' );
39
+ toast.showToast ('Connected successfully to "$ alias " .' );
31
40
32
41
final writeState =
33
42
WriteState (device: scanResult.device, manager: manager);
34
43
final result = await writeState.process ();
44
+
35
45
try {
36
46
await scanResult.device.disconnect ();
37
47
logger.d ("Device disconnected after transfer" );
@@ -40,6 +50,7 @@ class ConnectState extends RetryBleState {
40
50
} catch (e) {
41
51
logger.e ("Error during disconnect after transfer: $e " );
42
52
}
53
+
43
54
return result;
44
55
} else {
45
56
throw Exception ("Failed to connect to the device" );
0 commit comments