create account

Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story) by ideba

View this thread on: hive.blogpeakd.comecency.com
· @ideba ·
$28.47
Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)
### Repository

https://github.com/enyason/Syde

<center>![SPLASH SCREEN.png](https://cdn.steemitimages.com/DQma5umohSERmjPHNnk9ZvG1gKJmnrJWEGtUd1hCAMNi6ft/SPLASH%20SCREEN.png)</center>
### History

- ##### [Implementing Syde An online Forum in Flutter (Update 2 : Post A Story, Retrieve All Stories)](https://steemit.com/utopian-io/@ideba/implementing-syde-an-online-forum-in-flutter-update-2--post-a-story-retrieve-all-stories-)

- [Implementing Syde An online Forum in Flutter (Update : Authenticate With Google)](https://steemit.com/utopian-io/@ideba/implementing-syde-an-online-forum-in-flutter-update--authenticate-with-google)

- [Implementing Syde(An online Forum) in Flutter](https://steemit.com/utopian-io/@ideba/implementing-sydean-online-forum-in-flutter)

  







### New Features

- **Add  comments to a story**
- **UI Update**
  

### Add comments to a story

Beyond creating a story on the platform, users can also comment on a specific story. This feature which is part of the back-end implementation is Handled by Fire-base. 

***Implementation***

- **Create a Comment Object**

  ```
  class Comment {
  
    String commentBody, commentId, userId, timeStamp;
    Comment({this.commentBody, this.commentId, this.userId, this.timeStamp});
  
    factory Comment.fromMap(Map comment) {
      return Comment(
        commentBody: comment["comment_body"],
        commentId: comment["comment_id"],
        timeStamp: comment["time_stamp"],
        userId: comment["user_id"],
      );
    }
  
    Map<String, dynamic> toMap() {
      return {
        "comment_body": commentBody,
        "comment_id": commentId,
        "time_stamp": timeStamp,
        "user_id": userId
      };
    }
  }
  ```

  - This class shows a basic structure of the comment object

- **Add a Comment**

  ```
  addComment(){
  
      Map<String, dynamic> data = Comment(
          commentBody: _controller.value.text,
          commentId: "na",
          userId: _user.uid,
          timeStamp: DateTime.now()
              .millisecondsSinceEpoch
              .toString())
          .toMap();
  
      _controller.clear();
      _commentRef.add(data).then((docRef) {
  
  
        _commentRef
            .document(docRef.documentID)
            .updateData({"comment_id": docRef.documentID});
  
        incrementComment(widget.story.storyId);
  
      }
  
      );
      
    }
  ```

  - This method takes the users message from the text-field  and adds it to the lists of comments

- **Increment Comment Count**

  ```
  incrementComment(String docRef) async {
      //use transaction on the fire store instance to prevent race condition
      Firestore.instance.runTransaction((transaction) async {
        //get a document snapshot at the current position
        DocumentSnapshot snapshot =
        await transaction.get(Firestore.instance.collection("all_post").document(docRef));
  
        //increment comment count for the story
        await transaction.update(snapshot.reference,
            {"comment_count": snapshot.data["comment_count"] + 1});
  
      });
    }
  ```

  - To Keep track of the number of comments, I have a field called "comment_count"
  - This method gets the document reference and increments the number by 1

- **Listen to  Comment Count** 

  ```
  StreamBuilder(
  	stream: Firestore.instance                                      	   .collection("all_post")                                         .document(document.data.documents[index]                                         ["post_id"]).snapshots(), builder: (BuildContext context,
   AsyncSnapshot snapshot) {
  	return Padding(
     		 padding: const EdgeInsets.only(right: 20.0),
      	 child: Row(
                      children: <Widget>[
                    		 Icon(Icons.chat_bubble_outline,
                       	   color: Colors.grey, size: 18.0),
            				  Text(      snapshot.data == null
                                                    ? "0"
                                                    : snapshot
                                                        .data["comment_count"]
                                                        .toString(),
                                                style: TextStyle(
                                                    color: Colors.grey,
                                                    fontSize: 10.0),
                                              ),
                                            ],
                                          ),
                                        );
                                      },
                                    )),
  ```

  - With the stream builder widget, I listen to the node that carries the "comment_count" filed. With this, there is a real-time update of the number of comments made on a particular story



<center>
<p float="left">
  <img src="/https://steemitimages.com/p/2bP4pJr4wVimqCWjYimXJe2cnCgn9eVrBqRBsERBjX4?format=match&mode=fit&width=640&height=600.png"  />
  <img src="/https://steemitimages.com/p/4W3i2hyrJTVfeKM2gnkYJZVrfqSuqn15iebdkSwKmQKMDjDNH96?format=match&mode=fit&width=640&height=600" /> 

</p>
</center>





### More UI Layouts

<center>
<p float="left">
  <img src="/https://steemitimages.com/p/2bP4pJr4wVimqCWjYimXJe2cnCgnLqBAjKPbziY55LS?format=match&mode=fit&width=640&height=500.png" width="100" />
  <img src="/https://steemitimages.com/p/2bP4pJr4wVimqCWjYimXJe2cnCgnKZrVqgFdDdpfZ3L?format=match&mode=fit&width=640&height=500.png" width="100" /> 
  <img src="/https://steemitimages.com/p/2ADPRBseKViToZTQ1BqZsv9HK2WaGBarbJx3Xi6yVy74uarn7oJeYLfuccytGk3WE6rPvXHwN6KRg4tKPWyZAPS7m6TVphoSXEg5WLhT8EYYEm2gW6oLRaUn6AVVe1wcL1QfzFfhVQJX3jMPftezDtB7wTZPS29cu8ia2XkrCVJ86kFqs5ecys6PMwfHQmN1PVWBpmuYU3R6xk3ekayQaAmLmzYefjzfTLKwVFeXzcUL5gaaTGUja6z5oK6GM2KWk6GAxaKJj29KupzRJTGf1JtifkgmjgAGPk8RGZYgxYezSA3hkLrddKkSz3H93QNCVMLKKfNyk6yowSXrgmMjp3xM869qbSH43KCqT9KLVqHQHtwTtsMrnChjSptxUwsmgzHWy7bWR3ZsdhSoMEmSikkFR4M23LToes7m?format=match&mode=fit&width=640&height=500" width="100" />
</p>
</center>

Minor modifications have been made, as specified by my designer. Link to complete UI design https://www.figma.com/file/Rb5CIpYQoOtFI52awQrC6Yo7/SydeTeam 



**N/B**

Other functionalities stated in the GitHub commits are still in a basic structure. As these functionalities are updated to work fully, I will duly write about them.  

### IMPORTANT RESOURCES

*Github *: https://github.com/enyason/Syde



### Road Map

- ~~Authenticate User~~
- ~~Persisting user post~~
- ~~Displaying all post~~
- ~~Detailed screen implementation~~
- ~~Story Reaction Implementation (like and unlike a story)~~
- ~~Adding Comments to a story~~
- Searching all posts
- ~~Providing different layouts~~
- ToDo for users to track their daily progress
- Push Notifications
- Posts sharing
- Users dashboard
- Searching all users
- Direct Messaging with Users
- ChatGroup
- Bookmarking post


### How to contribute?

You can reach me by commenting on this post or send a message via enyasonjnr@gmail.com.
If you want to make this application better, you can make a Pull Request. [Github](https://github.com/enyason/Syde)
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 149 others
properties (23)
authorideba
permlinkimplementing-syde-an-online-forum-in-flutter-update-3--add-comments-to-a-story
categoryutopian-io
json_metadata{"tags":["utopian-io","development","dart","flutter","firebase"],"app":"steem-plus-app"}
created2019-04-06 23:59:03
last_update2019-04-06 23:59:03
depth0
children6
last_payout2019-04-13 23:59:03
cashout_time1969-12-31 23:59:59
total_payout_value21.335 HBD
curator_payout_value7.138 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,148
author_reputation10,184,429,675,092
root_title"Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)"
beneficiaries
0.
accountsteemplus-pay
weight100
1.
accountutopian.pay
weight500
max_accepted_payout100,000.000 HBD
percent_hbd10,000
post_id82,604,838
net_rshares48,194,500,439,753
author_curate_reward""
vote details (213)
@emrebeyler ·
$8.25
Hi there,

Syde looks good. I have some feedback about the Utopian compatibility:

- Your project needs an open-source license. Without a proper license, we cannot say the project is open source nor free software. Check out [this link](https://opensource.org/licenses) for the open-source licenses and [this link](https://help.github.com/en/articles/adding-a-license-to-a-repository) to find out how to add a license to your Github project. You have been warned before about this, so please add an open-source license. :)

- It's essential for Utopian moderators to see the changeset in an organized manner. So, adding the related commits or pull requests to the contribution helps us to see what's changed with the related update.

I am hoping to see these issues fixed with the next update. Cheers.

***

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/3/3-2-2-2-2-1-2-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , , , , , ,
properties (23)
authoremrebeyler
permlinkre-ideba-implementing-syde-an-online-forum-in-flutter-update-3--add-comments-to-a-story-20190410t103421662z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://opensource.org/licenses","https://help.github.com/en/articles/adding-a-license-to-a-repository","https://join.utopian.io/guidelines","https://review.utopian.io/result/3/3-2-2-2-2-1-2-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-04-10 10:34:21
last_update2019-04-10 10:34:21
depth1
children2
last_payout2019-04-17 10:34:21
cashout_time1969-12-31 23:59:59
total_payout_value6.288 HBD
curator_payout_value1.959 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,255
author_reputation448,535,049,068,622
root_title"Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,799,837
net_rshares13,362,753,627,295
author_curate_reward""
vote details (17)
@ideba ·
Thanks for reviewing my contribution...  Regarding the licensing,  I had looked into it but didn't add it to this update.  Thanks for the suggestion and I'll work towards making the changes you have outlined.
πŸ‘  
properties (23)
authorideba
permlinkre-emrebeyler-re-ideba-implementing-syde-an-online-forum-in-flutter-update-3--add-comments-to-a-story-20190410t122324732z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2019-04-10 12:23:30
last_update2019-04-10 12:23:30
depth2
children0
last_payout2019-04-17 12:23:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length208
author_reputation10,184,429,675,092
root_title"Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,805,413
net_rshares7,876,390,243
author_curate_reward""
vote details (1)
@utopian-io ·
Thank you for your review, @emrebeyler! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-ideba-implementing-syde-an-online-forum-in-flutter-update-3--add-comments-to-a-story-20190410t103421662z-20190412t213548z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-04-12 21:35:51
last_update2019-04-12 21:35:51
depth2
children0
last_payout2019-04-19 21:35:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length62
author_reputation152,955,367,999,756
root_title"Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,984,188
net_rshares0
@steem-plus ·
SteemPlus upvote
Hi, @ideba!

You just got a **0.96%** upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in [here](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
properties (22)
authorsteem-plus
permlinkimplementing-syde-an-online-forum-in-flutter-update-3--add-comments-to-a-story---vote-steemplus
categoryutopian-io
json_metadata{}
created2019-04-07 13:37:24
last_update2019-04-07 13:37:24
depth1
children0
last_payout2019-04-14 13:37:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length432
author_reputation247,952,188,232,400
root_title"Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,636,410
net_rshares0
@steem-ua ·
#### Hi @ideba!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-implementing-syde-an-online-forum-in-flutter-update-3--add-comments-to-a-story-20190410t134644z
categoryutopian-io
json_metadata"{"app": "beem/0.20.19"}"
created2019-04-10 13:46:45
last_update2019-04-10 13:46:45
depth1
children0
last_payout2019-04-17 13:46:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length284
author_reputation23,214,230,978,060
root_title"Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,810,090
net_rshares0
@utopian-io ·
Hey, @ideba!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-implementing-syde-an-online-forum-in-flutter-update-3--add-comments-to-a-story-20190412t014720z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-04-12 01:47:21
last_update2019-04-12 01:47:21
depth1
children0
last_payout2019-04-19 01:47:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length587
author_reputation152,955,367,999,756
root_title"Implementing Syde An online Forum in Flutter (Update 3 : Add Comments to a story)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,919,918
net_rshares0