stream_feed_flutter_core 0.4.0+1 stream_feed_flutter_core: ^0.4.0+1 copied to clipboard
Stream Feed official Flutter SDK Core. Build your own feed experience using Dart and Flutter.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:stream_feed_flutter_core/stream_feed_flutter_core.dart';
Future<void> main() async {
const apiKey = String.fromEnvironment('key');
const userToken = String.fromEnvironment('user_token');
final client = StreamFeedClient(
apiKey,
token: const Token(userToken),
);
await client.setUser(
const User(
id: 'GroovinChip',
data: {
'handle': '@GroovinChip',
'first_name': 'Reuben',
'last_name': 'Turner',
'full_name': 'Reuben Turner',
'profile_image': 'https://avatars.githubusercontent.com/u/4250470?v=4',
},
),
const Token(userToken),
);
runApp(
MyApp(client: client),
);
}
class MyApp extends StatelessWidget {
const MyApp({
Key? key,
required this.client,
}) : super(key: key);
final StreamFeedClient client;
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: (context, child) => FeedProvider(
bloc: FeedBloc(
client: client,
),
child: child!,
),
home: HomePage(client: client),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({
Key? key,
required this.client,
}) : super(key: key);
final StreamFeedClient client;
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: FlatFeedCore(
feedGroup: 'user',
userId: widget.client.currentUser!.id,
feedBuilder: (BuildContext context, activities, int index) {
return InkWell(
child: ListTile(
title: Text('${activities[index].actor!.data!['handle']}'),
subtitle: Text('${activities[index].object}'),
),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => Scaffold(
body: ReactionListCore(
lookupValue: activities[index].id!,
reactionsBuilder: (context, reactions, idx) => Text(
'${reactions[index].data?['text']}',
),
),
),
),
);
},
);
},
),
);
}
}