11import 'package:flutter/material.dart' ;
22import './widgets/DeviceListItem.dart' ;
3+ import '../../util/apis/discovery.dart' ;
4+ import '../../util/data/Device.dart' ;
35
46class Discovery extends StatefulWidget {
57 const Discovery ({
@@ -16,18 +18,21 @@ class Discovery extends StatefulWidget {
1618}
1719
1820class DiscoveryState extends State <Discovery > {
19- List <Map < String , String > > devices;
21+ List <Device > devices;
2022
2123 @override
2224 void initState () {
23- devices = new List <Map <String , String >>();
24- devices.add ({"id" : "A" });
25- devices.add ({"id" : "B" });
26- devices.add ({"id" : "C" });
25+ devices = new List <Device >();
2726 super .initState ();
27+
28+ getDiscoveredList ().then ((fetchedDevices) {
29+ updateDeviceList (fetchedDevices);
30+ }).catchError ((onError) {
31+ print ("Error fetching device list" );
32+ });
2833 }
2934
30- void updateDeviceList (List <Map < String , String > > newDeviceList) {
35+ void updateDeviceList (List <Device > newDeviceList) {
3136 // TODO: Add a compasion mechanism
3237 setState (() {
3338 devices = newDeviceList;
@@ -42,7 +47,6 @@ class DiscoveryState extends State<Discovery> {
4247
4348 @override
4449 Widget build (BuildContext context) {
45-
4650 return Scaffold (
4751 appBar: AppBar (
4852 title: const Text ("New devices" ),
@@ -51,7 +55,7 @@ class DiscoveryState extends State<Discovery> {
5155 child: new ListView .builder (
5256 itemCount: devices.length,
5357 itemBuilder: (BuildContext context, int index) {
54- return new DeviceListItem (deviceID: devices[index][ "id" ] );
58+ return new DeviceListItem (deviceID: devices[index].id );
5559 })),
5660 );
5761 }
0 commit comments