diff --git a/example/lib/adapter/ble_adapter.dart b/example/lib/adapter/ble_adapter.dart index 35a1f059..622a275b 100644 --- a/example/lib/adapter/ble_adapter.dart +++ b/example/lib/adapter/ble_adapter.dart @@ -90,6 +90,7 @@ class BleAdapter { Future> discoverAndGetServicesCharacteristics( String peripheralId) async { + // TODO remove connect() call when connectivity handling is implemented await _scannedPeripherals[peripheralId].connect(); await _scannedPeripherals[peripheralId] .discoverAllServicesAndCharacteristics(); @@ -108,6 +109,7 @@ class BleAdapter { bleServices.add(BleService(service.uuid, bleCharacteristics)); } + // TODO remove when connectivity handling is implemented _scannedPeripherals[peripheralId].disconnectOrCancelConnection(); return bleServices; diff --git a/example/lib/example_peripherals/generic_peripheral.dart b/example/lib/example_peripherals/generic_peripheral.dart index 91dc6bf3..28d96d8c 100644 --- a/example/lib/example_peripherals/generic_peripheral.dart +++ b/example/lib/example_peripherals/generic_peripheral.dart @@ -20,42 +20,42 @@ class GenericPeripheral extends SimulatedPeripheral { SimulatedCharacteristic( uuid: 'F000AA10-0001-4000-B000-000000000000', value: Uint8List.fromList([0]), - convenienceName: 'Generic characteristic'), + convenienceName: 'Generic characteristic 1'), ], - convenienceName: 'Generic service', + convenienceName: 'Generic service 1', ), SimulatedService( uuid: 'F000AA01-0001-4000-B000-000000000000', isAdvertised: true, characteristics: [ SimulatedCharacteristic( - uuid: 'F000AA10-0001-4000-B000-000000000000', + uuid: 'F000AA11-0001-4000-B000-000000000000', value: Uint8List.fromList([0]), - convenienceName: 'Generic characteristic'), + convenienceName: 'Generic characteristic 2'), ], - convenienceName: 'Generic service', + convenienceName: 'Generic service 2', ), SimulatedService( uuid: 'F000AA02-0001-4000-B000-000000000000', isAdvertised: true, characteristics: [ SimulatedCharacteristic( - uuid: 'F000AA10-0001-4000-B000-000000000000', + uuid: 'F000AA12-0001-4000-B000-000000000000', value: Uint8List.fromList([0]), - convenienceName: 'Generic characteristic'), + convenienceName: 'Generic characteristic 3'), ], - convenienceName: 'Generic service', + convenienceName: 'Generic service 3', ), SimulatedService( uuid: 'F000AA03-0001-4000-B000-000000000000', isAdvertised: true, characteristics: [ SimulatedCharacteristic( - uuid: 'F000AA10-0001-4000-B000-000000000000', + uuid: 'F000AA13-0001-4000-B000-000000000000', value: Uint8List.fromList([0]), - convenienceName: 'Generic characteristic'), + convenienceName: 'Generic characteristic 4'), ], - convenienceName: 'Generic service', + convenienceName: 'Generic service 4', ), ], ); diff --git a/example/lib/peripheral_details/components/peripheral_details_view.dart b/example/lib/peripheral_details/components/peripheral_details_view.dart index 1d3245d2..f5ce50f4 100644 --- a/example/lib/peripheral_details/components/peripheral_details_view.dart +++ b/example/lib/peripheral_details/components/peripheral_details_view.dart @@ -48,8 +48,8 @@ class PeripheralDetailsView extends StatelessWidget { child: ListView.builder( shrinkWrap: true, itemCount: state.bleServiceStates.length, - itemBuilder: (context, index) => - _createServiceTileView(context, state.bleServiceStates[index]), + itemBuilder: (context, index) => _createServiceTileView( + context, state.bleServiceStates[index], index), ), ); } @@ -57,6 +57,7 @@ class PeripheralDetailsView extends StatelessWidget { Widget _createServiceTileView( BuildContext context, BleServiceState serviceState, + int index, ) { // ignore: close_sinks final PeripheralDetailsBloc bloc = @@ -73,22 +74,20 @@ class PeripheralDetailsView extends StatelessWidget { icon: Icon( serviceState.expanded ? Icons.unfold_less : Icons.unfold_more), onPressed: () => bloc.add(ServiceViewExpandedEvent( - serviceState, - !serviceState.expanded, + index, )), ), ), - serviceState.expanded - ? Padding( - padding: EdgeInsets.only(left: 16.0), - child: ListView.builder( - itemCount: serviceState.service.characteristics.length, - itemBuilder: (context, index) => _buildCharacteristicCard( - context, serviceState.service.characteristics[index]), - shrinkWrap: true, - ), - ) - : Column(), + if (serviceState.expanded) + Padding( + padding: EdgeInsets.only(left: 16.0), + child: ListView.builder( + itemCount: serviceState.service.characteristics.length, + itemBuilder: (context, index) => _buildCharacteristicCard( + context, serviceState.service.characteristics[index]), + shrinkWrap: true, + ), + ), ], ); } @@ -121,7 +120,7 @@ class PeripheralDetailsView extends StatelessWidget { List _getCharacteristicProperties(BleCharacteristic characteristic) { List properties = new List(); - if (characteristic.isWritableWithoutResponse || + if (characteristic.isWritableWithResponse || characteristic.isWritableWithoutResponse) { properties.add("write"); } diff --git a/example/lib/peripheral_details/peripheral_details_bloc.dart b/example/lib/peripheral_details/peripheral_details_bloc.dart index ac0bc35a..0262ae24 100644 --- a/example/lib/peripheral_details/peripheral_details_bloc.dart +++ b/example/lib/peripheral_details/peripheral_details_bloc.dart @@ -51,9 +51,8 @@ class PeripheralDetailsBloc List newBleServiceStates = List.from(state.bleServiceStates); - int serviceIndex = newBleServiceStates.indexOf(event.serviceStateToChange); - newBleServiceStates[serviceIndex] = - BleServiceState(event.serviceStateToChange.service, event.expanded); + newBleServiceStates[event.index] = + BleServiceState(state.bleServiceStates[event.index].service, !state.bleServiceStates[event.index].expanded); return PeripheralDetailsState( peripheral: state.peripheral, diff --git a/example/lib/peripheral_details/peripheral_details_event.dart b/example/lib/peripheral_details/peripheral_details_event.dart index ab2c236d..28de3d0b 100644 --- a/example/lib/peripheral_details/peripheral_details_event.dart +++ b/example/lib/peripheral_details/peripheral_details_event.dart @@ -1,5 +1,4 @@ import 'package:blemulator_example/model/ble_service.dart'; -import 'package:blemulator_example/peripheral_details/peripheral_details_state.dart'; import 'package:equatable/equatable.dart'; abstract class PeripheralDetailsEvent extends Equatable { @@ -17,10 +16,9 @@ class ServicesFetchedEvent extends PeripheralDetailsEvent { class ServiceViewExpandedEvent extends PeripheralDetailsEvent { @override - List get props => [serviceStateToChange, expanded]; + List get props => [index]; - final BleServiceState serviceStateToChange; - final bool expanded; + final int index; - ServiceViewExpandedEvent(this.serviceStateToChange, this.expanded); + ServiceViewExpandedEvent(this.index); } diff --git a/example/test/peripheral_details/peripheral_details_bloc_test.dart b/example/test/peripheral_details/peripheral_details_bloc_test.dart index 745e0958..aea13de8 100644 --- a/example/test/peripheral_details/peripheral_details_bloc_test.dart +++ b/example/test/peripheral_details/peripheral_details_bloc_test.dart @@ -56,7 +56,6 @@ void main() { test('should map ServiceViewExpandedEvent to PeripheralDetailsState', () async { // given SampleBleService service = SampleBleService(); - BleServiceState bleServiceState = BleServiceState(service, false); BleServiceState newBleServiceState = BleServiceState(service, true); peripheralDetailsBloc.add(ServicesFetchedEvent([service])); @@ -65,7 +64,7 @@ void main() { peripheral: peripheral, bleServiceStates: [newBleServiceState]); // when - peripheralDetailsBloc.add(ServiceViewExpandedEvent(bleServiceState, true)); + peripheralDetailsBloc.add(ServiceViewExpandedEvent(0)); // then await expectLater(