Flutter BLE cannot detect Raspberry Pi 4 Bluetooth

I am trying to connect to my Raspberry Pi 4 bluetooth from a Flutter app.

However, the flutter app is not even recognizing the Raspberry Pi 4 bluetooth.

This is the app screen which only shows the earphone.
App Interface showing the available bluetooth devices

This is my phone’s bluetooth control screen which shows both the Pi – nil and my local PC.
New Pair Screen

Ans this is my code –

    import 'package:flutter/material.dart';
    import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
    import 'dart:async';
    
    class ConnectDeviceScreen extends StatefulWidget {
      @override
      _BluetoothModuleState createState() => _BluetoothModuleState();
    }
    
    class _BluetoothModuleState extends State<ConnectDeviceScreen> {
      final FlutterReactiveBle _ble = FlutterReactiveBle();
      List<DiscoveredDevice> _devices = [];
      StreamSubscription<DiscoveredDevice>? _scanSubscription;
      StreamSubscription<ConnectionStateUpdate>? _connectionSubscription;
      bool _isScanning = false;
    
      @override
      void initState() {
        super.initState();
        _checkBleStatus();
      }
    
      void _checkBleStatus() {
        _ble.statusStream.listen((status) {
          print('BLE status: $status');
          if (status == BleStatus.ready) {
            _startScan();
          }
        });
      }
    
      void _startScan() {
        setState(() {
          _isScanning = true;
          _devices.clear();
        });
    
        _scanSubscription = _ble.scanForDevices(
          withServices: [], // Empty list means scan for all devices
          scanMode: ScanMode.lowLatency,
        ).listen(
          (device) {
            setState(() {
              final knownDeviceIndex =
                  _devices.indexWhere((d) => d.id == device.id);
              if (knownDeviceIndex >= 0) {
                _devices[knownDeviceIndex] = device;
              } else {
                _devices.add(device);
              }
            });
          },
          onError: (Object error) {
            print('Scanning failed: $error');
            setState(() {
              _isScanning = false;
            });
          },
        );
    
        // Stop scanning after 10 seconds
        Timer(Duration(seconds: 60), () {
          _stopScan();
        });
      }
    
      void _stopScan() {
        _scanSubscription?.cancel();
        setState(() {
          _isScanning = false;
        });
      }
    
      Future<void> _connectToDevice(DiscoveredDevice device) async {
        try {
          print('Connecting to ${device.name}...');
          _connectionSubscription = _ble
              .connectToDevice(
            id: device.id,
            connectionTimeout: const Duration(seconds: 5),
          )
              .listen(
            (connectionState) {
              print('Connection state: ${connectionState.connectionState}');
              if (connectionState.connectionState ==
                  DeviceConnectionState.connected) {
                print('Connected to ${device.name}');
                // Here you can perform operations like service discovery,
                // reading/writing characteristics, etc.
                // For example:
                // _discoverServices(device.id);
              }
            },
            onError: (Object error) {
              print('Connection failed: $error');
            },
          );
        } catch (e) {
          print('Failed to connect: $e');
        }
      }
    
      // Example of reading a characteristic
      // You'll need to replace the UUIDs with your specific ones
      Future<void> _readCharacteristic(String deviceId) async {
        final characteristic = QualifiedCharacteristic(
          serviceId: Uuid.parse("YOUR_SERVICE_UUID"),
          characteristicId: Uuid.parse("YOUR_CHARACTERISTIC_UUID"),
          deviceId: deviceId,
        );
        try {
          final response = await _ble.readCharacteristic(characteristic);
          print('Read characteristic: ${response}');
        } catch (e) {
          print('Error reading characteristic: $e');
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text('Bluetooth Devices')),
          body: ListView.builder(
            itemCount: _devices.length,
            itemBuilder: (context, index) {
              return ListTile(
                title: Text(_devices[index].name),
                subtitle: Text(_devices[index].id),
                trailing: ElevatedButton(
                  child: Text('Connect'),
                  onPressed: () => _connectToDevice(_devices[index]),
                ),
              );
            },
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: _isScanning ? _stopScan : _startScan,
            child: Icon(_isScanning ? Icons.stop : Icons.search),
          ),
        );
      }
    
      @override
      void dispose() {
        _scanSubscription?.cancel();
        _connectionSubscription?.cancel();
        super.dispose();
      }
    }

Why can’t the flutter app recognize the Raspberry Pi ? When I am connecting normally, using the default phone pairing method outside the flutter app, it connects fine with Pi.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật