| 1 | import 'package:aero/services/wear_os.dart'; |
| 2 | import 'package:flutter/material.dart'; |
| 3 | |
| 4 | class WearablesScreen extends StatefulWidget |
| 5 | const WearablesScreen({super |
| 6 | |
| 7 | @override |
| 8 | State<WearablesScreen> createState |
| 9 | } |
| 10 | |
| 11 | class _WearablesScreenState extends State |
| 12 | final WearOSService _wearOSService = |
| 13 | List<WearOSDevice> _connectedDevices = [] |
| 14 | bool _noDeviceFound = false; |
| 15 | bool _refreshing = false; |
| 16 | Future<void> _loadDevices |
| 17 | setState(() { |
| 18 | _refreshing = true; |
| 19 | }); |
| 20 | final devices = await _wearOSService. |
| 21 | setState(() { |
| 22 | _connectedDevices = devices; |
| 23 | _noDeviceFound = devices.isEmpty; |
| 24 | _refreshing = false; |
| 25 | }); |
| 26 | } |
| 27 | |
| 28 | @override |
| 29 | void initState() { |
| 30 | _loadDevices(); |
| 31 | super.initState(); |
| 32 | } |
| 33 | |
| 34 | @override |
| 35 | Widget build(BuildContext |
| 36 | return Scaffold( |
| 37 | appBar: AppBar( |
| 38 | title: Text( |
| 39 | "WearOS devices", |
| 40 | ), |
| 41 | actions: [ |
| 42 | IconButton( |
| 43 | onPressed: _loadDevices, |
| 44 | icon: AnimatedRotation( |
| 45 | duration: const Duration(milliseconds |
| 46 | turns: _refreshing ? -1 : |
| 47 | child: Icon( |
| 48 | Icons.refresh, |
| 49 | ), |
| 50 | ), |
| 51 | ) |
| 52 | ], |
| 53 | ), |
| 54 | body: Column( |
| 55 | children: [ |
| 56 | if (_noDeviceFound) |
| 57 | Padding( |
| 58 | padding: const EdgeInsets. |
| 59 | child: Center( |
| 60 | child: Text( |
| 61 | "No WearOS devices found. Make sure your watch is connected to your phone via Bluetooth and try refreshing.", |
| 62 | textAlign: TextAlign.center, |
| 63 | ), |
| 64 | ), |
| 65 | ), |
| 66 | Expanded( |
| 67 | child: ListView.builder( |
| 68 | itemCount: _connectedDevices.length, |
| 69 | itemBuilder: (context, index) { |
| 70 | final device = _connectedDevices[index]; |
| 71 | return ListTile( |
| 72 | title: Text(device.displayName), |
| 73 | subtitle: Text(device.id), |
| 74 | trailing: Icon( |
| 75 | device.isNearby ? Icons.check_circle |
| 76 | color: device.isNearby ? Colors |
| 77 | ), |
| 78 | ); |
| 79 | }, |
| 80 | ), |
| 81 | ), |
| 82 | ], |
| 83 | ), |
| 84 | ); |
| 85 | } |
| 86 | } |