Skip to content

Commit

Permalink
Displaying Timeline Posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Amorem committed Aug 24, 2019
1 parent 6aff6ab commit 2118b3d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import 'timeline.dart';
import 'upload.dart';

final GoogleSignIn googleSignIn = GoogleSignIn();
final DateTime timestamp = DateTime.now();
User currentUser;

final StorageReference storageRef = FirebaseStorage.instance.ref();
final CollectionReference usersRef = Firestore.instance.collection('users');
final CollectionReference postsRef = Firestore.instance.collection('posts');
Expand All @@ -26,8 +29,8 @@ final CollectionReference followersRef =
Firestore.instance.collection('followers');
final CollectionReference followingRef =
Firestore.instance.collection('following');
final DateTime timestamp = DateTime.now();
User currentUser;
final CollectionReference timelineRef =
Firestore.instance.collection('timeline');

class Home extends StatefulWidget {
@override
Expand Down Expand Up @@ -131,7 +134,7 @@ class _HomeState extends State<Home> {
return Scaffold(
body: PageView(
children: <Widget>[
Timeline(),
Timeline(currentUser: currentUser),
ActivityFeed(),
Upload(currentUser: currentUser),
Search(),
Expand Down
42 changes: 41 additions & 1 deletion lib/pages/timeline.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,63 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:fluttershare/models/post.dart';
import 'package:fluttershare/models/user.dart';
import 'package:fluttershare/pages/home.dart';
import 'package:fluttershare/widgets/post_widget.dart';
import 'package:fluttershare/widgets/progress.dart';

import '../widgets/header.dart';

class Timeline extends StatefulWidget {
final User currentUser;
Timeline({this.currentUser});

@override
_TimelineState createState() => _TimelineState();
}

class _TimelineState extends State<Timeline> {
List<PostWidget> posts = [];
@override
void initState() {
super.initState();
getTimeline();
}

getTimeline() async {
QuerySnapshot snapshot = await timelineRef
.document(widget.currentUser.id)
.collection('timelinePosts')
.orderBy('timestamp', descending: true)
.getDocuments();
List<PostWidget> posts = snapshot.documents
.map((doc) => PostWidget(Post.fromDocument(doc)))
.toList();
setState(() {
this.posts = posts;
});
}

buildTimeline() {
if (posts == null) {
return circularProgress();
} else if (posts.isEmpty) {
return Text('No posts');
} else {
return ListView(
children: posts,
);
}
}

@override
Widget build(context) {
return Scaffold(
appBar: header(context, isAppTitle: true),
body: Text('Timeline'),
body: RefreshIndicator(
onRefresh: () => getTimeline(),
child: buildTimeline(),
),
);
}
}

0 comments on commit 2118b3d

Please sign in to comment.