-3

`Can someone help me with some example?

I want to receive notification from a non-stop server on my app in flutter using SSE

Thanks in advance

this is my main. i want to print in a list the data from server.

import 'package:flutter_client_sse/flutter_client_sse.dart'; import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), ); } }

class ListViewHome extends StatelessWidget { @override Widget build(BuildContext context) { return ListView( padding: const EdgeInsets.all(8), children: <Widget>[ ListTile(title: Text('List 1')), ListTile(title: Text('List 2')), ListTile(title: Text('List 3')), ], ); } } Future<void> backgroundhandller(message) async { sendToServer(); } void sendToServer() { SSEClient.subscribeToSSE(url: '``https://qrmenu.testenv.ro/sse``', header: { "Cookie": 'jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2NDMyMTAyMzEsImV4cCI6MTY0MzgxNTAzMX0.U0aCAM2fKE1OVnGFbgAU_UVBvNwOMMquvPY8QaLD138; Path=/; Expires=Wed, 02 Feb 2022 15:17:11 GMT; HttpOnly; SameSite=Strict', "Accept": "text/event-stream", "Cache-Control": "no-cache", }).listen((event) { print('Id: ' + event.id!); print('Event: ' + event.event!); print('Data: ' + event.data!); }); }

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.