|
|
|
|
@ -2,17 +2,20 @@ 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 {
|
|
|
|
|
final String encodedBytes;
|
|
|
|
|
final String fileExtension;
|
|
|
|
|
final String addMasterId;
|
|
|
|
|
final ads.Advertisement advertisement;
|
|
|
|
|
|
|
|
|
|
const ITGAdsScreen({required this.encodedBytes, required this.fileExtension});
|
|
|
|
|
const ITGAdsScreen({required this.addMasterId, required this.advertisement});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_ITGAdsScreenState createState() => _ITGAdsScreenState();
|
|
|
|
|
@ -22,10 +25,39 @@ 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;
|
|
|
|
|
|
|
|
|
|
void checkFileType() async {
|
|
|
|
|
String? rFile = widget.advertisement!.viewAttachFileColl!.first.base64String;
|
|
|
|
|
String? rFileExt = widget.advertisement!.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(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() async {
|
|
|
|
|
Future<VideoPlayerController> createVideoPlayer(String encodedBytes) async {
|
|
|
|
|
try {
|
|
|
|
|
Uint8List decodedBytes = base64Decode(widget.encodedBytes.split("base64,").last);
|
|
|
|
|
Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
|
|
|
|
|
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
|
|
|
|
|
File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4");
|
|
|
|
|
file.writeAsBytesSync(decodedBytes);
|
|
|
|
|
@ -40,55 +72,15 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkType(){
|
|
|
|
|
|
|
|
|
|
// getFileTypeDescription(value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getFileTypeDescription(String value) {
|
|
|
|
|
switch (value) {
|
|
|
|
|
case ".pdf":
|
|
|
|
|
return "application/pdf";
|
|
|
|
|
case ".png":
|
|
|
|
|
return "image/png";
|
|
|
|
|
case ".txt":
|
|
|
|
|
return "text/plain";
|
|
|
|
|
case ".jpg":
|
|
|
|
|
return "image/jpg";
|
|
|
|
|
case ".jpeg":
|
|
|
|
|
return "image/jpeg";
|
|
|
|
|
case ".ppt":
|
|
|
|
|
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
|
|
|
case ".pptx":
|
|
|
|
|
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
|
|
|
case ".doc":
|
|
|
|
|
return "application/vnd.openxmlformats-officedocument.wordprocessingm";
|
|
|
|
|
case ".docx":
|
|
|
|
|
return "application/vnd.openxmlformats-officedocument.wordprocessingm";
|
|
|
|
|
case ".xls":
|
|
|
|
|
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
|
|
|
case ".xlsx":
|
|
|
|
|
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
|
|
|
case ".zip":
|
|
|
|
|
return "application/octet-stream";
|
|
|
|
|
case ".rar":
|
|
|
|
|
return "application/octet-stream";
|
|
|
|
|
default:
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_futureController = createVideoPlayer();
|
|
|
|
|
checkFileType();
|
|
|
|
|
initTimer();
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initTimer() {
|
|
|
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
|
|
|
Future.delayed(const Duration(seconds: 5), () {
|
|
|
|
|
setState(() {
|
|
|
|
|
skip = true;
|
|
|
|
|
});
|
|
|
|
|
@ -107,28 +99,34 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
body: Column(
|
|
|
|
|
children: [
|
|
|
|
|
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 (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: () {},
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
// DashboardApiClient().setAdvertisementViewed(widget.addMasterId, widget.advertisement!.advertisementId!).then((value) {
|
|
|
|
|
// logger.d(value);
|
|
|
|
|
// });
|
|
|
|
|
},
|
|
|
|
|
child: const Text("Go To Dashboard"),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
|