Merge branch 'master' into faiz_cs
# Conflicts: # lib/classes/consts.dart # lib/ui/landing/dashboard_screen.dart # lib/ui/marathon/marathon_intro_screen.dart # lib/ui/marathon/marathon_provider.dart # lib/ui/marathon/marathon_screen.dart # lib/ui/marathon/marathon_winner_selection.dart # lib/ui/marathon/widgets/question_card.dart # pubspec.yamlfaiz_marathon_signalR_critical
commit
2f825151a0
@ -0,0 +1,182 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:http/http.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/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_user_login_token_model.dart' as user;
|
||||
import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart' as fav;
|
||||
|
||||
class ChatApiClient {
|
||||
static final ChatApiClient _instance = ChatApiClient._internal();
|
||||
|
||||
ChatApiClient._internal();
|
||||
|
||||
factory ChatApiClient() => _instance;
|
||||
|
||||
Future<user.UserAutoLoginModel> getUserLoginToken() async {
|
||||
Response response = await ApiClient().postJsonForResponse(
|
||||
"${ApiConsts.chatLoginTokenUrl}externaluserlogin",
|
||||
{
|
||||
"employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER.toString(),
|
||||
"password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG",
|
||||
},
|
||||
);
|
||||
user.UserAutoLoginModel userLoginResponse = user.userAutoLoginModelFromJson(
|
||||
response.body,
|
||||
);
|
||||
return userLoginResponse;
|
||||
}
|
||||
|
||||
Future<List<ChatUser>?> getChatMemberFromSearch(String sName, int cUserId) async {
|
||||
Response response = await ApiClient().getJsonForResponse(
|
||||
"${ApiConsts.chatLoginTokenUrl}getUserWithStatusAndFavAsync/$sName/$cUserId",
|
||||
token: AppState().chatDetails!.response!.token,
|
||||
);
|
||||
return searchUserJsonModel(response.body);
|
||||
}
|
||||
|
||||
List<ChatUser> searchUserJsonModel(String str) => List<ChatUser>.from(
|
||||
json.decode(str).map((x) => ChatUser.fromJson(x)),
|
||||
);
|
||||
|
||||
Future<ChatUserModel> getRecentChats() async {
|
||||
try {
|
||||
Response response = await ApiClient().getJsonForResponse(
|
||||
"${ApiConsts.chatRecentUrl}getchathistorybyuserid",
|
||||
token: AppState().chatDetails!.response!.token,
|
||||
);
|
||||
return ChatUserModel.fromJson(
|
||||
json.decode(response.body),
|
||||
);
|
||||
} 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;
|
||||
getRecentChats();
|
||||
} else {
|
||||
Utils.showToast(
|
||||
userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr",
|
||||
);
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Future<ChatUserModel> getFavUsers() async {
|
||||
Response favRes = await ApiClient().getJsonForResponse(
|
||||
"${ApiConsts.chatFavUser}getFavUserById/${AppState().chatDetails!.response!.id}",
|
||||
token: AppState().chatDetails!.response!.token,
|
||||
);
|
||||
return ChatUserModel.fromJson(
|
||||
json.decode(favRes.body),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Response> getSingleUserChatHistory({required int senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false, required int paginationVal}) async {
|
||||
try {
|
||||
Response response = await ApiClient().getJsonForResponse(
|
||||
"${ApiConsts.chatSingleUserHistoryUrl}GetUserChatHistory/$senderUID/$receiverUID/$paginationVal",
|
||||
token: AppState().chatDetails!.response!.token,
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
e as APIException;
|
||||
if (e.message == "api_common_unauthorized") {
|
||||
user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken();
|
||||
if (userLoginResponse.response != null) {
|
||||
AppState().setchatUserDetails = userLoginResponse;
|
||||
getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal);
|
||||
} else {
|
||||
Utils.showToast(
|
||||
userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr",
|
||||
);
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Future<fav.FavoriteChatUser> favUser({required int userID, required int targetUserID}) async {
|
||||
Response response = await ApiClient().postJsonForResponse(
|
||||
"${ApiConsts.chatFavUser}addFavUser",
|
||||
{
|
||||
"targetUserId": targetUserID,
|
||||
"userId": userID,
|
||||
},
|
||||
token: AppState().chatDetails!.response!.token);
|
||||
fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body);
|
||||
return favoriteChatUser;
|
||||
}
|
||||
|
||||
Future<fav.FavoriteChatUser> unFavUser({required int userID, required int targetUserID}) async {
|
||||
try {
|
||||
Response response = await ApiClient().postJsonForResponse(
|
||||
"${ApiConsts.chatFavUser}deleteFavUser",
|
||||
{"targetUserId": targetUserID, "userId": userID},
|
||||
token: AppState().chatDetails!.response!.token,
|
||||
);
|
||||
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 {
|
||||
dynamic request = MultipartRequest('POST', Uri.parse('${ApiConsts.chatServerBaseApiUrl}upload'));
|
||||
request.fields.addAll({'userId': userId, 'fileSource': '1'});
|
||||
request.files.add(await MultipartFile.fromPath('files', file.path));
|
||||
request.headers.addAll({'Authorization': 'Bearer ${AppState().chatDetails!.response!.token}'});
|
||||
StreamedResponse response = await request.send();
|
||||
return response;
|
||||
}
|
||||
|
||||
// Download File For Chat
|
||||
|
||||
Future<Uint8List> downloadURL({required String fileName, required String fileTypeDescription}) async {
|
||||
Response response = await ApiClient().postJsonForResponse(
|
||||
"${ApiConsts.chatMediaImageUploadUrl}download",
|
||||
{"fileType": fileTypeDescription, "fileName": fileName, "fileSource": 1},
|
||||
token: AppState().chatDetails!.response!.token,
|
||||
);
|
||||
Uint8List data = Uint8List.fromList(response.bodyBytes);
|
||||
return data;
|
||||
}
|
||||
|
||||
Future getUsersImages({required List encryptedEmails}) async {
|
||||
Response response = await ApiClient().postJsonForResponse(
|
||||
"${ApiConsts.chatUserImages}images",
|
||||
{
|
||||
"encryptedEmails": ["/g8Rc+s6eEOdci41PwJuV5dX+gXe51G9OTHzb9ahcVlHCmVvNhxReirudF79+hdxVSkCnQ6wC5DBFV8xnJlC74X6157PxF7mNYrAYuHRgp4="],
|
||||
"fromClient": true
|
||||
},
|
||||
token: AppState().chatDetails!.response!.token,
|
||||
);
|
||||
logger.d(response.body);
|
||||
// Uint8List data = Uint8List.fromList(response.body);
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as Io;
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:mohem_flutter_app/api/dashboard_api_client.dart';
|
||||
import 'package:mohem_flutter_app/classes/colors.dart';
|
||||
import 'package:mohem_flutter_app/main.dart';
|
||||
import 'package:mohem_flutter_app/models/itg/advertisement.dart' as ads;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
class ITGAdsScreen extends StatefulWidget {
|
||||
const ITGAdsScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ITGAdsScreenState createState() => _ITGAdsScreenState();
|
||||
}
|
||||
|
||||
class _ITGAdsScreenState extends State<ITGAdsScreen> {
|
||||
late Future<VideoPlayerController> _futureController;
|
||||
late VideoPlayerController _controller;
|
||||
bool skip = false;
|
||||
bool isVideo = false;
|
||||
bool isImage = false;
|
||||
String ext = '';
|
||||
late File imageFile;
|
||||
ads.Advertisement? advertisementData;
|
||||
dynamic data;
|
||||
String? masterID;
|
||||
|
||||
void checkFileType() async {
|
||||
String? rFile = advertisementData!.viewAttachFileColl!.first.base64String;
|
||||
String? rFileExt = advertisementData!.viewAttachFileColl!.first.fileName;
|
||||
ext = "." + rFileExt!.split(".").last.toLowerCase();
|
||||
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif") {
|
||||
await processImage(rFile!);
|
||||
isImage = true;
|
||||
} else {
|
||||
isVideo = true;
|
||||
_futureController = createVideoPlayer(rFile!);
|
||||
}
|
||||
setState(() {});
|
||||
initTimer();
|
||||
}
|
||||
|
||||
Future processImage(String encodedBytes) async {
|
||||
try {
|
||||
Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
|
||||
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
|
||||
imageFile = Io.File("${appDocumentsDirectory.path}/addImage$ext");
|
||||
imageFile.writeAsBytesSync(decodedBytes);
|
||||
} catch (e) {
|
||||
logger.d(e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<VideoPlayerController> createVideoPlayer(String encodedBytes) async {
|
||||
try {
|
||||
Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
|
||||
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
|
||||
File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4");
|
||||
file.writeAsBytesSync(decodedBytes);
|
||||
VideoPlayerController controller = VideoPlayerController.file(file);
|
||||
await controller.initialize();
|
||||
await controller.play();
|
||||
await controller.setVolume(1.0);
|
||||
await controller.setLooping(false);
|
||||
return controller;
|
||||
} catch (e) {
|
||||
return new VideoPlayerController.asset("dataSource");
|
||||
}
|
||||
}
|
||||
|
||||
void initTimer() {
|
||||
Future.delayed(const Duration(seconds: 5), () {
|
||||
skip = true;
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
data = ModalRoute.of(context)!.settings.arguments;
|
||||
if (advertisementData == null) advertisementData = data["advertisement"] as ads.Advertisement;
|
||||
if (masterID == null) masterID = data["masterId"];
|
||||
if (advertisementData != null) {
|
||||
checkFileType();
|
||||
}
|
||||
double height = MediaQuery.of(context).size.height * .25;
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
if (isVideo)
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height * .3,
|
||||
child: FutureBuilder(
|
||||
future: _futureController,
|
||||
builder: (BuildContext context, AsyncSnapshot<Object?> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) {
|
||||
_controller = snapshot.data as VideoPlayerController;
|
||||
return AspectRatio(
|
||||
aspectRatio: _controller.value.aspectRatio,
|
||||
child: VideoPlayer(_controller),
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
if (isImage) Image.file(imageFile),
|
||||
if (skip)
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
// DashboardApiClient().setAdvertisementViewed(widget.addMasterId, widget.advertisement!.advertisementId!).then((value) {
|
||||
// logger.d(value);
|
||||
// });
|
||||
},
|
||||
child: const Text("Go To Dashboard"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as Io;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
class MovieTheaterBody extends StatefulWidget {
|
||||
final String encodedBytes;
|
||||
|
||||
const MovieTheaterBody({required this.encodedBytes});
|
||||
|
||||
@override
|
||||
_MovieTheaterBodyState createState() => _MovieTheaterBodyState();
|
||||
}
|
||||
|
||||
class _MovieTheaterBodyState extends State<MovieTheaterBody> {
|
||||
late Future<VideoPlayerController> _futureController;
|
||||
late VideoPlayerController _controller;
|
||||
|
||||
Future<VideoPlayerController> createVideoPlayer() async {
|
||||
try {
|
||||
var decodedBytes = base64Decode(widget.encodedBytes);
|
||||
|
||||
var file = Io.File("decodedBezkoder.mp4");
|
||||
file.writeAsBytesSync(decodedBytes);
|
||||
|
||||
VideoPlayerController controller = VideoPlayerController.file(file);
|
||||
await controller.initialize();
|
||||
await controller.setLooping(true);
|
||||
return controller;
|
||||
} catch (e) {
|
||||
print("object0000000");
|
||||
print(e);
|
||||
return new VideoPlayerController.asset("dataSource");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_futureController = createVideoPlayer();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Expanded(
|
||||
child: FutureBuilder(
|
||||
future: _futureController,
|
||||
builder: (context, snapshot) {
|
||||
//UST: 05/2021 - MovieTheaterBody - id:11 - 2pts - Criação
|
||||
if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) {
|
||||
_controller = snapshot.data as VideoPlayerController;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: _controller.value.aspectRatio,
|
||||
child: VideoPlayer(_controller),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 50,
|
||||
),
|
||||
FloatingActionButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
if (_controller.value.isPlaying) {
|
||||
_controller.pause();
|
||||
} else {
|
||||
// If the video is paused, play it.
|
||||
_controller.play();
|
||||
}
|
||||
});
|
||||
},
|
||||
backgroundColor: Colors.green[700],
|
||||
child: Icon(
|
||||
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue