Skip to content

Commit

Permalink
📈 Make compatible with flutter v3.0.1.
Browse files Browse the repository at this point in the history
⬆️ Upgrade some packages.
✏️ Fix typos.
  • Loading branch information
TheAlphamerc committed Jun 25, 2022
1 parent 775b2ec commit 31093ec
Show file tree
Hide file tree
Showing 51 changed files with 533 additions and 477 deletions.
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cSpell.words": [
"Alives",
"Fwitter",
"parentkey",
"Retwetkey",
"RGBO",
"userlist"
]
}
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 29
compileSdkVersion 32

lintOptions {
disable 'InvalidPackage'
Expand Down
1 change: 0 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Fwitter"
android:icon="@mipmap/ic_launcher"
android:usesCleartextTraffic="true"
Expand Down
37 changes: 21 additions & 16 deletions lib/helper/utility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import '../widgets/newWidget/customLoader.dart';

final kAnalytics = FirebaseAnalytics.instance;
final DatabaseReference kDatabase = FirebaseDatabase.instance.ref();
final kScreenloader = CustomLoader();
final kScreenLoader = CustomLoader();
void cprint(dynamic data,
{String? errorIn, String? event, String label = 'Log'}) {
/// Print logs only in development mode
Expand Down Expand Up @@ -49,7 +49,7 @@ class Utility {
return dat;
}

static String getdob(String? date) {
static String getDob(String? date) {
if (date == null || date.isEmpty) {
return '';
}
Expand Down Expand Up @@ -101,12 +101,12 @@ class Utility {
static String getPollTime(String date) {
int hr, mm;
String msg = 'Poll ended';
var enddate = DateTime.parse(date);
if (DateTime.now().isAfter(enddate)) {
var endDate = DateTime.parse(date);
if (DateTime.now().isAfter(endDate)) {
return msg;
}
msg = 'Poll ended in';
var dur = enddate.difference(DateTime.now());
var dur = endDate.difference(DateTime.now());
hr = dur.inHours - dur.inDays * 24;
mm = dur.inMinutes - (dur.inHours * 60);
if (dur.inDays > 0) {
Expand Down Expand Up @@ -143,8 +143,12 @@ class Utility {
}

static launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
if (url == "") {
return;
}
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchURL(url);
} else {
cprint('Could not launch $url');
}
Expand Down Expand Up @@ -206,7 +210,7 @@ class Utility {
return false;
}

var status = validateEmal(email);
var status = validateEmail(email);
if (!status) {
customSnackBar(_scaffoldKey, 'Please enter valid email id');
return false;
Expand All @@ -232,7 +236,7 @@ class Utility {
_scaffoldKey.currentState!.showSnackBar(snackBar);
}

static bool validateEmal(String email) {
static bool validateEmail(String email) {
String p =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';

Expand All @@ -245,13 +249,14 @@ class Utility {
static Future<Uri> createLinkToShare(BuildContext context, String id,
{required SocialMetaTagParameters socialMetaTagParameters}) async {
final DynamicLinkParameters parameters = DynamicLinkParameters(
uriPrefix: 'https://fwitterdev.page.link',
link: Uri.parse('https://twitter.com/$id'),
androidParameters: AndroidParameters(
packageName: 'com.thealphamerc.fwitter_dev',
minimumVersion: 0,
),
socialMetaTagParameters: socialMetaTagParameters);
uriPrefix: 'https://fwitter.page.link',
link: Uri.parse('https://twitter.com/$id'),
androidParameters: AndroidParameters(
packageName: 'com.thealphamerc.flutter_twitter_clone_dev',
minimumVersion: 0,
),
socialMetaTagParameters: socialMetaTagParameters,
);
Uri url;
final ShortDynamicLink shortLink =
await FirebaseDynamicLinks.instance.buildShortLink(parameters);
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MyApp extends StatelessWidget {
],
child: MaterialApp(
title: 'Fwitter',
theme: AppTheme.apptheme.copyWith(
theme: AppTheme.appTheme.copyWith(
textTheme: GoogleFonts.mulishTextTheme(
Theme.of(context).textTheme,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/state/appState.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppState extends ChangeNotifier {
return _pageIndex;
}

set setpageIndex(int index) {
set setPageIndex(int index) {
_pageIndex = index;
notifyListeners();
}
Expand Down
34 changes: 17 additions & 17 deletions lib/state/base/tweetBaseState.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import 'package:flutter_twitter_clone/state/appState.dart';
class TweetBaseState extends AppState {
/// get [Tweet Detail] from firebase realtime kDatabase
/// If model is null then fetch tweet from firebase
/// [getpostDetailFromDatabase] is used to set prepare Tweetr to display Tweet detail
/// After getting tweet detail fetch tweet coments from firebase
Future<FeedModel?> getpostDetailFromDatabase(String postID) async {
/// [getPostDetailFromDatabase] is used to set prepare Tweet to display Tweet detail
/// After getting tweet detail fetch tweet comments from firebase
Future<FeedModel?> getPostDetailFromDatabase(String postID) async {
try {
late FeedModel tweet;

Expand All @@ -31,13 +31,13 @@ class TweetBaseState extends AppState {
return tweet;
});
} catch (error) {
cprint(error, errorIn: 'getpostDetailFromDatabase');
cprint(error, errorIn: 'getPostDetailFromDatabase');
return null;
}
}

Future<List<FeedModel>?> getTweetsComments(FeedModel post) async {
late List<FeedModel> _commentlist;
late List<FeedModel> _commentList;
// Check if parent tweet has reply tweets or not
if (post.replyTweetKeyList != null && post.replyTweetKeyList!.isNotEmpty) {
// for (String? x in post.replyTweetKeyList!) {
Expand All @@ -46,7 +46,7 @@ class TweetBaseState extends AppState {
// }
// }
//FIXME
_commentlist = [];
_commentList = [];
for (String? replyTweetId in post.replyTweetKeyList!) {
if (replyTweetId != null) {
await kDatabase
Expand All @@ -56,27 +56,27 @@ class TweetBaseState extends AppState {
.then((DatabaseEvent event) {
final snapshot = event.snapshot;
if (snapshot.value != null) {
var commentmodel = FeedModel.fromJson(snapshot.value as Map);
var commentModel = FeedModel.fromJson(snapshot.value as Map);
var key = snapshot.key!;
commentmodel.key = key;
commentModel.key = key;

/// add comment tweet to list if tweet is not present in [comment tweet ]list
/// To reduce duplicacy
if (!_commentlist.any((x) => x.key == key)) {
_commentlist.add(commentmodel);
/// To reduce delicacy
if (!_commentList.any((x) => x.key == key)) {
_commentList.add(commentModel);
}
} else {}
if (replyTweetId == post.replyTweetKeyList!.last) {
/// Sort comment by time
/// It helps to display newest Tweet first.
_commentlist.sort((x, y) => DateTime.parse(y.createdAt)
_commentList.sort((x, y) => DateTime.parse(y.createdAt)
.compareTo(DateTime.parse(x.createdAt)));
}
});
}
}
}
return _commentlist;
return _commentList;
}

/// [Delete tweet] in Firebase kDatabase
Expand Down Expand Up @@ -118,7 +118,7 @@ class TweetBaseState extends AppState {
tweet.likeList!.add(userId);
tweet.likeCount = tweet.likeCount! + 1;
}
// update likelist of a tweet
// update likeList of a tweet
kDatabase
.child('tweet')
.child(tweet.key!)
Expand Down Expand Up @@ -146,9 +146,9 @@ class TweetBaseState extends AppState {
/// Returns new tweet id
String? createPost(FeedModel tweet) {
var json = tweet.toJson();
var refence = kDatabase.child('tweet').push();
refence.set(json);
return refence.key;
var reference = kDatabase.child('tweet').push();
reference.set(json);
return reference.key;
}

/// upload [file] to firebase storage and return its path url
Expand Down
22 changes: 11 additions & 11 deletions lib/state/chats/chatState.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:flutter_twitter_clone/model/user.dart';
import 'package:flutter_twitter_clone/state/appState.dart';

class ChatState extends AppState {
late bool setIsChatScreenOpen; //!obselete
late bool setIsChatScreenOpen; //!obsolete
final FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;

List<ChatMessage>? _messageList;
Expand All @@ -28,7 +28,7 @@ class ChatState extends AppState {
Query? messageQuery;

/// Contains list of chat messages on main chat screen
/// List is sortBy mesage timeStamp
/// List is sortBy message timeStamp
/// Last message will be display on the bottom of screen
List<ChatMessage>? get messageList {
if (_messageList == null) {
Expand Down Expand Up @@ -67,22 +67,22 @@ class ChatState extends AppState {
}
}

/// Fecth FCM server key from firebase Remote config
/// Fetch FCM server key from firebase Remote config
/// FCM server key is stored in firebase remote config
/// you have to add server key in firebase remote config
/// To fetch this key go to project setting in firebase
/// Click on `cloud messaging` tab
/// Copy server key from `Project credentials`
/// Now goto `Remote Congig` section in fireabse
/// Add [FcmServerKey] as paramerter key and below json in Default vslue
/// Now goto `Remote Config` section in Firebase
/// Add [FcmServerKey] as parameter key and below json in Default value
/// ``` json
/// {
/// "key": "FCM server key here"
/// } ```
/// For more detail visit:- https://github.com/TheAlphamerc/flutter_twitter_clone/issues/28#issue-611695533
/// For package detail check:- https://pub.dev/packages/firebase_remote_config#-readme-tab-
void getFCMServerKey() async {
final RemoteConfig remoteConfig = RemoteConfig.instance;
final FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.instance;
await remoteConfig.fetchAndActivate();
// await remoteConfig.
var data = remoteConfig.getString('FcmServerKey');
Expand All @@ -95,7 +95,7 @@ class ChatState extends AppState {
}

/// Fetch users list to who have ever engaged in chat message with logged-in user
void getUserchatList(String userId) {
void getUserChatList(String userId) {
try {
kDatabase
.child('chatUsers')
Expand Down Expand Up @@ -135,10 +135,10 @@ class ChatState extends AppState {
}
}

/// Fetch chat all chat messages
/// Fetch all chat messages
/// `_channelName` is used as primary key for chat message table
/// `_channelName` is created from by combining first 5 letters from user ids of two users
void getchatDetailAsync() async {
void getChatDetailAsync() async {
try {
kDatabase
.child('chats')
Expand Down Expand Up @@ -210,7 +210,7 @@ class ChatState extends AppState {
return _channelName!;
}

/// Method will trigger every time when you send/recieve from/to someone messgae.
/// Method will trigger every time when you send/receive from/to someone message.
void _onMessageAdded(DatabaseEvent event) {
_messageList ??= <ChatMessage>[];
if (event.snapshot.value != null) {
Expand Down Expand Up @@ -271,7 +271,7 @@ class ChatState extends AppState {
notifyListeners();
}

// update last message on chat user list screen when manin chat screen get closed.
// update last message on chat user list screen when main chat screen get closed.
void onChatScreenClosed() {
if (_chatUserList != null &&
_chatUserList!.isNotEmpty &&
Expand Down
Loading

0 comments on commit 31093ec

Please sign in to comment.