Skip to content

Commit

Permalink
🐛 (fix) home page tweets arn't updating when chamged from detil page.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlphamerc committed Jul 22, 2021
1 parent e138c99 commit d4ec2b4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 21 deletions.
15 changes: 8 additions & 7 deletions lib/state/appState.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import 'package:flutter/material.dart';

class AppState extends ChangeNotifier{

bool _isBusy;
class AppState extends ChangeNotifier {
bool _isBusy = false;
bool get isbusy => _isBusy;
set loading(bool value){
set loading(bool value) {
_isBusy = value;
notifyListeners();
}

int _pageIndex = 0;
int get pageIndex {
return _pageIndex;
}
set setpageIndex(int index){
return _pageIndex;
}

set setpageIndex(int index) {
_pageIndex = index;
notifyListeners();
}
Expand Down
29 changes: 19 additions & 10 deletions lib/state/feedState.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class FeedState extends AppState {
if (_feedQuery == null) {
_feedQuery = kDatabase.child("tweet");
_feedQuery.onChildAdded.listen(_onTweetAdded);
_feedQuery.onValue.listen(_onTweetChanged);
_feedQuery.onChildChanged.listen(_onTweetChanged);
_feedQuery.onChildRemoved.listen(_onTweetRemoved);
}

Expand Down Expand Up @@ -279,24 +279,31 @@ class FeedState extends AppState {
}

/// create [New Tweet]
createTweet(FeedModel model) {
/// returns Tweet key
Future<String> createTweet(FeedModel model) async {
/// Create tweet in [Firebase kDatabase]
isBusy = true;
notifyListeners();
String tweetKey;
try {
kDatabase.child('tweet').push().set(model.toJson());
DatabaseReference dbReference = kDatabase.child('tweet');

await dbReference.push().set(model.toJson());
tweetKey = dbReference.key;
} catch (error) {
cprint(error, errorIn: 'createTweet');
}
isBusy = false;
notifyListeners();
return tweetKey;
}

/// It will create tweet in [Firebase kDatabase] just like other normal tweet.
/// update retweet count for retweet model
createReTweet(FeedModel model) {
Future<String> createReTweet(FeedModel model) async {
String tweetKey;
try {
createTweet(model);
tweetKey = await createTweet(model);
if (_tweetToReplyModel != null) {
if (_tweetToReplyModel.retweetCount == null) {
_tweetToReplyModel.retweetCount = 0;
Expand All @@ -307,6 +314,7 @@ class FeedState extends AppState {
} catch (error) {
cprint(error, errorIn: 'createReTweet');
}
return tweetKey;
}

/// [Delete tweet] in Firebase kDatabase
Expand Down Expand Up @@ -422,18 +430,19 @@ class FeedState extends AppState {

/// Add [new comment tweet] to any tweet
/// Comment is a Tweet itself
addcommentToPost(FeedModel replyTweet) {
Future<String> addcommentToPost(FeedModel replyTweet) async {
try {
isBusy = true;
notifyListeners();
String tweetKey;
if (_tweetToReplyModel != null) {
FeedModel tweet =
_feedlist.firstWhere((x) => x.key == _tweetToReplyModel.key);
var json = replyTweet.toJson();
kDatabase.child('tweet').push().set(json).then((value) {
tweet.replyTweetKeyList.add(_feedlist.last.key);
updateTweet(tweet);
});
DatabaseReference ref = kDatabase.child('tweet').push();
await ref.set(json);
tweet.replyTweetKeyList.add(ref.key);
updateTweet(tweet);
}
} catch (error) {
cprint(error, errorIn: 'addcommentToPost');
Expand Down
2 changes: 2 additions & 0 deletions lib/ui/page/feed/composeTweet/composeTweet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class _ComposeTweetReplyPageState extends State<ComposeTweetPage> {
var authState = Provider.of<AuthState>(context, listen: false);
var myUser = authState.userModel;
var profilePic = myUser.profilePic ?? Constants.dummyProfilePic;

/// User who are creting reply tweet
var commentedUser = UserModel(
displayName: myUser.displayName ?? myUser.email.split('@')[0],
profilePic: profilePic,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/page/notification/notificationPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class NotificationPageBody extends StatelessWidget {
Widget build(BuildContext context) {
var state = Provider.of<NotificationState>(context);
var list = state.notificationList;
if (state?.isbusy ?? true && (list == null || list.isEmpty)) {
if (state.isbusy) {
return SizedBox(
height: 3,
child: LinearProgressIndicator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class _UserCard extends StatelessWidget {
if (bio == "Edit profile to update bio") {
return "No bio available";
} else {
return bio;
return bio.takeOnly(100);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/page/profile/qrCode/scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class _QrCodeState extends State<QrCode> {
@override
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).dividerColor.withOpacity(.6),
color: Theme.of(context).dividerColor.withOpacity(.2),
alignment: Alignment.center,
child: InkWell(
onTap: () {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/theme/extention.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension OnPressed on Widget {
extension StringHelper on String {
String takeOnly(int value) {
if (this != null && length > value) {
return this.substring(0, value) + "...";
return this.substring(0, value) + " ...";
}
return this;
}
Expand Down

0 comments on commit d4ec2b4

Please sign in to comment.