Chat Fixes

merge-requests/72/head
Aamir Muhammad 3 years ago
parent 4d14184f34
commit 967257ec2e

@ -18,8 +18,7 @@ class APIError {
APIError(this.errorCode, this.errorMessage); APIError(this.errorCode, this.errorMessage);
Map<String, dynamic> toJson() => Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage};
{'errorCode': errorCode, 'errorMessage': errorMessage};
@override @override
String toString() { String toString() {
@ -54,8 +53,7 @@ APIException _throwAPIException(Response response) {
return APIException(APIException.INTERNAL_SERVER_ERROR); return APIException(APIException.INTERNAL_SERVER_ERROR);
case 444: case 444:
var downloadUrl = response.headers["location"]; var downloadUrl = response.headers["location"];
return APIException(APIException.UPGRADE_REQUIRED, return APIException(APIException.UPGRADE_REQUIRED, arguments: downloadUrl);
arguments: downloadUrl);
default: default:
return APIException(APIException.OTHER); return APIException(APIException.OTHER);
} }
@ -68,13 +66,8 @@ class ApiClient {
factory ApiClient() => _instance; factory ApiClient() => _instance;
Future<U> postJsonForObject<T, U>( Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
FactoryConstructor<U> factoryConstructor, String url, T jsonObject, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
{String? token,
Map<String, dynamic>? queryParameters,
Map<String, String>? headers,
int retryTimes = 0,
bool isFormData = false}) async {
var _headers = {'Accept': 'application/json'}; var _headers = {'Accept': 'application/json'};
if (headers != null && headers.isNotEmpty) { if (headers != null && headers.isNotEmpty) {
_headers.addAll(headers); _headers.addAll(headers);
@ -84,12 +77,7 @@ class ApiClient {
var bodyJson = json.encode(jsonObject); var bodyJson = json.encode(jsonObject);
print("body:$bodyJson"); print("body:$bodyJson");
} }
var response = await postJsonForResponse(url, jsonObject, var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes, isFormData: isFormData);
token: token,
queryParameters: queryParameters,
headers: _headers,
retryTimes: retryTimes,
isFormData: isFormData);
// try { // try {
if (!kReleaseMode) { if (!kReleaseMode) {
logger.i("res: " + response.body); logger.i("res: " + response.body);
@ -102,8 +90,7 @@ class ApiClient {
return factoryConstructor(jsonData); return factoryConstructor(jsonData);
} else { } else {
APIError? apiError; APIError? apiError;
apiError = apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage']);
APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage']);
throw APIException(APIException.BAD_REQUEST, error: apiError); throw APIException(APIException.BAD_REQUEST, error: apiError);
} }
// } catch (ex) { // } catch (ex) {
@ -116,11 +103,7 @@ class ApiClient {
} }
Future<Response> postJsonForResponse<T>(String url, T jsonObject, Future<Response> postJsonForResponse<T>(String url, T jsonObject,
{String? token, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
Map<String, dynamic>? queryParameters,
Map<String, String>? headers,
int retryTimes = 0,
bool isFormData = false}) async {
String? requestBody; String? requestBody;
late Map<String, String> stringObj; late Map<String, String> stringObj;
if (jsonObject != null) { if (jsonObject != null) {
@ -134,22 +117,13 @@ class ApiClient {
if (isFormData) { if (isFormData) {
headers = {'Content-Type': 'application/x-www-form-urlencoded'}; headers = {'Content-Type': 'application/x-www-form-urlencoded'};
stringObj = ((jsonObject ?? {}) as Map<String, dynamic>) stringObj = ((jsonObject ?? {}) as Map<String, dynamic>).map((key, value) => MapEntry(key, value?.toString() ?? ""));
.map((key, value) => MapEntry(key, value?.toString() ?? ""));
} }
return await _postForResponse(url, isFormData ? stringObj : requestBody, return await _postForResponse(url, isFormData ? stringObj : requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes);
} }
Future<Response> _postForResponse(String url, requestBody, Future<Response> _postForResponse(String url, requestBody, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
{String? token,
Map<String, dynamic>? queryParameters,
Map<String, String>? headers,
int retryTimes = 0}) async {
try { try {
var _headers = <String, String>{}; var _headers = <String, String>{};
if (token != null) { if (token != null) {
@ -164,9 +138,7 @@ class ApiClient {
var queryString = new Uri(queryParameters: queryParameters).query; var queryString = new Uri(queryParameters: queryParameters).query;
url = url + '?' + queryString; url = url + '?' + queryString;
} }
var response = var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 120));
await _post(Uri.parse(url), body: requestBody, headers: _headers)
.timeout(Duration(seconds: 120));
if (response.statusCode >= 200 && response.statusCode < 300) { if (response.statusCode >= 200 && response.statusCode < 300) {
return response; return response;
@ -177,11 +149,7 @@ class ApiClient {
if (retryTimes > 0) { if (retryTimes > 0) {
print('will retry after 3 seconds...'); print('will retry after 3 seconds...');
await Future.delayed(Duration(seconds: 3)); await Future.delayed(Duration(seconds: 3));
return await _postForResponse(url, requestBody, return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes - 1);
} else { } else {
throw APIException(APIException.OTHER, arguments: e); throw APIException(APIException.OTHER, arguments: e);
} }
@ -189,11 +157,7 @@ class ApiClient {
if (retryTimes > 0) { if (retryTimes > 0) {
print('will retry after 3 seconds...'); print('will retry after 3 seconds...');
await Future.delayed(Duration(seconds: 3)); await Future.delayed(Duration(seconds: 3));
return await _postForResponse(url, requestBody, return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes - 1);
} else { } else {
throw APIException(APIException.OTHER, arguments: e); throw APIException(APIException.OTHER, arguments: e);
} }
@ -203,39 +167,23 @@ class ApiClient {
if (retryTimes > 0) { if (retryTimes > 0) {
print('will retry after 3 seconds...'); print('will retry after 3 seconds...');
await Future.delayed(Duration(seconds: 3)); await Future.delayed(Duration(seconds: 3));
return await _postForResponse(url, requestBody, return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes - 1);
} else { } else {
throw APIException(APIException.OTHER, arguments: e); throw APIException(APIException.OTHER, arguments: e);
} }
} }
} }
Future<Response> getJsonForResponse<T>(String url, Future<Response> getJsonForResponse<T>(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
{String? token,
Map<String, dynamic>? queryParameters,
Map<String, String>? headers,
int retryTimes = 0}) async {
if (headers == null) { if (headers == null) {
headers = {'Content-Type': 'application/json'}; headers = {'Content-Type': 'application/json'};
} else { } else {
headers['Content-Type'] = 'application/json'; headers['Content-Type'] = 'application/json';
} }
return await _getForResponse(url, return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes);
} }
Future<Response> _getForResponse(String url, Future<Response> _getForResponse(String url, {String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0}) async {
{String? token,
Map<String, dynamic>? queryParameters,
Map<String, String>? headers,
int retryTimes = 0}) async {
try { try {
var _headers = <String, String>{}; var _headers = <String, String>{};
if (token != null) { if (token != null) {
@ -250,8 +198,7 @@ class ApiClient {
var queryString = new Uri(queryParameters: queryParameters).query; var queryString = new Uri(queryParameters: queryParameters).query;
url = url + '?' + queryString; url = url + '?' + queryString;
} }
var response = await _get(Uri.parse(url), headers: _headers) var response = await _get(Uri.parse(url), headers: _headers).timeout(Duration(seconds: 60));
.timeout(Duration(seconds: 60));
if (response.statusCode >= 200 && response.statusCode < 300) { if (response.statusCode >= 200 && response.statusCode < 300) {
return response; return response;
@ -262,11 +209,7 @@ class ApiClient {
if (retryTimes > 0) { if (retryTimes > 0) {
print('will retry after 3 seconds...'); print('will retry after 3 seconds...');
await Future.delayed(Duration(seconds: 3)); await Future.delayed(Duration(seconds: 3));
return await _getForResponse(url, return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes - 1);
} else { } else {
throw APIException(APIException.OTHER, arguments: e); throw APIException(APIException.OTHER, arguments: e);
} }
@ -274,11 +217,7 @@ class ApiClient {
if (retryTimes > 0) { if (retryTimes > 0) {
print('will retry after 3 seconds...'); print('will retry after 3 seconds...');
await Future.delayed(Duration(seconds: 3)); await Future.delayed(Duration(seconds: 3));
return await _getForResponse(url, return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes - 1);
} else { } else {
throw APIException(APIException.OTHER, arguments: e); throw APIException(APIException.OTHER, arguments: e);
} }
@ -288,19 +227,14 @@ class ApiClient {
if (retryTimes > 0) { if (retryTimes > 0) {
print('will retry after 3 seconds...'); print('will retry after 3 seconds...');
await Future.delayed(Duration(seconds: 3)); await Future.delayed(Duration(seconds: 3));
return await _getForResponse(url, return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1);
token: token,
queryParameters: queryParameters,
headers: headers,
retryTimes: retryTimes - 1);
} else { } else {
throw APIException(APIException.OTHER, arguments: e); throw APIException(APIException.OTHER, arguments: e);
} }
} }
} }
Future<Response> _get(url, {Map<String, String>? headers}) => Future<Response> _get(url, {Map<String, String>? headers}) => _withClient((client) => client.get(url, headers: headers));
_withClient((client) => client.get(url, headers: headers));
bool _certificateCheck(X509Certificate cert, String host, int port) => true; bool _certificateCheck(X509Certificate cert, String host, int port) => true;
@ -314,8 +248,5 @@ class ApiClient {
} }
} }
Future<Response> _post(url, Future<Response> _post(url, {Map<String, String>? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding));
{Map<String, String>? headers, body, Encoding? encoding}) =>
_withClient((client) =>
client.post(url, headers: headers, body: body, encoding: encoding));
} }

@ -5,6 +5,9 @@ import 'package:http/http.dart';
import 'package:mohem_flutter_app/api/api_client.dart'; import 'package:mohem_flutter_app/api/api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/consts.dart';
import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/exceptions/api_exception.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart'; import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart';
import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as user; import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as user;
import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart' as fav; import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart' as fav;
@ -83,13 +86,30 @@ class ChatApiClient {
} }
Future<fav.FavoriteChatUser> unFavUser({required int userID, required int targetUserID}) async { Future<fav.FavoriteChatUser> unFavUser({required int userID, required int targetUserID}) async {
Response response = await ApiClient().postJsonForResponse( try {
"${ApiConsts.chatFavUser}deleteFavUser", Response response = await ApiClient().postJsonForResponse(
{"targetUserId": targetUserID, "userId": userID}, "${ApiConsts.chatFavUser}deleteFavUser",
token: AppState().chatDetails!.response!.token, {"targetUserId": targetUserID, "userId": userID},
); token: AppState().chatDetails!.response!.token,
fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body); );
return favoriteChatUser; fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body);
return favoriteChatUser;
} catch (e) {
e as APIException;
if (e.message == "api_common_unauthorized") {
logger.d("Token Generated On APIIIIII");
user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken();
if (userLoginResponse.response != null) {
AppState().setchatUserDetails = userLoginResponse;
unFavUser(userID: userID, targetUserID: targetUserID);
} else {
Utils.showToast(
userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr",
);
}
}
throw e;
}
} }
Future<StreamedResponse> uploadMedia(String userId, File file) async { Future<StreamedResponse> uploadMedia(String userId, File file) async {

@ -10,6 +10,7 @@ import 'package:mohem_flutter_app/api/chat/chat_api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/consts.dart';
import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/classes/utils.dart';
import 'package:mohem_flutter_app/exceptions/api_exception.dart';
import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart'; import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart';
import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart';
@ -586,6 +587,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<void> unFavoriteUser({required int userID, required int targetUserID}) async { Future<void> unFavoriteUser({required int userID, required int targetUserID}) async {
fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().unFavUser(userID: userID, targetUserID: targetUserID); fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().unFavUser(userID: userID, targetUserID: targetUserID);
if (favoriteChatUser.response != null) { if (favoriteChatUser.response != null) {
for (ChatUser user in searchedChats!) { for (ChatUser user in searchedChats!) {
if (user.id == favoriteChatUser.response!.targetUserId!) { if (user.id == favoriteChatUser.response!.targetUserId!) {
@ -596,6 +598,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
(ChatUser element) => element.id == targetUserID, (ChatUser element) => element.id == targetUserID,
); );
} }
notifyListeners(); notifyListeners();
} }

@ -46,105 +46,87 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
builder: (BuildContext context, ChatProviderModel m, Widget? child) { builder: (BuildContext context, ChatProviderModel m, Widget? child) {
return m.isLoading return m.isLoading
? ChatHomeShimmer() ? ChatHomeShimmer()
: ListView( : Column(
shrinkWrap: true,
physics: const AlwaysScrollableScrollPhysics(),
children: <Widget>[ children: <Widget>[
Padding( TextField(
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20), controller: m.search,
child: TextField( style: const TextStyle(color: MyColors.darkTextColor, fontWeight: FontWeight.w500, fontSize: 12),
controller: m.search, onChanged: (String val) {
style: const TextStyle(color: MyColors.darkTextColor, fontWeight: FontWeight.w500, fontSize: 12), m.filter(val);
onChanged: (String val) { },
m.filter(val); decoration: InputDecoration(
}, border: fieldBorder(radius: 5, color: 0xFFE5E5E5),
decoration: InputDecoration( focusedBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5),
border: fieldBorder(radius: 5, color: 0xFFE5E5E5), enabledBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5),
focusedBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5), contentPadding: const EdgeInsets.all(11),
enabledBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5), hintText: LocaleKeys.searchfromchat.tr(),
contentPadding: const EdgeInsets.all(11), hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500, fontSize: 12),
hintText: LocaleKeys.searchfromchat.tr(), filled: true,
hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500, fontSize: 12), fillColor: const Color(0xFFF7F7F7),
filled: true, suffixIconConstraints: const BoxConstraints(),
fillColor: const Color(0xFFF7F7F7), suffixIcon: m.search.text.isNotEmpty
suffixIconConstraints: const BoxConstraints(), ? IconButton(
suffixIcon: m.search.text.isNotEmpty constraints: const BoxConstraints(),
? IconButton( onPressed: () {
constraints: const BoxConstraints(), m.clearSelections();
onPressed: () { },
m.clearSelections(); icon: const Icon(Icons.clear, size: 22),
}, color: MyColors.redA3Color,
icon: const Icon(Icons.clear, size: 22), )
color: MyColors.redA3Color, : null,
)
: null,
),
), ),
), ).paddingOnly(top: 20, bottom: 14),
if (m.searchedChats != null) if (m.searchedChats != null)
ListView.separated( ListView.separated(
itemCount: m.searchedChats!.length, itemCount: m.searchedChats!.length,
padding: const EdgeInsets.only(bottom: 80),
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const ClampingScrollPhysics(),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
// todo @aamir, remove list tile, make a custom ui instead
return SizedBox( return SizedBox(
height: 55, height: 55,
// todo @aamir, remove list tile, make a custom ui instead child: Row(
child: ListTile( children: [
leading: Stack( Stack(
children: <Widget>[ children: <Widget>[
SvgPicture.asset( SvgPicture.asset(
"assets/images/user.svg", "assets/images/user.svg",
height: 48, height: 48,
width: 48, width: 48,
), ),
Positioned( Positioned(
right: 5, right: 5,
bottom: 1, bottom: 1,
child: Container( child: Container(
width: 10, width: 10,
height: 10, height: 10,
decoration: BoxDecoration( decoration: BoxDecoration(
color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red,
borderRadius: const BorderRadius.all( borderRadius: const BorderRadius.all(
Radius.circular(10), Radius.circular(10),
),
), ),
), ),
), )
) ],
], ),
), Column(
title: (m.searchedChats![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(color: MyColors.darkTextColor), mainAxisAlignment: MainAxisAlignment.start,
// subtitle: (m.searchedChats![index].isTyping == true ? "Typing ..." : "").toText11(color: MyColors.normalTextColor), crossAxisAlignment: CrossAxisAlignment.start,
trailing: SizedBox( children: [
width: 60, (m.searchedChats![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(color: MyColors.darkTextColor).paddingOnly(left: 11, top: 13),
child: Row( ],
crossAxisAlignment: CrossAxisAlignment.center, ).expanded,
mainAxisAlignment: MainAxisAlignment.end, SizedBox(
mainAxisSize: MainAxisSize.max, width: 60,
children: <Widget>[ child: Row(
// if (m.searchedChats![index].isLoadingCounter!) crossAxisAlignment: CrossAxisAlignment.center,
// Flexible( mainAxisAlignment: MainAxisAlignment.end,
// child: Container( mainAxisSize: MainAxisSize.max,
// padding: EdgeInsets.zero, children: <Widget>[
// alignment: Alignment.centerRight, if (m.searchedChats![index].unreadMessageCount! > 0)
// width: 18, Container(
// height: 18, alignment: Alignment.center,
// decoration: const BoxDecoration(
// // color: MyColors.redColor,
// borderRadius: BorderRadius.all(
// Radius.circular(20),
// ),
// ),
// child: CircularProgressIndicator(),
// ),
// ),
if (m.searchedChats![index].unreadMessageCount! > 0)
Flexible(
child: Container(
padding: EdgeInsets.zero,
alignment: Alignment.centerRight,
width: 18, width: 18,
height: 18, height: 18,
decoration: const BoxDecoration( decoration: const BoxDecoration(
@ -158,18 +140,12 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
color: MyColors.white, color: MyColors.white,
) )
.center, .center,
), ).paddingOnly(right: 10).center,
), Icon(
Flexible( m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == false ? Icons.star_sharp : Icons.star_sharp,
child: IconButton(
constraints: BoxConstraints(),
alignment: Alignment.centerRight,
padding: EdgeInsets.zero,
icon: Icon(
m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == false ? Icons.star_sharp : Icons.star_sharp,
),
color: m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == true ? MyColors.yellowColor : MyColors.grey35Color, color: m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == true ? MyColors.yellowColor : MyColors.grey35Color,
onPressed: () { ).onPress(
() {
if (m.searchedChats![index].isFav == null || m.searchedChats![index].isFav == false) { if (m.searchedChats![index].isFav == null || m.searchedChats![index].isFav == false) {
m.favoriteUser( m.favoriteUser(
userID: AppState().chatDetails!.response!.id!, userID: AppState().chatDetails!.response!.id!,
@ -187,40 +163,18 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
); );
} }
}, },
), ).center
) ],
], ),
), ),
), ],
minVerticalPadding: 0,
onTap: () {
Navigator.pushNamed(
context,
AppRoutes.chatDetailed,
arguments: {"targetUser": m.searchedChats![index], "isNewChat": false},
).then((Object? value) {
// m.GetUserChatHistoryNotDeliveredAsync(userId: int.parse(AppState().chatDetails!.response!.id.toString()));
m.clearSelections();
m.notifyListeners();
});
},
), ),
); );
}, },
separatorBuilder: (BuildContext context, int index) => const Padding( separatorBuilder: (BuildContext context, int index) => const Divider(color: MyColors.lightGreyE5Color).paddingOnly(left: 59),
padding: EdgeInsets.only( ).paddingOnly(bottom: 70).expanded,
right: 10,
left: 70,
),
child: Divider(
color: Color(
0xFFE5E5E5,
),
),
),
),
], ],
); ).paddingOnly(left: 21, right: 21);
}, },
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(

@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/colors.dart';
@ -26,81 +27,70 @@ class ChatFavoriteUsersScreen extends StatelessWidget {
return m.favUsersList != null && m.favUsersList.isNotEmpty return m.favUsersList != null && m.favUsersList.isNotEmpty
? ListView.separated( ? ListView.separated(
itemCount: m.favUsersList!.length, itemCount: m.favUsersList!.length,
padding: const EdgeInsets.only(top: 20),
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return SizedBox( return SizedBox(
height: 55, height: 55,
child: ListTile( child: Row(
leading: Stack( children: [
children: <Widget>[ Stack(
SvgPicture.asset( children: <Widget>[
"assets/images/user.svg", SvgPicture.asset(
height: 48, "assets/images/user.svg",
width: 48, height: 48,
), width: 48,
Positioned( ),
right: 5, Positioned(
bottom: 1, right: 5,
child: Container( bottom: 1,
width: 10, child: Container(
height: 10, width: 10,
decoration: BoxDecoration( height: 10,
color: m.favUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, decoration: BoxDecoration(
borderRadius: const BorderRadius.all( color: m.favUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red,
Radius.circular(10), borderRadius: const BorderRadius.all(
Radius.circular(10),
),
), ),
), ),
), )
) ],
],
),
title: (m.favUsersList![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(
color: MyColors.darkTextColor,
),
trailing: IconButton(
alignment: Alignment.centerRight,
padding: EdgeInsets.zero,
icon: Icon(
m.favUsersList![index].isFav! ? Icons.star : Icons.star_border,
), ),
color: m.favUsersList![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, Column(
onPressed: () { mainAxisAlignment: MainAxisAlignment.start,
if (m.favUsersList![index].isFav!) crossAxisAlignment: CrossAxisAlignment.start,
m.unFavoriteUser( children: [
userID: AppState().chatDetails!.response!.id!, (m.favUsersList![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(color: MyColors.darkTextColor).paddingOnly(left: 11, top: 13),
targetUserID: m.favUsersList![index].id!, ],
); ).expanded,
}, SizedBox(
), width: 60,
minVerticalPadding: 0, child: Row(
onTap: () { crossAxisAlignment: CrossAxisAlignment.center,
Navigator.pushNamed( mainAxisAlignment: MainAxisAlignment.end,
context, mainAxisSize: MainAxisSize.max,
AppRoutes.chatDetailed, children: <Widget>[
arguments: {"targetUser": m.favUsersList![index], "isNewChat": false}, Icon(
).then( m.favUsersList![index].isFav! ? Icons.star : Icons.star_border,
(Object? value) { color: m.favUsersList![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color,
m.clearSelections(); ).onPress(() {
}, if (m.favUsersList![index].isFav!) {
); m.unFavoriteUser(
}, userID: AppState().chatDetails!.response!.id!,
targetUserID: m.favUsersList![index].id!,
);
}
}).center,
],
),
),
],
), ),
); );
}, },
separatorBuilder: (BuildContext context, int index) => const Padding( separatorBuilder: (BuildContext context, int index) => const Divider(color: MyColors.lightGreyE5Color).paddingOnly(left: 70),
padding: EdgeInsets.only( ).paddingAll(21)
right: 10,
left: 70,
),
child: Divider(
color: Color(
0xFFE5E5E5,
),
),
),
)
: Column( : Column(
children: <Widget>[ children: <Widget>[
Utils.getNoDataWidget(context).expanded, Utils.getNoDataWidget(context).expanded,

Loading…
Cancel
Save