How do I show a tick mark on the connected bluetooth device in Flutter?

Viewed 27

So I need to show a tick mark alongside the connected bluetooth device and I want the tick mark to show through the entire app session if the bluetooth device is connected. The functionality that I have kept is,

1- We tap on the bluetooth device.

2- The tick mark appears on the right of the selected bluetooth device.

3- Then we tap on the connect button to connect to the device.

The tick mark does not appear on the right of selected bluetooth device after I come back on the screen.

So far the method I have tried is:

  • To set the tick mark in Visibility widget and save the boolean of visible in SharedPreferences to save the status throughout the app session, but it doesn't seem to work.

I would like the tick mark to stay alongside the connected bluetooth device if its connected and throughout the app session it should appear there even if i come to the screen.

Here is the code for streambuilder that prints the list of bluetooth devices:

StreamBuilder<List<BluetoothDevice>>(
                  stream: bluetoothPrint.scanResults,
                  initialData: [],
                  builder: (c, snapshot) => snapshot.data != null
                    ? Column(
                    children: snapshot.data!.map((d) => ListTile(
                      title: Text(d.name??''),
                      subtitle: Text(d.address.toString()),
                      onTap: (){
                        setState(() {
                          _device = d;
                          globalDevice = _device;
                        });
                      },
                      trailing: _device?.address==d.address?
                      Text('connected'): Text('not connected'),
                    )).toList(),
                  )
                    : Column(
                    children: [
                      SizedBox(height: 220),
                      Text(
                        "No bluetooth devices in range.",
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 16.0,
                            color: Colors.black),
                        textAlign: TextAlign.center,
                      ),
                    ],
                  )
                ),

0 Answers
Related