pusher flutter code example

Example: pusher connect flutter

pusher_websocket_flutter: ^0.1.1
 
 try {
      await Pusher.init(
          "Appid",
          PusherOptions(
            auth: PusherAuth(url, headers: {
              'Content-Type': 'application/json',
              'Authorization': 'Bearer ' + token
            }),
            cluster: "ap2",
            encrypted: true,
          ),
          enableLogging: true);
    } on PlatformException catch (e) {
      print(e.message);
    }

    Pusher.connect(onConnectionStateChange: (x) async {
      print(x.currentState);
    }, onError: (x) {
      debugPrint("Error: ${x.exception}");
    });
    channel = await Pusher.subscribe(
        'private-message-1'}');
    channel.bind('newmessage', (onEvent) {
	print(onEvent.data)

    });

Tags:

Misc Example