lightstreamer_flutter_client 1.0.0 copy "lightstreamer_flutter_client: ^1.0.0" to clipboard
lightstreamer_flutter_client: ^1.0.0 copied to clipboard

outdated

A lutter plugin for Lightstreamer, built on top of Android SDK.

Lightstreamer Flutter Plugin #

A Flutter plugin for Lightstreamer, built on top of Android SDK. The support of iOs environment will follow shortly.

Getting Started #

Import the package

import 'package:lightstreamer_flutter_client/lightstreamer_flutter_client.dart';

Configure and Start a Lightstreamer Client Session

To connect to a Lightstreamer Server a LightstreamerClient object has to be created, configured, and instructed to connect to a specified endpoint. The platform-specific implementation will take care of this when it receives a 'connect' command on the specific MethodChannel. A minimal version of the code which through the 'connect' command connect to the public Lightstreamer Demo Server (on https://push.lightstreamer.com) will look like this:

    String currentStatus;

    try {
      Map<String, String> params = {"user": "prova1", 
             "password": "qwerty!"};

      currentStatus = await LightstreamerFlutterClient.connect(
              "https://push.lightstreamer.com/", "WELCOME", params) ??
          'Unknown client session status';
    } on PlatformException catch (e) {
      currentStatus =
          "Problems in starting a session with Lightstreamer: '${e.message}' .";
    }

    setState(() {
      _status = currentStatus;
    });

The below code allow the application to listen for any real-time connection state change events:

    LightstreamerFlutterClient.setClientListener(_clientStatus);

    void _clientStatus(String msg) {
    setState(() {
      _status = msg;
    });
  }

Receive Real-Time Updates

In order to receive real-time updates from the Lightstreamer server the client needs to subscribe to specific Items handled by a Data Adapter deployed at the server-side. This can be accomplished by instantiating an object of type Subscription. For more details about Subscription in Lightstreamer see the section 3.2 of the Lightstreamer General Concepts documentation. A sample of code that subscribes three Items of the classic Stock-List example is:

    String static_sub_id = "";

    String? subId = "";
    try {
      Map<String, String> params = {
        "dataAdapter": "STOCKS",
        "requestedMaxFrequency": "7",
        "requestedSnapshot": "yes"
      };
      subId = await LightstreamerFlutterClient.subscribe(
          "MERGE",
          "item2,item7,item8".split(","),
          "last_price,time,stock_name".split(","),
          params);

      static_sub_id = subId as String;

      LightstreamerFlutterClient.setSubscriptionListener(subId, _values);
    } on PlatformException catch (e) {
      // ...
    }

The below code shows an example of implementation of the callback to listen for any real-time updates from your subcriptions:

  void _values(String item, String fieldName, String fieldValue) {
    setState(() {
      _lastUpdate = item + "," + fieldName + "," + fieldValue;
      highlightcolorLast = Colors.yellow;
    });
  }

This code allow to unsubscribing from receiving messages for the previous subscription:

    try {
      await LightstreamerFlutterClient.unsubscribe(static_sub_id);
    } on PlatformException catch (e) {
      // ...
    }

Send Client Messages to the Server

The client can also send messages to the server:

    try {
      await LightstreamerFlutterClient.sendMessageExt(
           "Hello World", "Sequence1", 5000, _clientmessages, true);
    } on PlatformException catch (e) {
      // ...
    }

The below code shows an example of implementation of the callback to listen for send message feedback:

    void _clientmessages(String msg) {
        setState(() {
            _status = msg;
        });
    }

A full running example app is included in the project under example folder.

External Documentations #

7
likes
0
points
118
downloads

Publisher

verified publisherlightstreamer.com

Weekly Downloads

A lutter plugin for Lightstreamer, built on top of Android SDK.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on lightstreamer_flutter_client