Building a Flutter Chat Application with Stream: Configuration (Part 2)
Tags: mobiledevelopment, flutter, stream, chatapplication
Published: 2020-10-20 13:11:00


## Building a Flutter Chat Application with Stream: Configuration (Part 2)

![](https://cdn-images-1.medium.com/max/2000/1*Hw0DRh6aJvQALyyIM7v0zg.png)

This article is part of a series on building a fully functional Flutter app with Stream. All other parts, as well as the finished code, can be found below.

[Part 1: Introduction](https://medium.com/flutter-community/building-a-flutter-chat-application-with-stream-introduction-part-1-901977551169)

[Part 3: Building the App](https://medium.com/flutter-community/building-a-flutter-chat-application-with-stream-building-the-app-part-3-f18f9c810ba8)

[SpikeChat Github Project](https://github.com/ashtonjonesdev/spike_chat)

## Configuration:

There is quite a bit of configuration I had to do before I could start using Stream’s SDK. Below is a synopsis of all the configuration:

* Pubspec.yaml dependencies

* Configuration of Stream App

* Code for constants class

* Co-dependencies configuration for iOS

* Code for authorization configuration using [start_jwt](https://pub.dev/packages/start_jwt/)

### Pubspec.yaml Dependencies

In order to use Stream, I needed to add the [stream_chat_flutter](https://pub.dev/packages/stream_chat_flutter), along with [flutter_file_picker](http://flutter_file_picker plugin), [video_player](https://pub.dev/packages/video_player), and [image_picker](https://pub.dev/packages/image_picker), which are required to enable full functionality of Stream’s APIs on iOS.

 <iframe src="https://medium.com/media/e4e4e60a26e5e8b7bf710f2394e611c9" frameborder=0></iframe>

### Configuration of Stream App

First, I needed to create an account with [Stream](https://getstream.io/). They allow developers a 30 day trial period to try out their Chat and Feed APIs.

After creating an account, I created a Stream project called “SpikeChat” for my Flutter application with development mode selected. After creating the app, an app key and app secret is generated, which will be used to authenticate the app with Stream.

![](https://cdn-images-1.medium.com/max/3840/1*FPjMaC5inlM7aRCvmt8NMQ.png)

Next, I created a chat type called “mobile” by selecting the app then clicking chat-> chat overview-> add chat type.

In order to allow users to write and read (send and see) messages, I had to scroll down to permissions and add the “user” in “roles” to give users the same access as the administrator.

![](https://cdn-images-1.medium.com/max/3840/1*yOKtnNgJJAg8R9l1useDyA.png)

### Configuration for Constants class:

After configuring the Stream app, I put the Stream app key and secret in a constants class that are used when authenticating with the Stream client:

 <iframe src="https://medium.com/media/d59507ae8b81834beebb4b9d3a26145d" frameborder=0></iframe>

### Co-dependencies Configuration for iOS:

In order to get the full functionality of Stream to work on iOS, I had to do some additional configuration. I needed to add permissions to the info.plist file, highlighted between the comments below. Most of the co-dependencies are good to go with Android, but you may need to do some additional configuration if you are targeting older APIs. If you want to read more in depth about why you need these and ensure you are correctly configured for Android, check out the [stream_chat_flutter plugin’s readme](https://pub.dev/packages/stream_chat_flutter).

 <iframe src="https://medium.com/media/7225bde97493aa9fb717a2f5b487251a" frameborder=0></iframe>

### Code for Authorization Configuration Using start_jwt

I was stuck for awhile trying to figure out how to authorize my app with Stream’s APIs. Unfortunately, the [documentation for authentication on Flutter ](https://getstream.io/chat/docs/tokens_and_authentication/?language=dart)is lacking. This was pretty frustrating because I was stuck for a couple days and unable to move forward.

![](https://cdn-images-1.medium.com/max/3840/1*i1fi8EpvO6UK2xRMtK9U3A.png)

Luckily I was able to figure out how to implement authentication. In order to authenticate the user, I used the [start_jwt](https://pub.dev/packages/start_jwt/) plugin to generate a JSON web token with my Stream app secret. The method ‘tokenProvider’ uses the Stream app secret to create a token, and also adds the username to the client. I explain more about how this works in part 3.

 <iframe src="https://medium.com/media/43e408e97b550d48c3654e1e5f70d81f" frameborder=0></iframe>

## Up Next:

In part 3, I’ll explain how I built the app using Stream’s widgets.

If you want to follow along, here is the SpikeChat project:
(https://github.com/ashtonjonesdev/spike_chat)

## Resources:

* [SpikeChat Github project](https://github.com/ashtonjonesdev/spike_chat)

* [Stream website](https://getstream.io/)

* [Stream Initialization and Users in Dart](https://getstream.io/chat/docs/init_and_users/?language=dart)

* [Stream Tokens and Authentication in Dart](https://getstream.io/chat/docs/tokens_and_authentication/?language=dart)

* [stream_chat_flutter plugin](https://pub.dev/packages/stream_chat_flutter)

* [flutter_file_picker plugin](https://github.com/miguelpruivo/flutter_file_picker)

* [video_player plugin](https://pub.dev/packages/video_player)

* [image_picker plugin](https://pub.dev/packages/image_picker)

* [start_jwt plugin](https://pub.dev/packages/start_jwt/)

Hi, I’m Ash 👋🏼 Let’s connect!

🌐 [ashtonjones.dev](https://ashtonjones.dev/#/)|👥 **@TJgrapes**|✉️ [ashtonjonesdev@gmail.com](mailto:ashtonjonesdev@gmail.com)

👨‍💻 Google Certified Android Engineer |
✍ Writer |
🧘‍♂️ Stoic && Meditator

📱 Need an app built? Contact me [here](mailto:ashtonjones.dev?subject=Hi%20Ashton!).

![](https://cdn-images-1.medium.com/max/2000/1*8D0WQH0Y7-hCiy_AxI-Xnw.png)

![[https://www.twitter.com/FlutterComm](https://www.twitter.com/FlutterComm)](https://cdn-images-1.medium.com/max/2400/1*AuT0GXEd7j21RI6uXlxYTQ.png)