Skip to content

Commit 5e6e15c

Browse files
committed
🐛 (fix) Null issues
1 parent 308588a commit 5e6e15c

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

lib/state/feedState.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ class FeedState extends AppState {
267267

268268
/// Fetch `Retweet` model from firebase realtime kDatabase.
269269
/// Retweet itself is a type of `Tweet`
270-
Future<FeedModel> fetchTweet(String postID) async {
271-
late FeedModel _tweetDetail;
270+
Future<FeedModel?> fetchTweet(String postID) async {
271+
FeedModel? _tweetDetail;
272272

273273
/// If tweet is availabe in feedlist then no need to fetch it from firebase
274274
if (feedlist!.any((x) => x.key == postID)) {
@@ -284,8 +284,8 @@ class FeedState extends AppState {
284284
if (snapshot.value != null) {
285285
var map = snapshot.value as Map<dynamic, dynamic>;
286286
_tweetDetail = FeedModel.fromJson(map);
287-
_tweetDetail.key = snapshot.key!;
288-
print(_tweetDetail.description);
287+
_tweetDetail!.key = snapshot.key!;
288+
print(_tweetDetail!.description);
289289
}
290290
},
291291
);
@@ -408,7 +408,7 @@ class FeedState extends AppState {
408408
}
409409

410410
/// [update] tweet
411-
updateTweet(FeedModel model) async {
411+
Future<void> updateTweet(FeedModel model) async {
412412
await kDatabase.child('tweet').child(model.key!).set(model.toJson());
413413
}
414414

@@ -454,7 +454,7 @@ class FeedState extends AppState {
454454

455455
/// Add [new comment tweet] to any tweet
456456
/// Comment is a Tweet itself
457-
Future addcommentToPost(FeedModel replyTweet) async {
457+
Future<String?> addcommentToPost(FeedModel replyTweet) async {
458458
try {
459459
isBusy = true;
460460
notifyListeners();
@@ -466,7 +466,8 @@ class FeedState extends AppState {
466466
DatabaseReference ref = kDatabase.child('tweet').push();
467467
await ref.set(json);
468468
tweet.replyTweetKeyList!.add(ref.key);
469-
updateTweet(tweet);
469+
await updateTweet(tweet);
470+
return ref.key;
470471
}
471472
} catch (error) {
472473
cprint(error, errorIn: 'addcommentToPost');

lib/widgets/tweet/widgets/parentTweet.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ParentTweetWidget extends StatelessWidget {
3232
var feedstate = Provider.of<FeedState>(context, listen: false);
3333
return FutureBuilder(
3434
future: feedstate.fetchTweet(childRetwetkey),
35-
builder: (context, AsyncSnapshot<FeedModel> snapshot) {
35+
builder: (context, AsyncSnapshot<FeedModel?> snapshot) {
3636
if (snapshot.hasData) {
3737
return Tweet(
3838
model: snapshot.data!,

lib/widgets/tweet/widgets/retweetWidget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class RetweetWidget extends StatelessWidget {
106106
var feedstate = Provider.of<FeedState>(context, listen: false);
107107
return FutureBuilder(
108108
future: feedstate.fetchTweet(childRetwetkey),
109-
builder: (context, AsyncSnapshot<FeedModel> snapshot) {
109+
builder: (context, AsyncSnapshot<FeedModel?> snapshot) {
110110
if (snapshot.hasData) {
111111
return Container(
112112
margin: EdgeInsets.only(

lib/widgets/tweet/widgets/tweetBottomSheet.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,11 @@ class TweetBottomSheet {
450450

451451
Navigator.pop(context);
452452
var sharedPost = await state.fetchTweet(post.childRetwetkey!);
453-
sharedPost.retweetCount ??= 0;
454-
sharedPost.retweetCount = sharedPost.retweetCount! + 1;
455-
state.updateTweet(sharedPost);
453+
if (sharedPost != null) {
454+
sharedPost.retweetCount ??= 0;
455+
sharedPost.retweetCount = sharedPost.retweetCount! + 1;
456+
state.updateTweet(sharedPost);
457+
}
456458
},
457459
),
458460
_widgetBottomSheetRow(

lib/widgets/tweet/widgets/unavailableTweet.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class UnavailableTweet extends StatelessWidget {
77
const UnavailableTweet({Key? key, required this.snapshot, required this.type})
88
: super(key: key);
99

10-
final AsyncSnapshot<FeedModel> snapshot;
10+
final AsyncSnapshot<FeedModel?> snapshot;
1111
final TweetType type;
1212

1313
@override

0 commit comments

Comments
 (0)