diff --git a/android/src/main/java/com/pauldemarco/flutter_blue/ProtoMaker.java b/android/src/main/java/com/pauldemarco/flutter_blue/ProtoMaker.java index 31e758a8..edba358c 100644 --- a/android/src/main/java/com/pauldemarco/flutter_blue/ProtoMaker.java +++ b/android/src/main/java/com/pauldemarco/flutter_blue/ProtoMaker.java @@ -14,14 +14,11 @@ import android.bluetooth.le.ScanRecord; import android.bluetooth.le.ScanResult; import android.os.Build; -import android.os.Parcel; import android.os.ParcelUuid; -import android.util.Log; import android.util.SparseArray; import com.google.protobuf.ByteString; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; @@ -68,17 +65,21 @@ static Protos.ScanResult from(BluetoothDevice device, ScanResult scanResult) { } // Manufacturer Specific Data SparseArray msd = scanRecord.getManufacturerSpecificData(); - for (int i = 0; i < msd.size(); i++) { - int key = msd.keyAt(i); - byte[] value = msd.valueAt(i); - a.putManufacturerData(key, ByteString.copyFrom(value)); + if (msd!=null){ + for (int i = 0; i < msd.size(); i++) { + int key = msd.keyAt(i); + byte[] value = msd.valueAt(i); + a.putManufacturerData(key, ByteString.copyFrom(value)); + } } // Service Data Map serviceData = scanRecord.getServiceData(); - for (Map.Entry entry : serviceData.entrySet()) { - ParcelUuid key = entry.getKey(); - byte[] value = entry.getValue(); - a.putServiceData(key.getUuid().toString(), ByteString.copyFrom(value)); + if (serviceData!=null){ + for (Map.Entry entry : serviceData.entrySet()) { + ParcelUuid key = entry.getKey(); + byte[] value = entry.getValue(); + a.putServiceData(key.getUuid().toString(), ByteString.copyFrom(value)); + } } // Service UUIDs List serviceUuids = scanRecord.getServiceUuids(); diff --git a/example/lib/main.dart b/example/lib/main.dart index e4a55a1a..31bba3c2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -54,7 +54,7 @@ class BluetoothOffScreen extends StatelessWidget { 'Bluetooth Adapter is ${state != null ? state.toString().substring(15) : 'not available'}.', style: Theme.of(context) .primaryTextTheme - .subhead + .subtitle1 ?.copyWith(color: Colors.white), ), ], diff --git a/example/lib/widgets.dart b/example/lib/widgets.dart index aefdf262..23ae5949 100644 --- a/example/lib/widgets.dart +++ b/example/lib/widgets.dart @@ -135,7 +135,7 @@ class ServiceTile extends StatelessWidget { children: [ Text('Service'), Text('0x${service.uuid.toString().toUpperCase().substring(4, 8)}', - style: Theme.of(context).textTheme.body1?.copyWith( + style: Theme.of(context).textTheme.bodyText1?.copyWith( color: Theme.of(context).textTheme.caption?.color)) ], ), @@ -183,7 +183,7 @@ class CharacteristicTile extends StatelessWidget { Text('Characteristic'), Text( '0x${characteristic.uuid.toString().toUpperCase().substring(4, 8)}', - style: Theme.of(context).textTheme.body1?.copyWith( + style: Theme.of(context).textTheme.bodyText1?.copyWith( color: Theme.of(context).textTheme.caption?.color)) ], ), @@ -245,7 +245,7 @@ class DescriptorTile extends StatelessWidget { Text('0x${descriptor.uuid.toString().toUpperCase().substring(4, 8)}', style: Theme.of(context) .textTheme - .body1 + .bodyText1 ?.copyWith(color: Theme.of(context).textTheme.caption?.color)) ], ), @@ -289,11 +289,11 @@ class AdapterStateTile extends StatelessWidget { child: ListTile( title: Text( 'Bluetooth adapter is ${state.toString().substring(15)}', - style: Theme.of(context).primaryTextTheme.subhead, + style: Theme.of(context).primaryTextTheme.subtitle1, ), trailing: Icon( Icons.error, - color: Theme.of(context).primaryTextTheme.subhead?.color, + color: Theme.of(context).primaryTextTheme.subtitle1?.color, ), ), );