@@ -24,6 +24,9 @@ class ComposeTweetState extends ChangeNotifier {
24
24
}
25
25
26
26
/// Display/Hide userlist on the basis of username availability in description
27
+ /// To display userlist in compose screen two condion is required
28
+ /// First is value of `status` should be true
29
+ /// Second value of `hideUserList` should be false
27
30
bool get displayUserList {
28
31
RegExp regExp = new RegExp (usernameRegex);
29
32
var status = regExp.hasMatch (description);
@@ -34,12 +37,18 @@ class ComposeTweetState extends ChangeNotifier {
34
37
}
35
38
}
36
39
37
- /// Hide userlist when a username is selected from userlist
40
+ /// Hide userlist when a user select a username from userlist
38
41
void onUserSelected () {
39
42
hideUserList = true ;
40
43
notifyListeners ();
41
44
}
42
45
46
+ /// This method will trigger every time when user writes tweet description.
47
+ /// `hideUserList` is set to false to reset user list show flag.
48
+ /// If description is not empty and its lenth is lesser then 280 characters
49
+ /// then value of `enableSubmitButton` is set to true.
50
+ ///
51
+ /// `enableSubmitButton` is responsible to enable/disable tweet submit button
43
52
void onDescriptionChanged (String text, SearchState searchState) {
44
53
description = text;
45
54
hideUserList = false ;
@@ -54,7 +63,7 @@ class ComposeTweetState extends ChangeNotifier {
54
63
enableSubmitButton = true ;
55
64
var last = text.substring (text.length - 1 , text.length);
56
65
57
- /// Regex to search last username from description
66
+ /// Regex to search last username available from description
58
67
/// Ex. `Hello @john do you know @ricky`
59
68
/// In above description reegex is serch for last username ie. `@ricky` .
60
69
@@ -88,8 +97,25 @@ class ComposeTweetState extends ChangeNotifier {
88
97
return description;
89
98
}
90
99
91
- /// Fecth FCM server key from firebase Remote config
100
+ /// Fetch FCM server key from firebase Remote config
101
+ /// FCM server key is stored in firebase remote config
102
+ /// you have to add server key in firebase remote config
103
+ /// To fetch this key go to project setting in firebase
104
+ /// Click on `cloud messaging` tab
105
+ /// Copy server key from `Project credentials`
106
+ /// Now goto `Remote Congig` section in fireabse
107
+ /// Add [FcmServerKey] as paramerter key and below json in Default vslue
108
+ /// ``` json
109
+ /// {
110
+ /// "key": "FCM server key here"
111
+ /// } ```
112
+ /// For more detail visit:- https://github.com/TheAlphamerc/flutter_twitter_clone/issues/28#issue-611695533
113
+ /// For package detail check:- https://pub.dev/packages/firebase_remote_config#-readme-tab-
92
114
Future <Null > getFCMServerKey () async {
115
+ /// If FCM server key is already fetched then no need to fetch it again.
116
+ if (serverToken != null && serverToken.isNotEmpty){
117
+ return Future .value (null );
118
+ }
93
119
final RemoteConfig remoteConfig = await RemoteConfig .instance;
94
120
await remoteConfig.fetch (expiration: const Duration (hours: 5 ));
95
121
await remoteConfig.activateFetched ();
@@ -98,16 +124,17 @@ class ComposeTweetState extends ChangeNotifier {
98
124
serverToken = jsonDecode (data)["key" ];
99
125
}
100
126
}
101
-
127
+ /// Fecth FCM server key from firebase Remote config
128
+ /// send notification to user once fcmToken is retrieved from firebase
102
129
Future <void > sendNotification (FeedModel model, SearchState state) async {
103
130
final usernameRegex = r"(@\w*[a-zA-Z1-9])" ;
104
131
RegExp regExp = new RegExp (usernameRegex);
105
132
var status = regExp.hasMatch (description);
133
+ /// Check if username is availeble in description or not
106
134
if (status) {
107
- /// Fecth FCM server key from firebase Remote config
108
- /// send notification to user once fcmToken is retrieved from firebase
135
+ /// Get FCM server key from firebase remote config
109
136
getFCMServerKey ().then ((val) async {
110
- /// Reset userlist
137
+ /// Reset userlist
111
138
state.filterByUsername ("" );
112
139
113
140
/// Search all username from description
0 commit comments