From 39eb5c7d9bb7215044ec772dfd450526329b0851 Mon Sep 17 00:00:00 2001
From: ChangJoo Park <changjoo.park@iplateia.com>
Date: Mon, 1 Jul 2019 21:28:34 +0900
Subject: [PATCH 1/2] "Unknown device" when device name is null

---
 example/lib/BluetoothDeviceListEntry.dart | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/example/lib/BluetoothDeviceListEntry.dart b/example/lib/BluetoothDeviceListEntry.dart
index e0a5b4dd..d98d463f 100644
--- a/example/lib/BluetoothDeviceListEntry.dart
+++ b/example/lib/BluetoothDeviceListEntry.dart
@@ -13,7 +13,7 @@ class BluetoothDeviceListEntry extends ListTile {
     onLongPress: onLongPress,
     enabled: enabled,
     leading: Icon(Icons.devices), // @TODO . !BluetoothClass! class aware icon
-    title: Text(device.name),
+    title: Text(device.name ?? "Unknown device"),
     subtitle: Text(device.address.toString()),
     trailing: Row(
       mainAxisSize: MainAxisSize.min,

From 85901d265ac4ea6ab956fb3e1abad264e03d0bfb Mon Sep 17 00:00:00 2001
From: ChangJoo Park <changjoo.park@iplateia.com>
Date: Mon, 1 Jul 2019 21:30:58 +0900
Subject: [PATCH 2/2] Using builder for BluetoothDeviceListEntry

---
 example/lib/DiscoveryPage.dart | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/example/lib/DiscoveryPage.dart b/example/lib/DiscoveryPage.dart
index 6595a678..38105d24 100644
--- a/example/lib/DiscoveryPage.dart
+++ b/example/lib/DiscoveryPage.dart
@@ -9,7 +9,7 @@ class DiscoveryPage extends StatefulWidget {
   final bool start;
 
   const DiscoveryPage({this.start = true});
-  
+
   @override
   _DiscoveryPage createState() => new _DiscoveryPage();
 }
@@ -18,13 +18,13 @@ class _DiscoveryPage extends State<DiscoveryPage> {
   StreamSubscription<BluetoothDiscoveryResult> _streamSubscription;
   List<BluetoothDiscoveryResult> results = List<BluetoothDiscoveryResult>();
   bool isDiscovering;
-  
+
   _DiscoveryPage();
 
   @override
   void initState() {
     super.initState();
-    
+
     isDiscovering = widget.start;
     if (isDiscovering) {
       _startDiscovery();
@@ -44,7 +44,7 @@ class _DiscoveryPage extends State<DiscoveryPage> {
     _streamSubscription = FlutterBluetoothSerial.instance.startDiscovery().listen((r) {
       setState(() { results.add(r); });
     });
-    
+
     _streamSubscription.onDone(() {
       setState(() { isDiscovering = false; });
     });
@@ -59,22 +59,15 @@ class _DiscoveryPage extends State<DiscoveryPage> {
 
     super.dispose();
   }
-  
+
   @override
   Widget build(BuildContext context) {
-    List<BluetoothDeviceListEntry> list = results.map((result) => BluetoothDeviceListEntry(
-      device: result.device,
-      rssi: result.rssi,
-      onTap: () {
-        Navigator.of(context).pop(result.device);
-      },
-    )).toList();
     return Scaffold(
       appBar: AppBar(
         title: isDiscovering ? Text('Discovering devices') : Text('Discovered devices'),
         actions: <Widget>[
           (
-            isDiscovering ? 
+            isDiscovering ?
               FittedBox(child: Container(
                 margin: new EdgeInsets.all(16.0),
                 child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.white))
@@ -87,7 +80,19 @@ class _DiscoveryPage extends State<DiscoveryPage> {
           )
         ],
       ),
-      body: ListView(children: list)
+      body: ListView.builder(
+        itemCount: results.length,
+        itemBuilder: (BuildContext context, index) {
+          BluetoothDiscoveryResult result = results[index];
+          return BluetoothDeviceListEntry(
+            device: result.device,
+            rssi: result.rssi,
+            onTap: () {
+              Navigator.of(context).pop(result.device);
+            },
+          );
+        },
+      )
     );
   }
 }