androiddatabaseflutterdata-storage

Flutter - storing data localy and accesing them from another users phone


I´am just starting flutter and wanted to ask for a posibility of tracking variable from another users interface

Can I somehow access and pass simple int variable changess via wifi F.E. or do i need to use some backend like firebase.

Thank you !



Solution

  • You could probably take a look at UDP i.e. User Datagram Protocol. The UDP protocol allows the computer applications to send the messages in the form of datagrams from one machine/device to another over the Internet Protocol.

    In Flutter there is a package which can allow you to do this, you can check it out here Link to package and explore the possibilities of what you require.

    The below code shows an example of the how the package works:

        import 'package:udp/udp.dart';
    
        main() async {
        // creates a UDP instance and binds it to the first available network
        // interface on port 65000.
        var sender = await UDP.bind(Endpoint.any(port: Port(65000)));
    
        // send a simple string to a broadcast endpoint on port 65001.
        var dataLength = await sender.send("Hello World!".codeUnits,
        Endpoint.broadcast(port: Port(65001)));
      
        stdout.write("$dataLength bytes sent.");
      
        // creates a new UDP instance and binds it to the local address and the port
        // 65002.
        var receiver = await UDP.bind(Endpoint.loopback(port: Port(65002)));
      
        // receiving\listening
        receiver.asStream(timeout: Duration(seconds: 20)).listen((datagram) {
          var str = String.fromCharCodes(datagram.data);
          stdout.write(str);
        });
      
        // close the UDP instances and their sockets.
        sender.close();
        receiver.close();
      
      
       // MULTICAST
        var multicastEndpoint =
            Endpoint.multicast(InternetAddress("239.1.2.3"), port: Port(54321));
      
        var receiver = await UDP.bind(multicastEndpoint);
      
        var sender = await UDP.bind(Endpoint.any());
      
        receiver.asStream().listen((datagram) {
          if (datagram != null) {
            var str = String.fromCharCodes(datagram?.data);
      
            stdout.write(str);
          }
        });
      
        await sender.send("Foo".codeUnits, multicastEndpoint);
      
        await Future.delayed(Duration(seconds:5));
      
        sender.close();
        receiver.close();
    }