title: Is there a way to access data coming from BLE device from single file which keeps updating?
body: <p>I want to access characteristic values of BLE from one dart file, What I am doing is that I am connecting the device from one activity and then sending the device info to all other activities. But to get values I have to write the same code again and again to all activities/dart files.
  For example i am connecting device in an activity like this:</p>
  <pre><code>StreamBuilder&lt;List&lt;ScanResult&gt;&gt;(
                  stream: FlutterBlue.instance.scanResults,
                  initialData: [],
                  builder: (c, snapshot) =&gt; Column(
                    children: snapshot.data
                        .map(
                          (r) =&gt; ScanResultTile(
                        result: r,
                        onTap: () =&gt; Navigator.of(context)
                            .push(MaterialPageRoute(builder: (context) {
                          r.device.connect();
                          print('DEVICE CONNECTED');
                          return BluetoothConnectedSuccess(device: r.device);
  </code></pre>
  <p>Here <code>device: r.device</code> is the device that i have connected to my Flutter App. Now if i want to display device data i have to initilaze these lines of code everytime i jump to any screen/activity:</p>
  <pre><code>class BluetoothConnectedSuccess extends StatefulWidget {
    const BluetoothConnectedSuccess({Key key, this.device}) : super(key: key);
    final BluetoothDevice device;
    @override
    _BluetoothConnectedSuccessState createState() =&gt;
        _BluetoothConnectedSuccessState();
  }
  
  class _BluetoothConnectedSuccessState extends State&lt;BluetoothConnectedSuccess&gt; {
      // BLE
        final String SERVICE_UUID = &quot;4fafc201-1fb5-459e-8fcc-c5c9c331914b&quot;;
        final String CHARACTERISTIC_UUID = &quot;beb5483e-36e1-4688-b7f5-ea07361b26a8&quot;;
        bool isReady;
        Stream&lt;List&lt;int&gt;&gt; stream;
        List&lt;int&gt; lastValue;
        List&lt;double&gt; traceDust = List();
      
        @override
        void initState() {
          super.initState();
          isReady = false;
          connectToDevice();
        }
      
        connectToDevice() async {
          await widget.device.connect();
          discoverServices();
        }
      
        discoverServices() async {
          List&lt;BluetoothService&gt; services = await widget.device.discoverServices();
          services.forEach((service) {
            if (service.uuid.toString() == SERVICE_UUID) {
              service.characteristics.forEach((characteristic) {
                if (characteristic.uuid.toString() == CHARACTERISTIC_UUID) {
                  characteristic.setNotifyValue(!characteristic.isNotifying);
                  stream = characteristic.value;
                  print(stream);
                  lastValue = characteristic.lastValue;
                  print(lastValue);
      
                  setState(() {
                    isReady = true;
                  });
                }
              });
            }
          });
        }
      
        _dataParser(List&lt;int&gt; data) {
          var value = Uint8List.fromList(data);
          print(&quot;stream.value: $value&quot;); // stream.value: [33]
          var hr = ByteData.sublistView(value, 0, 1);
          print(&quot;Heart rate: ${hr.getUint8(0)}&quot;);
          return hr.getUint8(0); // Heart rate: 33
        }
  </code></pre>
  <p>It's creating a lot of mess to write the same code again and again to the activities where BLE data is needed.
  Is there a way to only call this connected device from a single file instead of initializing the same code in every activity?</p>
  <p>This is the link to my <a href="https://github.com/nabiasalman99/Epicare-Medical-App" rel="nofollow noreferrer">repo</a> for a look at what I am doing on every activity/screen with BLE device data.
  Please help me out as I am new to Flutter. Thank you</p>