eventflux 0.5.0 copy "eventflux: ^0.5.0" to clipboard
eventflux: ^0.5.0 copied to clipboard

outdated

EventFlux: A Dart package for efficient handling of server-sent event streams with easy connectivity and data management.

example/lib/main.dart

import 'dart:developer';

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

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              TextButton(
                  onPressed: () {
                    String url = 'https://example.com/events';
                    try {
                      EventFluxResponse response = EventFlux.instance.connect(
                        EventFluxConnectionType.get,
                        url,
                        onConnectionClose: () {
                          log('Connection Closed');
                        },
                      );
                      if (response.status == EventFluxStatus.connected) {
                        response.stream?.listen((event) {
                          log('Revieved Event');
                        });
                      } else {
                        log('Error');
                      }
                    } catch (e) {
                      if (e is EventFluxException) {
                        log('Error Message: ${e.message}');
                      }
                    }
                  },
                  child: const Text("Connect")),
              TextButton(
                  onPressed: () {
                    try {
                      EventFluxStatus status = EventFlux.instance.disconnect();
                      log('Status: $status');
                    } catch (e) {
                      if (e is EventFluxException) {
                        log('Error Message: ${e.message}');
                      }
                    }
                  },
                  child: const Text("Disconnect")),
              TextButton(
                  onPressed: () {
                    String url = 'https://example.com/events';
                    try {
                      EventFluxResponse response = EventFlux.instance
                          .reconnect(EventFluxConnectionType.get, url);
                      if (response.status == EventFluxStatus.connected) {
                        response.stream?.listen((event) {
                          log('Event: ${event.data}');
                        });
                      } else {
                        log('Error');
                      }
                    } catch (e) {
                      if (e is EventFluxException) {
                        log('Error Message: ${e.message}');
                      }
                    }
                  },
                  child: const Text("Reconnect")),
            ],
          ),
        ),
      ),
    );
  }
}
89
likes
0
points
10.4k
downloads

Publisher

verified publishergokula.dev

Weekly Downloads

EventFlux: A Dart package for efficient handling of server-sent event streams with easy connectivity and data management.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http

More

Packages that depend on eventflux