I have been working my graduation project which is "Social network application for my university" it basically have 4 main pages (Home page, news page, messages page and profile page) I followed along with the messaging page with these videos: https://www.youtube.com/watch?v=vgqBc7jni8c&list=PLNBhvhkAJG6sH7dkmwt4BiCclFkMoXq4r
using https://getstream.io/chat/docs/ for Stream chat API and it works just fine
now back to mu issue, I didn't find anyone that has explained Stream Feed API and worked for me, it all has errors even from stream_feed docs didn't work for me
basically I have users (authenticated using Firebase) and I want anyone who is using the app can see anyone's post (or whatever you call it)
this is my app.dart which has some declarations
import 'package:firebase_auth/firebase_auth.dart' as fb;
import 'package:flutter/material.dart';
import 'package:logger/logger.dart' as log;
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_feed/stream_feed.dart' as feeds;
const appId = '';
const streamKey = '';
const streamSecretKey = '';
const feedToken = '';
var logger = log.Logger();
extension StreamChatContext on BuildContext {
String? get currentUserImage => currentUser!.image;
User? get currentUser => StreamChatCore.of(this).currentUser;
}
final fb.FirebaseAuth auth = fb.FirebaseAuth.instance;
final fb.User? user = auth.currentUser;
final uid = user!.uid;
final client = feeds.StreamFeedClient(
streamKey,
secret: streamSecretKey,
);
final userToken = client.frontendToken(uid);
I did declared the stream keys but I have to delete them here
Here is the Home Page I tested but it keeps giving me an error and I don't even know if it's a correct way or not
import 'package:flutter/material.dart';
import 'package:stream_feed/stream_feed.dart' as feeds;
import '../app.dart';
class TestHomePage extends StatefulWidget {
const TestHomePage({Key? key}) : super(key: key);
@override
State<TestHomePage> createState() => _TestHomePageState();
}
final client = feeds.StreamFeedClient(
streamKey,
secret: streamSecretKey,
);
final userToken = client.frontendToken(uid.toString());
final userFeed = client.flatFeed('timeline', userToken.toString());
class _TestHomePageState extends State<TestHomePage> {
@override
void initState() {
super.initState();
client.setUser(feeds.User(id: uid), userToken);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('User Feed'),
),
body: FutureBuilder<List<feeds.Activity>>(
future: userFeed.getActivities(limit: 10),
builder: (context, snapshot) {
if (snapshot.hasData) {
final activities = snapshot.data!;
return ListView.builder(
itemCount: activities.length,
itemBuilder: (context, index) {
final activity = activities[index];
return ListTile(
title: Text(activity.actor ?? ''),
subtitle: Text(activity.verb ?? ''),
);
},
);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
),
);
}
}
if anyone can help me to create and implement the correct way to show/use the feed from https://getstream.io/ I would be Thankful
(if there's a better way then it is welcomed)
btw this is the error I get:
AssertionError (Assertion failed: "userToken
must be provided while running on client-side please make sure to call client.setUser")
pointed at this line: final userToken = client.frontendToken(uid.toString());