0

Hey lovely flutter developers,

I have successfully created a connection from my flutter app to my laravel-websocket server and I can display triggered events from laravels tinker console in the flutter console, but can't figure out how to display them in the app?

When I'm trying to build a StreamBulder, I get the Error that the getter _channel isn't defined for MyAppState.

Or when I declare a channel like Channel _cannel = pusher.subscribe(...).bind(), I get another Error: A value of type 'Future' can't be assigned to a variable of type 'Channel'.

  • 'Future' is from 'dart:async'.
  • 'Channel' is from 'package:laravel_flutter_pusher/laravel_flutter_pusher.dart'
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:laravel_flutter_pusher/laravel_flutter_pusher.dart';


void main() async {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    setUpServices();
  }

  void setUpServices() {
    var options = PusherOptions(
        host: '127.0.0.1', port: 6001, encrypted: false, cluster: 'mt1');

    LaravelFlutterPusher pusher =
        LaravelFlutterPusher('local', options, enableLogging: true);
    pusher
        .subscribe('test-channel')
        .bind('test-event', (event) => print('event =>' + event.toString()) );
  }



  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Websocket Example'),
        ),
        body: Center(
          child: Text('Here I would like to display the message from the websocket'),
        ),
      ),
    );
  }
}


Can someone please push me in the right direction what I have to read/learn next to display the websockt message in the app?

m1ge0
  • 3
  • 1

0 Answers0