Skip to content

Commit b89d560

Browse files
committed
⬆️ Upgrade packages.
🐛 (fix) serialisation issues
1 parent a24b34c commit b89d560

26 files changed

+280
-220
lines changed

lib/helper/utility.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import 'package:url_launcher/url_launcher.dart';
1515

1616
import '../widgets/newWidget/customLoader.dart';
1717

18-
final kAnalytics = FirebaseAnalytics();
19-
final DatabaseReference kDatabase = FirebaseDatabase.instance.reference();
18+
final kAnalytics = FirebaseAnalytics.instance;
19+
final DatabaseReference kDatabase = FirebaseDatabase.instance.ref();
2020
final kScreenloader = CustomLoader();
2121
void cprint(dynamic data,
2222
{String? errorIn, String? event, String label = 'Log'}) {
@@ -248,12 +248,10 @@ class Utility {
248248
packageName: 'com.thealphamerc.fwitter_dev',
249249
minimumVersion: 0,
250250
),
251-
dynamicLinkParametersOptions: DynamicLinkParametersOptions(
252-
shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
253-
),
254251
socialMetaTagParameters: socialMetaTagParameters);
255252
Uri url;
256-
final ShortDynamicLink shortLink = await parameters.buildShortLink();
253+
final ShortDynamicLink shortLink =
254+
await FirebaseDynamicLinks.instance.buildShortLink(parameters);
257255
url = shortLink.shortUrl;
258256
return url;
259257
}

lib/model/notificationModel.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class NotificationModel {
66
String? id;
77
String? tweetKey;
88
String? updatedAt;
9-
late String createdAt;
9+
late String? createdAt;
1010
late String type;
1111
late Map<String, dynamic> data;
1212

@@ -20,7 +20,10 @@ class NotificationModel {
2020

2121
NotificationModel.fromJson(String tweetId, Map<dynamic, dynamic> map) {
2222
id = tweetId;
23-
final data = json.decode(json.encode(map["data"])) as Map<String, dynamic>;
23+
Map<String, dynamic> data = {};
24+
if (map.containsKey('data')) {
25+
data = json.decode(json.encode(map["data"])) as Map<String, dynamic>;
26+
}
2427
tweetKey = tweetId;
2528
updatedAt = map["updatedAt"];
2629
type = map["type"];
@@ -36,5 +39,5 @@ class NotificationModel {
3639
extension NotificationModelHelper on NotificationModel {
3740
UserModel get user => UserModel.fromJson(data);
3841

39-
DateTime? get timeStamp => DateTime.tryParse(updatedAt ?? createdAt);
42+
DateTime? get timeStamp => DateTime.tryParse(updatedAt ?? createdAt!);
4043
}

lib/resource/push_notification_service.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class PushNotificationService {
2323
Stream<PushNotificationModel> get pushNotificationResponseStream =>
2424
_pushNotificationSubject.stream;
2525

26+
// ignore: unused_field, cancel_subscriptions
2627
late StreamSubscription<RemoteMessage> _backgroundMessageSubscription;
2728

2829
void initializeMessages() {

lib/state/authState.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:io';
23

34
import 'package:firebase_auth/firebase_auth.dart';
@@ -341,11 +342,12 @@ class AuthState extends AppState {
341342
/// `Fetch` user `detail` whoose userId is passed
342343
Future<UserModel?> getuserDetail(String userId) async {
343344
UserModel user;
344-
var snapshot = await kDatabase.child('profile').child(userId).once();
345-
if (snapshot.value != null) {
346-
var map = snapshot.value;
345+
var event = await kDatabase.child('profile').child(userId).once();
346+
347+
final map = event.snapshot.value as Map?;
348+
if (map != null) {
347349
user = UserModel.fromJson(map);
348-
user.key = snapshot.key!;
350+
user.key = event.snapshot.key!;
349351
return user;
350352
} else {
351353
return null;
@@ -354,7 +356,7 @@ class AuthState extends AppState {
354356

355357
/// Fetch user profile
356358
/// If `userProfileId` is null then logged in user's profile will fetched
357-
getProfileUser({String? userProfileId}) {
359+
FutureOr<void> getProfileUser({String? userProfileId}) {
358360
try {
359361
loading = true;
360362

@@ -363,9 +365,10 @@ class AuthState extends AppState {
363365
.child("profile")
364366
.child(userProfileId)
365367
.once()
366-
.then((DataSnapshot snapshot) {
368+
.then((DatabaseEvent event) async {
369+
final snapshot = event.snapshot;
367370
if (snapshot.value != null) {
368-
var map = snapshot.value;
371+
var map = snapshot.value as Map<dynamic, dynamic>?;
369372
if (map != null) {
370373
if (userProfileId == user!.uid) {
371374
_userModel = UserModel.fromJson(map);
@@ -409,9 +412,10 @@ class AuthState extends AppState {
409412

410413
/// Trigger when logged-in user's profile change or updated
411414
/// Firebase event callback for profile update
412-
void _onProfileChanged(Event event) {
415+
void _onProfileChanged(DatabaseEvent event) {
413416
// if (event.snapshot != null) {
414-
final updatedUser = UserModel.fromJson(event.snapshot.value);
417+
final val = event.snapshot.value;
418+
final updatedUser = UserModel.fromJson(val as Map);
415419
_userModel = updatedUser;
416420
cprint('UserModel Updated');
417421
notifyListeners();

lib/state/base/tweetBaseState.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class TweetBaseState extends AppState {
2121
.child('tweet')
2222
.child(postID)
2323
.once()
24-
.then((DataSnapshot snapshot) {
24+
.then((DatabaseEvent event) {
25+
final snapshot = event.snapshot;
2526
if (snapshot.value != null) {
26-
var map = snapshot.value;
27+
var map = snapshot.value as Map;
2728
tweet = FeedModel.fromJson(map);
2829
tweet.key = snapshot.key!;
2930
}
@@ -52,9 +53,10 @@ class TweetBaseState extends AppState {
5253
.child('tweet')
5354
.child(replyTweetId)
5455
.once()
55-
.then((DataSnapshot snapshot) {
56+
.then((DatabaseEvent event) {
57+
final snapshot = event.snapshot;
5658
if (snapshot.value != null) {
57-
var commentmodel = FeedModel.fromJson(snapshot.value);
59+
var commentmodel = FeedModel.fromJson(snapshot.value as Map);
5860
var key = snapshot.key!;
5961
commentmodel.key = key;
6062

@@ -142,7 +144,7 @@ class TweetBaseState extends AppState {
142144

143145
/// Add new [tweet]
144146
/// Returns new tweet id
145-
String createPost(FeedModel tweet) {
147+
String? createPost(FeedModel tweet) {
146148
var json = tweet.toJson();
147149
var refence = kDatabase.child('tweet').push();
148150
refence.set(json);

lib/state/bookmarkState.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class BookmarkState extends AppState {
3939
.child('bookmark')
4040
.child(userId)
4141
.once()
42-
.then((DataSnapshot snapshot) async {
42+
.then((DatabaseEvent event) async {
43+
final snapshot = event.snapshot;
4344
if (snapshot.value != null) {
4445
var map = snapshot.value as Map<dynamic, dynamic>?;
4546
if (map != null) {
@@ -72,7 +73,9 @@ class BookmarkState extends AppState {
7273
/// get `Tweet` present in notification
7374
Future<FeedModel?> getTweetDetail(String tweetId) async {
7475
FeedModel _tweetDetail;
75-
var snapshot = await kDatabase.child('tweet').child(tweetId).once();
76+
final event = await kDatabase.child('tweet').child(tweetId).once();
77+
78+
final snapshot = event.snapshot;
7679
if (snapshot.value != null) {
7780
var map = snapshot.value as Map<dynamic, dynamic>;
7881
_tweetDetail = FeedModel.fromJson(map);

lib/state/chats/chatState.dart

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ class ChatState extends AppState {
101101
.child('chatUsers')
102102
.child(userId)
103103
.once()
104-
.then((DataSnapshot snapshot) {
104+
.then((DatabaseEvent event) {
105+
final snapshot = event.snapshot;
105106
_chatUserList = <ChatMessage>[];
106107
if (snapshot.value != null) {
107-
var map = snapshot.value;
108+
var map = snapshot.value as Map?;
108109
if (map != null) {
109110
map.forEach((key, value) {
110111
var model = ChatMessage.fromJson(value);
@@ -143,10 +144,11 @@ class ChatState extends AppState {
143144
.child('chats')
144145
.child(_channelName!)
145146
.once()
146-
.then((DataSnapshot snapshot) {
147+
.then((DatabaseEvent event) {
148+
final snapshot = event.snapshot;
147149
_messageList = <ChatMessage>[];
148150
if (snapshot.value != null) {
149-
var map = snapshot.value;
151+
var map = snapshot.value as Map<dynamic, dynamic>?;
150152
if (map != null) {
151153
map.forEach((key, value) {
152154
var model = ChatMessage.fromJson(value);
@@ -209,10 +211,11 @@ class ChatState extends AppState {
209211
}
210212

211213
/// Method will trigger every time when you send/recieve from/to someone messgae.
212-
void _onMessageAdded(Event event) {
214+
void _onMessageAdded(DatabaseEvent event) {
213215
_messageList ??= <ChatMessage>[];
214216
if (event.snapshot.value != null) {
215-
var map = event.snapshot.value;
217+
var map = event.snapshot.value as Map;
218+
// ignore: unnecessary_null_comparison
216219
if (map != null) {
217220
var model = ChatMessage.fromJson(map);
218221
model.key = event.snapshot.key!;
@@ -228,10 +231,11 @@ class ChatState extends AppState {
228231
notifyListeners();
229232
}
230233

231-
void _onMessageChanged(Event event) {
234+
void _onMessageChanged(DatabaseEvent event) {
232235
_messageList ??= <ChatMessage>[];
233236
if (event.snapshot.value != null) {
234-
var map = event.snapshot.value;
237+
var map = event.snapshot.value as Map<dynamic, dynamic>;
238+
// ignore: unnecessary_null_comparison
235239
if (map != null) {
236240
var model = ChatMessage.fromJson(map);
237241
model.key = event.snapshot.key!;
@@ -247,10 +251,11 @@ class ChatState extends AppState {
247251
notifyListeners();
248252
}
249253

250-
void _onChatUserAdded(Event event) {
254+
void _onChatUserAdded(DatabaseEvent event) {
251255
_chatUserList ??= <ChatMessage>[];
252256
if (event.snapshot.value != null) {
253-
var map = event.snapshot.value;
257+
var map = event.snapshot.value as Map;
258+
// ignore: unnecessary_null_comparison
254259
if (map != null) {
255260
var model = ChatMessage.fromJson(map);
256261
model.key = event.snapshot.key!;

lib/state/feedState.dart

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ class FeedState extends AppState {
156156
isBusy = true;
157157
_feedlist = null;
158158
notifyListeners();
159-
kDatabase.child('tweet').once().then((DataSnapshot snapshot) {
159+
kDatabase.child('tweet').once().then((DatabaseEvent event) {
160+
final snapshot = event.snapshot;
160161
_feedlist = <FeedModel>[];
161162
if (snapshot.value != null) {
162-
var map = snapshot.value;
163+
var map = snapshot.value as Map<dynamic, dynamic>?;
163164
if (map != null) {
164165
map.forEach((key, value) {
165166
var model = FeedModel.fromJson(value);
@@ -206,9 +207,10 @@ class FeedState extends AppState {
206207
.child('tweet')
207208
.child(postID!)
208209
.once()
209-
.then((DataSnapshot snapshot) {
210+
.then((DatabaseEvent event) {
211+
final snapshot = event.snapshot;
210212
if (snapshot.value != null) {
211-
var map = snapshot.value;
213+
var map = snapshot.value as Map<dynamic, dynamic>;
212214
_tweetDetail = FeedModel.fromJson(map);
213215
_tweetDetail!.key = snapshot.key!;
214216
setFeedModel = _tweetDetail!;
@@ -230,9 +232,10 @@ class FeedState extends AppState {
230232
.child('tweet')
231233
.child(x)
232234
.once()
233-
.then((DataSnapshot snapshot) {
235+
.then((DatabaseEvent event) {
236+
final snapshot = event.snapshot;
234237
if (snapshot.value != null) {
235-
var commentmodel = FeedModel.fromJson(snapshot.value);
238+
var commentmodel = FeedModel.fromJson(snapshot.value as Map);
236239
String key = snapshot.key!;
237240
commentmodel.key = key;
238241

@@ -276,9 +279,10 @@ class FeedState extends AppState {
276279
else {
277280
cprint("Fetched from DB: " + postID);
278281
var model = await kDatabase.child('tweet').child(postID).once().then(
279-
(DataSnapshot snapshot) {
282+
(DatabaseEvent event) {
283+
final snapshot = event.snapshot;
280284
if (snapshot.value != null) {
281-
var map = snapshot.value;
285+
var map = snapshot.value as Map<dynamic, dynamic>;
282286
_tweetDetail = FeedModel.fromJson(map);
283287
_tweetDetail.key = snapshot.key!;
284288
print(_tweetDetail.description);
@@ -296,11 +300,11 @@ class FeedState extends AppState {
296300

297301
/// create [New Tweet]
298302
/// returns Tweet key
299-
Future<String> createTweet(FeedModel model) async {
303+
Future<String?> createTweet(FeedModel model) async {
300304
/// Create tweet in [Firebase kDatabase]
301305
isBusy = true;
302306
notifyListeners();
303-
late String tweetKey;
307+
String? tweetKey;
304308
try {
305309
DatabaseReference dbReference = kDatabase.child('tweet').push();
306310

@@ -317,8 +321,8 @@ class FeedState extends AppState {
317321

318322
/// It will create tweet in [Firebase kDatabase] just like other normal tweet.
319323
/// update retweet count for retweet model
320-
Future<String> createReTweet(FeedModel model) async {
321-
late String tweetKey;
324+
Future<String?> createReTweet(FeedModel model) async {
325+
String? tweetKey;
322326
try {
323327
tweetKey = await createTweet(model);
324328
if (_tweetToReplyModel != null) {
@@ -477,14 +481,16 @@ class FeedState extends AppState {
477481
var userId = await pref.getUserProfile().then((value) => value!.userId);
478482
DatabaseReference dbReference =
479483
kDatabase.child('bookmark').child(userId!).child(tweetId);
480-
await dbReference.set({"tweetId": tweetId});
484+
await dbReference.set(
485+
{"tweetId": tweetId, "created_at": DateTime.now().toUtc().toString()});
481486
}
482487

483488
/// Trigger when any tweet changes or update
484489
/// When any tweet changes it update it in UI
485490
/// No matter if Tweet is in home page or in detail page or in comment section.
486-
_onTweetChanged(Event event) {
487-
var model = FeedModel.fromJson(event.snapshot.value);
491+
_onTweetChanged(DatabaseEvent event) {
492+
var model =
493+
FeedModel.fromJson(event.snapshot.value as Map<dynamic, dynamic>);
488494
model.key = event.snapshot.key!;
489495
if (_feedlist!.any((x) => x.key == model.key)) {
490496
var oldEntry = _feedlist!.lastWhere((entry) {
@@ -526,8 +532,8 @@ class FeedState extends AppState {
526532
/// Trigger when new tweet added
527533
/// It will add new Tweet in home page list.
528534
/// IF Tweet is comment it will be added in comment section too.
529-
_onTweetAdded(Event event) {
530-
FeedModel tweet = FeedModel.fromJson(event.snapshot.value);
535+
_onTweetAdded(DatabaseEvent event) {
536+
FeedModel tweet = FeedModel.fromJson(event.snapshot.value as Map);
531537
tweet.key = event.snapshot.key!;
532538

533539
/// Check if Tweet is a comment
@@ -567,8 +573,8 @@ class FeedState extends AppState {
567573

568574
/// Trigger when Tweet `Deleted`
569575
/// It removed Tweet from home page list, Tweet detail page list and from comment section if present
570-
_onTweetRemoved(Event event) async {
571-
FeedModel tweet = FeedModel.fromJson(event.snapshot.value);
576+
_onTweetRemoved(DatabaseEvent event) async {
577+
FeedModel tweet = FeedModel.fromJson(event.snapshot.value as Map);
572578
tweet.key = event.snapshot.key!;
573579
var tweetId = tweet.key;
574580
var parentkey = tweet.parentkey;

0 commit comments

Comments
 (0)