Skip to content

Commit

Permalink
🗃 Change remote config
Browse files Browse the repository at this point in the history
🩹 (fix) non critical issues
  • Loading branch information
TheAlphamerc committed Jan 26, 2022
1 parent 5e6e15c commit d78758e
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 82 deletions.
1 change: 0 additions & 1 deletion lib/helper/constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Constants {
static List<String> dummyProfilePicList = [
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ6TaCLCqU4K0ieF27ayjl51NmitWaJAh_X0r1rLX4gMvOe0MDaYw&s',
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTFDjXj1F8Ix-rRFgY_r3GerDoQwfiOMXVt-tZdv_Mcou_yIlUC&s',
'http://www.azembelani.co.za/wp-content/uploads/2016/07/20161014_58006bf6e7079-3.png',
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRzDG366qY7vXN2yng09wb517WTWqp-oua-mMsAoCadtncPybfQ&s',
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTq7BgpG1CwOveQ_gEFgOJASWjgzHAgVfyozkIXk67LzN1jnj9I&s',
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRPxjRIYT8pG0zgzKTilbko-MOv8pSnmO63M9FkOvfHoR9FvInm&s',
Expand Down
11 changes: 7 additions & 4 deletions lib/helper/utility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ class Utility {
}

var dur = DateTime.now().toLocal().difference(dt);
if (dur.inDays > 0) {
if (dur.inDays > 365) {
msg = DateFormat.yMMMd().format(dt);
} else if (dur.inDays > 30) {
msg = DateFormat.yMMMd().format(dt);
} else if (dur.inDays > 0) {
msg = '${dur.inDays} d';
return dur.inDays == 1 ? '1d' : DateFormat("dd MMM").format(dt);
return dur.inDays == 1 ? '1d' : DateFormat.MMMd().format(dt);
} else if (dur.inHours > 0) {
msg = '${dur.inHours} h';
} else if (dur.inMinutes > 0) {
Expand Down Expand Up @@ -146,8 +150,7 @@ class Utility {
}
}

static void logEvent(String event,
{required Map<String, dynamic> parameter}) {
static void logEvent(String event, {Map<String, dynamic>? parameter}) {
kReleaseMode
? kAnalytics.logEvent(name: event, parameters: parameter)
: print("[EVENT]: $event");
Expand Down
8 changes: 2 additions & 6 deletions lib/model/notificationModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class NotificationModel {
String? id;
String? tweetKey;
String? updatedAt;
late String? createdAt;
String? createdAt;
late String type;
late Map<String, dynamic> data;
Map<String, dynamic>? data;

NotificationModel(
{this.id,
Expand All @@ -30,10 +30,6 @@ class NotificationModel {
createdAt = map["createdAt"];
this.data = data;
}

Map<String, dynamic> toJson() => {
"tweetKey": tweetKey,
};
}

extension NotificationModelHelper on NotificationModel {
Expand Down
14 changes: 8 additions & 6 deletions lib/state/authState.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AuthState extends AppState {
notifyListeners();
}

databaseInit() {
void databaseInit() {
try {
if (_profileQuery == null) {
_profileQuery = kDatabase.child("profile").child(user!.uid);
Expand Down Expand Up @@ -135,7 +135,7 @@ class AuthState extends AppState {
}

/// Create user profile from google login
createUserFromGoogleSignIn(User user) {
void createUserFromGoogleSignIn(User user) {
var diff = DateTime.now().difference(user.metadata.creationTime!);
// Check if user is new or old
// If user is new then add new user to firebase realtime kDatabase
Expand Down Expand Up @@ -193,7 +193,7 @@ class AuthState extends AppState {
/// `Create` and `Update` user
/// IF `newUser` is true new user is created
/// Else existing user will update with new values
createUser(UserModel user, {bool newUser = false}) {
void createUser(UserModel user, {bool newUser = false}) {
if (newUser) {
// Create username by the combination of name and id
user.userName =
Expand Down Expand Up @@ -233,7 +233,7 @@ class AuthState extends AppState {
}

/// Reload user to get refresh user data
reloadUser() async {
void reloadUser() async {
await user!.reload();
user = _firebaseAuth.currentUser;
if (user!.emailVerified) {
Expand Down Expand Up @@ -308,13 +308,15 @@ class AuthState extends AppState {
var name = userModel.displayName ?? user!.displayName;
_firebaseAuth.currentUser!.updateDisplayName(name);
_firebaseAuth.currentUser!.updatePhotoURL(userModel.profilePic);
Utility.logEvent('user_profile_image');
}

/// upload banner image if not null
if (bannerImage != null) {
/// get banner storage path from server
userModel!.bannerImage = await _uploadFileToStorage(bannerImage,
'user/profile/${userModel.userName}/${path.basename(bannerImage.path)}');
Utility.logEvent('user_banner_image');
}

if (userModel != null) {
Expand All @@ -324,7 +326,7 @@ class AuthState extends AppState {
}
}

Utility.logEvent('update_user', parameter: {});
Utility.logEvent('update_user');
} catch (error) {
cprint(error, errorIn: 'updateUserProfile');
}
Expand All @@ -333,7 +335,7 @@ class AuthState extends AppState {
Future<String> _uploadFileToStorage(File file, path) async {
var task = _firebaseStorage.ref().child(path);
var status = await task.putFile(file);
print(status.state);
cprint(status.state);

/// get file storage path from server
return await task.getDownloadURL();
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/page/common/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ class _SidebarMenuState extends State<SidebarMenu> {
Navigator.push(
context, ProfilePage.getRoute(profileId: state.userId));
}),
_menuListRowButton('Lists', icon: AppIcon.lists),
_menuListRowButton(
'Bookmark',
icon: AppIcon.bookmark,
Expand All @@ -264,8 +263,8 @@ class _SidebarMenuState extends State<SidebarMenu> {
Navigator.push(context, BookmarkPage.getRoute());
},
),
_menuListRowButton('Lists', icon: AppIcon.lists),
_menuListRowButton('Moments', icon: AppIcon.moments),
_menuListRowButton('Fwitter ads', icon: AppIcon.twitterAds),
const Divider(),
_menuListRowButton('Settings and privacy', isEnable: true,
onPressed: () {
Expand Down
40 changes: 21 additions & 19 deletions lib/ui/page/common/splash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class _SplashPageState extends State<SplashPage> {
cprint("App is updated");
Future.delayed(const Duration(seconds: 1)).then((_) {
var state = Provider.of<AuthState>(context, listen: false);
// state.authStatus = AuthStatus.NOT_DETERMINED;
state.getCurrentUser();
});
}
Expand All @@ -54,25 +53,24 @@ class _SplashPageState extends State<SplashPage> {
Future<bool> _checkAppVersion() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
final currentAppVersion = packageInfo.version;
final appVersion = await _getAppVersionFromFirebaseConfig();
if (appVersion != currentAppVersion) {
final buildNo = packageInfo.buildNumber;
final config = await _getAppVersionFromFirebaseConfig();

if (config != null &&
config['name'] == currentAppVersion &&
config['versions'].contains(int.tryParse(buildNo))) {
return true;
} else {
if (kDebugMode) {
cprint("Latest version of app is not installed on your system");
cprint(
"In debug mode we are not restrict devlopers to redirect to update screen");
"This is for testing purpose only. In debug mode update screen will not be open up");
cprint(
"Redirect devs to update screen can put other devs in confusion");
"If you are planning to publish app on store then please update app version in firebase config");
return true;
}
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const UpdateApp(),
),
);
Navigator.pushReplacement(context, UpdateApp.getRoute());
return false;
} else {
return true;
}
}

Expand All @@ -82,20 +80,24 @@ class _SplashPageState extends State<SplashPage> {
/// you have to add latest app version in firebase remote config
/// To fetch this key go to project setting in firebase
/// Open `Remote Config` section in fireabse
/// Add [appVersion] as paramerter key and below json in Default value
/// ``` json
/// Add [supportedBuild] as paramerter key and below json in Default value
/// ```
/// {
/// "key": "1.0.0"
/// "supportedBuild":
/// {
/// "name": "<Current Build Version>","
/// "versions": [ <Current Build Version> ]
/// }
/// } ```
/// After adding app version key click on Publish Change button
/// For package detail check:- https://pub.dev/packages/firebase_remote_config#-readme-tab-
Future<String?> _getAppVersionFromFirebaseConfig() async {
Future<Map?> _getAppVersionFromFirebaseConfig() async {
final RemoteConfig remoteConfig = RemoteConfig.instance;
await remoteConfig.fetchAndActivate();
// await remoteConfig.activateFetched();
var data = remoteConfig.getString('appVersion');
var data = remoteConfig.getString('supportedBuild');
if (data.isNotEmpty) {
return jsonDecode(data)["key"];
return jsonDecode(data) as Map;
} else {
cprint(
"Please add your app's current version into Remote config in firebase",
Expand Down
6 changes: 6 additions & 0 deletions lib/ui/page/common/updateApp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import 'package:flutter_twitter_clone/widgets/newWidget/title_text.dart';
class UpdateApp extends StatefulWidget {
const UpdateApp({Key? key}) : super(key: key);

static Route<T> getRoute<T>() {
return MaterialPageRoute(
builder: (_) => UpdateApp(),
);
}

@override
_UpdateAppState createState() => _UpdateAppState();
}
Expand Down
5 changes: 2 additions & 3 deletions lib/ui/page/feed/composeTweet/composeTweet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ class _ComposeTweetReplyPageState extends State<ComposeTweetPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: CustomAppBar(
title: customTitleText(
'',
),
title: customTitleText(''),
onActionPressed: _submitButton,
isCrossButton: true,
submitButtonText: widget.isTweet
Expand Down Expand Up @@ -589,6 +587,7 @@ class _UserList extends StatelessWidget {
const BoxConstraints(minHeight: 30, maxHeight: double.infinity),
child: ListView.builder(
itemCount: list!.length,
physics: ClampingScrollPhysics(),
itemBuilder: (context, index) {
return _UserTile(
user: list![index],
Expand Down
17 changes: 12 additions & 5 deletions lib/ui/page/message/chatListPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ class _ChatListPageState extends State<ChatListPage> {
physics: const BouncingScrollPhysics(),
itemCount: state.chatUserList!.length,
itemBuilder: (context, index) => _userCard(
searchState.userlist!.firstWhere(
(x) => x.userId == state.chatUserList![index].key,
orElse: () => UserModel(userName: "Unknown"),
),
state.chatUserList![index]),
searchState.userlist!.firstWhere(
(x) => x.userId == state.chatUserList![index].key,
orElse: () => UserModel(userName: "Unknown"),
),
state.chatUserList![index],
),
separatorBuilder: (context, index) {
return const Divider(
height: 0,
Expand Down Expand Up @@ -120,11 +121,17 @@ class _ChatListPageState extends State<ChatListPage> {
getLastMessage(lastMessage?.message) ?? '@${model.displayName}',
style:
TextStyles.onPrimarySubTitleText.copyWith(color: Colors.black54),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
trailing: lastMessage == null
? const SizedBox.shrink()
: Text(
Utility.getChatTime(lastMessage.createdAt).toString(),
style: TextStyles.onPrimarySubTitleText.copyWith(
color: Colors.black54,
fontSize: 12,
),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/page/profile/profilePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ class _ProfilePageState extends State<ProfilePage>
late TabController _tabController;

void shareProfile(BuildContext context) async {
var authstate = context.read<AuthState>();
var authstate = context.read<ProfileState>();
var user = authstate.profileUserModel;
Utility.createLinkAndShare(
context,
"profilePage/${widget.profileId}/",
socialMetaTagParameters: SocialMetaTagParameters(
description: !user!.bio!.contains("Edit profile")
description: !user.bio!.contains("Edit profile")
? user.bio
: "Checkout ${user.displayName}'s profile on Fwitter app",
title: "${user.displayName} is on Fwitter app",
Expand Down
8 changes: 7 additions & 1 deletion lib/ui/page/profile/widgets/circular_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ class CircularImage extends StatelessWidget {
}

CachedNetworkImageProvider customAdvanceNetworkImage(String? path) {
path ??= Constants.dummyProfilePic;
if (path ==
'http://www.azembelani.co.za/wp-content/uploads/2016/07/20161014_58006bf6e7079-3.png') {
path = Constants.dummyProfilePic;
} else {
path ??= Constants.dummyProfilePic;
}
return CachedNetworkImageProvider(
path,
cacheKey: path,
);
}
20 changes: 17 additions & 3 deletions lib/widgets/cache_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import 'package:flutter/material.dart';
import 'package:flutter_twitter_clone/helper/constant.dart';

class CacheImage extends StatelessWidget {
const CacheImage({Key? key, this.path, this.fit = BoxFit.contain})
: super(key: key);
const CacheImage({
Key? key,
this.path,
this.fit = BoxFit.contain,
this.errorWidget,
}) : super(key: key);
final String? path;
final BoxFit fit;
final Widget? errorWidget;

Widget customNetworkImage(String? path, {BoxFit fit = BoxFit.contain}) {
return CachedNetworkImage(
Expand All @@ -24,7 +29,16 @@ class CacheImage extends StatelessWidget {
placeholder: (context, url) => Container(
color: const Color(0xffeeeeee),
),
errorWidget: (context, url, error) => const Icon(Icons.error),
cacheKey: path,
errorWidget: (context, url, error) =>
errorWidget ??
Container(
color: const Color(0xffeeeeee),
child: Icon(
Icons.error,
color: Colors.grey[700],
),
),
);
}

Expand Down
18 changes: 11 additions & 7 deletions lib/widgets/customWidgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ Widget customIcon(
);
}

Widget customText(String? msg,
{Key? key,
TextStyle? style,
TextAlign textAlign = TextAlign.justify,
TextOverflow overflow = TextOverflow.visible,
BuildContext? context,
bool softwrap = true}) {
Widget customText(
String? msg, {
Key? key,
TextStyle? style,
TextAlign textAlign = TextAlign.justify,
TextOverflow overflow = TextOverflow.visible,
BuildContext? context,
bool softwrap = true,
int? maxLines,
}) {
if (msg == null) {
return const SizedBox(
height: 0,
Expand All @@ -64,6 +67,7 @@ Widget customText(String? msg,
overflow: overflow,
softWrap: softwrap,
key: key,
maxLines: maxLines,
);
}
}
Expand Down
Loading

0 comments on commit d78758e

Please sign in to comment.