Minimal example
This shows the minimal possible example to integrate Flutter Nakama into your app.
đ¨âđģ Minimal example
In this example we initialize the Nakama SDK, sign in as a static user and create a match where other user's can join later on.
Initialize SDK
After booting the app, initialize Nakama SDK with required parameters:
You can optionally provide httpPort
and grpcPort
if you want to customize them. Default values are same as Nakama's default ports.
Sign In
Sign in with the user's credentials, for example with email & password:
Tip: there is no difference between sign in and sign up at Nakama. You can find out via
session.created
if the account has been created or it is a recurring sign in.
You receive an instance of Session which contains userId
and accessToken
among others. You are now logged in.
Initialize / create WebSocket connection
All realtime communication runs though a WebSocket connection. You need to initialize this once after authentication. Then you establish a connection until the user closed the app:
Don't forget to close after disposing the app widget:
Create & join a match
The simplest thing is to create a match and join with another's account.
On another instance:
Match / Realtime Data
flutter_nakama provides a handy way to listen to realtime events sent from the Nakama server. For example you can listen on match data:
You can send match data from your client like so:
Please refer to the Realtime Multiplayer docs on more detailed information on how the realtime data works and which fields are available to use.
You are absolutely free on what and how sending match data. You are free to use JSON or protobuf while the latter might result in very good performance. But you can also just send free text.
Last updated