Interfacing with Websockets and Streams in Dart's Flutter Framework

in #utopian-io7 years ago (edited)

What Will I Learn?

Write here briefly the details of what the user is going to learn in a bullet list.

  • You will learn about asynchronous snapshots
  • You will learn how to use the streambuilder widget
  • You will learn how to use the websocket channel library from the flutter sdk

Requirements

Difficulty

  • Intermediate

Description

In this Flutter Video Tutorial, we take a look at the Websocket Channel Library and how we can interface with websockets using the Flutter SDK. We also look at the concept of the asynchronous snapshot and the basic idea behind the StreamBuilder widget. We take these concepts and build out a simple echo chat application which fires off a message to a websocket and then receives the message back as an echo.

The Websocket Channel Library gives us an abstraction that is above streams; a StreamChannel. This StreamChannel wraps the websocket connections in a Sink and a Stream. The Sink handles sending messages and the stream handles receiving messages. We can use the Stream in our Stream Builder Widget by accepting the data in Asynchronous Snapshots. These Snapshots are a central concept in Dart; the idea that we can save state and data as a pool of bytes. This idea originally came from one of Dart's predecessor languages, Smalltalk. Dart uses Snapshots in its virtual machine and in different parts of the language for many different reasons. In this case we are using them to gain access to incremental data cross-sections from our stream.

The source code for this project can be found here

The echo websocket server we used in this tutorial can be found here

Video Tutorial

Projects and Series

Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Minesweeper Game

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for your contribution.

Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Thank you for moderating my contribution.

Excellent contribution and explained in detail.

Thank you, I appreciate the feedback.

Hey @tensor! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Coin Marketplace

STEEM 0.26
TRX 0.20
JST 0.037
BTC 94320.05
ETH 3419.91
USDT 1.00
SBD 3.88