Skip to content

Commit 08912b4

Browse files
committed
reply on comment tweet issue fixed
1 parent c58b6fb commit 08912b4

File tree

5 files changed

+55
-21
lines changed

5 files changed

+55
-21
lines changed

lib/page/feed/feedPostDetail.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class _FeedPostDetailState extends State<FeedPostDetail> {
197197
SliverList(
198198
delegate: SliverChildListDelegate(
199199
[
200-
state.tweetDetailModel.length == 0 ? Container()
200+
state.tweetDetailModel == null || state.tweetDetailModel.length == 0 ? Container()
201201
: _postBody(state.tweetDetailModel?.last),
202202
Container(
203203
height: 6,

lib/page/feed/feedPostreply.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,30 @@ class _FeedPostReplyPageState extends State<FeedPostReplyPage> {
2828
bool isScrollingDown = false;
2929
String postId;
3030
File _image;
31+
FeedModel model;
3132
@override
3233
void initState() {
3334
postId = widget.postId;
35+
var feedState = Provider.of<FeedState>(context,listen: false);
36+
37+
/// if tweet is detail tweet
38+
if(feedState.tweetDetailModel.any((x)=>x.key == postId)){
39+
cprint('Search tweet from tweet detail page stack tweet');
40+
model = feedState.tweetDetailModel.last;
41+
}
42+
/// if tweet is reply tweet
43+
else if(feedState.tweetReplyMap.values.any((x)=> x.any((y)=>y.key == postId))){
44+
cprint('Search tweet from twee detail page roply tweet');
45+
feedState.tweetReplyMap.forEach((key,value){
46+
if(value.any((x)=> x.key == postId)){
47+
model = value.firstWhere((x)=>x.key == postId);
48+
}
49+
});
50+
}
51+
else{
52+
cprint('Search tweet from home page tweet');
53+
model = feedState.feedlist.firstWhere((x)=> x.key == postId);
54+
}
3455
scrollcontroller = ScrollController();
3556
_textEditingController = TextEditingController();
3657
scrollcontroller..addListener(_scrollListener);
@@ -40,6 +61,7 @@ class _FeedPostReplyPageState extends State<FeedPostReplyPage> {
4061
@override
4162
void dispose() {
4263
scrollcontroller.dispose();
64+
_textEditingController.dispose();
4365
super.dispose();
4466
}
4567

@@ -77,10 +99,8 @@ class _FeedPostReplyPageState extends State<FeedPostReplyPage> {
7799
}
78100

79101
Widget _tweerCard() {
80-
var feedState = Provider.of<FeedState>(
81-
context,
82-
);
83-
var model = feedState.tweetDetailModel.last;
102+
103+
84104
return Row(
85105
crossAxisAlignment: CrossAxisAlignment.start,
86106
mainAxisSize: MainAxisSize.min,
@@ -104,7 +124,7 @@ class _FeedPostReplyPageState extends State<FeedPostReplyPage> {
104124
Container(
105125
width: fullWidth(context) - 82,
106126
child: UrlText(
107-
text: model.description,
127+
text: model.description ?? '',
108128
style: TextStyle(color: Colors.black,fontSize: 18 ,
109129
fontWeight: FontWeight.w400),
110130
urlStyle: TextStyle(

lib/page/feed/widgets/tweetIconsRow.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ class _TweetIconsRowState extends State<TweetIconsRow> {
3737
icon:AppIcon.reply,iconColor: widget.iconColor,
3838
size : widget.size ?? 20,
3939
onPressed: (){
40-
if(widget.type == TweetType.Reply){
41-
return;
42-
}
43-
// feedstate.setFeedModel = model;
44-
Navigator.of(context).pushNamed('/FeedPostReplyPage/'+model.key);
40+
Navigator.of(context).pushNamed('/FeedPostReplyPage/'+model.key);
4541
},),
4642
_iconWidget(
4743
text:widget.isTweetDetail ? '' : model.commentCount.toString(),
@@ -59,7 +55,7 @@ class _TweetIconsRowState extends State<TweetIconsRow> {
5955
text:'',
6056
icon:null,
6157
sysIcon:Icons.share,
62-
onPressed: (){share('social.flutter.dev/feed/${model.key}',
58+
onPressed: (){share('${model.description}',
6359
subject:'${model.user.displayName}\'s post');},
6460
iconColor: widget.iconColor,
6561
size : widget.size ?? 20),

lib/state/feedState.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'dart:async';
22
import 'dart:io';
3-
import 'dart:math';
4-
53
import 'package:cloud_firestore/cloud_firestore.dart';
64
import 'package:firebase_database/firebase_database.dart';
75
import 'package:firebase_database/firebase_database.dart' as dabase;
@@ -17,12 +15,10 @@ class FeedState extends AuthState {
1715
bool isBusy = false;
1816
final FirebaseDatabase _database = FirebaseDatabase.instance;
1917
List<FeedModel> _feedlist;
20-
// bool isbbusy = false;
2118
List<FeedModel> _tweetDetailModel;
2219
List<FeedModel> _commentlist;
2320
Map<String, List<FeedModel>> tweetReplyMap = {};
2421
dabase.Query _feedQuery;
25-
dabase.Query _commentQuery;
2622
List<FeedModel> get tweetDetailModel => _tweetDetailModel;
2723
set setFeedModel(FeedModel model) {
2824
if (_tweetDetailModel == null) {
@@ -37,14 +33,24 @@ class FeedState extends AuthState {
3733
notifyListeners();
3834
}
3935
}
40-
36+
/// remove last tweet available from tweet detail page stack
4137
void removeLastTweetDetail(String tweetKey) {
4238
if (_tweetDetailModel != null && _tweetDetailModel.length > 0) {
4339
_tweetDetailModel.removeWhere((x) => x.key == tweetKey);
4440
tweetReplyMap.removeWhere((key, value) => key == tweetKey);
4541
}
4642
}
47-
43+
/// [clear all tweets] if any tweet present in tweet detail page or comment tweet
44+
void clearAllDetailAndReplyTweetStack(){
45+
if(_tweetDetailModel != null){
46+
_tweetDetailModel.clear();
47+
}
48+
if(tweetReplyMap != null){
49+
tweetReplyMap.clear();
50+
}
51+
cprint('Empty tweets from stack');
52+
}
53+
/// contain tweet list for home page
4854
List<FeedModel> get feedlist {
4955
if (_feedlist == null) {
5056
return null;
@@ -65,10 +71,8 @@ class FeedState extends AuthState {
6571
try {
6672
if (_feedQuery == null) {
6773
_feedQuery = _database.reference().child("feed");
68-
_commentQuery = _database.reference().child("comment");
6974
_feedQuery.onChildAdded.listen(_onTweetAdded);
7075
_feedQuery.onChildChanged.listen(_onTweetChanged);
71-
// _commentQuery.onChildAdded.listen(_onCommentChanged);
7276
}
7377

7478
return Future.value(true);

lib/widgets/tweet.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
23
import 'package:flutter_twitter_clone/helper/constant.dart';
34
import 'package:flutter_twitter_clone/helper/enum.dart';
45
import 'package:flutter_twitter_clone/helper/theme.dart';
@@ -53,11 +54,24 @@ class _TweetState extends State<Tweet> {
5354

5455
var feedstate = Provider.of<FeedState>(context,);
5556
return InkWell(
57+
onLongPress: (){
58+
if(widget.type == TweetType.Detail){
59+
var text = ClipboardData(text:_model.description);
60+
Clipboard.setData(text);
61+
Scaffold.of(context)
62+
.showSnackBar(
63+
SnackBar(
64+
backgroundColor: Theme.of(context).disabledColor,
65+
content: Text('Tweet copied',)));
66+
}
67+
},
5668
onTap: (){
5769
if(widget.type == TweetType.Detail){
5870
return;
5971
}
60-
// feedstate.setFeedModel = _model;
72+
if(widget.type == TweetType.Tweet){
73+
feedstate.clearAllDetailAndReplyTweetStack();
74+
}
6175
Navigator.of(context).pushNamed('/FeedPostDetail/'+_model.key);
6276
},
6377
child: Column(

0 commit comments

Comments
 (0)