💻
Flutter documentation
  • Flutter documentation
    • Starting an App
    • Import
  • Visual Studio Code
  • Widgets
    • Stateless Widget
    • Stateful Widget
    • Scaffold
    • Text
      • OverFlow
      • Rounded background text
    • Padding
    • Align
    • DraggableScrollableSheet
    • Container
    • Decorated box
    • Expanded
    • IntrinsicHeight
    • IntrinsicWidth
    • ListView.builder(...)
    • Buttons
    • Gauge
    • Navigator
      • WillPopScope
    • Web View
    • Divider
    • Future builder
    • Image
      • Cached_network_image
      • Fade In Image
    • ClipOval
    • InkWell
    • Wrap
    • SingleChildScrollView
    • Stack
    • FittedBox
    • DropdownButton
    • ValueListenableBuilder
    • Maps
    • fl_chart
    • Set SystemNavigation Bar Color
    • Onesignal
    • Builder
    • Set orientation
    • SSE
    • Chat
    • Flutter_animate
    • Supabase
      • Android
    • Changing name and package name
    • Sign apk/abb
  • Dart
    • If / Else in one line
    • Functions
  • Others
  • Airtable
Powered by GitBook
On this page
  1. Widgets

SSE

Getting data from the server, little by little

void establishSSEConnection() {
    http.Client client = http.Client();
    http.Request request = http.Request(
        'GET', Uri.parse('http://127.0.0.1:5000/?prompt=cuentame un chiste'));

    StreamSubscription<http.StreamedResponse> streamSubscription;

    streamSubscription = client.send(request).asStream().listen((response) {
      response.stream.listen((event) {
        print('sse');
        print(String.fromCharCodes(event));
        // Handle the received event
        // The event will be of type http.StreamedResponse
        // You can extract data using event.stream or event.stream.bytesToString()
      }, onError: (error) {
        // Handle any error that occurs during the connection or data retrieval
      }, cancelOnError: true);
    }, onError: (error) {
      // Handle any error that occurs while establishing the connection
    });
  }
PreviousSet orientationNextChat

Last updated 2 years ago