Description
class NewTradingStrategy extends StatefulWidget {
final String? videoId;
const NewTradingStrategy({super.key, this.videoId});
@OverRide
State createState() => _NewTradingStrategyState();
}
class _NewTradingStrategyState extends State {
// final NewTradingStrategyController controller = Get.find();
ChewieController? chewieController;
VideoPlayerController? videoPlayerController;
String speakerName = "";
String speakerImage = "";
Education? education;
late ModuleActionCotroller moduleActionCotroller;
late CommentController commentController;
TextEditingController _comment = TextEditingController();
@OverRide
void initState() {
// controller.getList("2023-07-10");
fetchLatestTradingStrategy(
widget.videoId == null ? null : int.parse(widget.videoId!));
super.initState();
}
Future fetchLatestTradingStrategy(int? id) async {
final dio = Dio();
String token = await SessionHandler().get_token();
var url = ApiConst.BASE_URL;
if (id != null) {
url = ApiConst.BASE_URL + "api/TradingStrategy/find?market=stock&id=$id";
} else {
url = ApiConst.BASE_URL + "api/TradingStrategy/find?market=stock";
}
final result = await dio.get(
url,
options: Options(
headers: {
"token": token,
},
),
);
if (result.data['data'] != null) {
if (mounted) {
setState(() {
education = Education.fromJson(result.data['data']);
populatingVideoPlayer();
populateSpeaker();
Get.lazyPut(() => ModuleActionCotroller(),
fenix: true, tag: "video" + education!.id.toString());
Get.lazyPut(() => CommentController(),
fenix: true, tag: "video" + education!.id.toString());
moduleActionCotroller =
Get.find(tag: "video" + education!.id.toString());
commentController = Get.find(tag: "video" + education!.id.toString());
//
moduleActionCotroller.setId(education!.id.toString(), "video");
commentController.setNoteId(education!.id.toString(), "video");
});
}
} else {
// EasyLoading.showError("Failed to get video data").then((value) {
// Get.back();
// });
}
//
watchTradingStrategy();
}
populateSpeaker() async {
final dio = Dio();
print(ApiConst.BASE_URL +
"api/TradingStrategy/speaker?id=" +
education!.id.toString());
String token = await SessionHandler().get_token();
var url = ApiConst.BASE_URL +
"api/TradingStrategy/speaker?id=" +
education!.id.toString();
final result = await dio.get(
url,
options: Options(
headers: {
"token": token,
},
),
);
if (result.data['data'] != null) {
setState(() {
speakerName = result.data['data']['fullname'];
speakerImage = result.data['data']['image'];
});
}
}
Future watchTradingStrategy() async {
print("Watching Trading Strategy");
final dio = Dio();
String token = await SessionHandler().get_token();
final data = await dio.post(
ApiConst.BASE_URL + "api/TradingStrategy/watch",
data: {"video_id": education!.id},
options: Options(
headers: {
'token': token,
},
),
);
}
populatingVideoPlayer() async {
print('cuaks video : ${Uri.parse(education!.mediaUrl!)}');
videoPlayerController = VideoPlayerController.networkUrl(
Uri.parse(education!.mediaUrl!),
);
await videoPlayerController!.initialize();
setState(() {
print("Video Player Initialized");
chewieController = ChewieController(
videoPlayerController: videoPlayerController!,
autoPlay: false,
looping: true,
);
});
}
@OverRide
void dispose() {
videoPlayerController?.dispose();
chewieController?.dispose();
super.dispose();
}
@OverRide
Widget build(BuildContext context) {
// print("cuaks url : ${ApiConst.get_video_attchment +
// education!.thumbnail!}");
return Scaffold(
backgroundColor: AppColors.backgroundColor,
appBar: PreferredSize(
preferredSize: Size.fromHeight(55),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 0,
blurRadius: 24.2,
offset: Offset(0, 3),
),
],
),
padding: const EdgeInsets.symmetric(
horizontal: 24,
),
child: Column(
children: [
Container(
height: MediaQuery.viewPaddingOf(context).top,
width: double.infinity,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
InkWell(
onTap: () {
Get.back();
},
child: Row(
children: [
Icon(
Icons.arrow_back,
),
SizedBox(width: 8),
],
),
),
Text(
"Trading Strategy Video",
style: GoogleFonts.quicksand(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Color(
0xff484C52,
),
),
),
],
),
),
],
),
],
),
),
),
body: education == null
? Container()
: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
chewieController == null
? CachedNetworkImage(
imageUrl: ApiConst.get_video_attchment +
education!.thumbnail!,
placeholder: (context, url) => Center(
child: CircularProgressIndicator(),
),
errorWidget: (context, url, error) =>
Icon(Icons.error),
)
: AspectRatio(
aspectRatio: 24 / 9,
child: Chewie(
controller: chewieController!,
),
),
Container(
width: double.infinity,
padding: EdgeInsets.symmetric(
horizontal: 24.w,
vertical: 12.w,
),
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 257.w,
child: Text(
education!.title!,
style: GoogleFonts.quicksand(
fontSize: 18,
fontWeight: FontWeight.w700,
color: Color(
0xff484C52,
),
),
),
),
Spacer(),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 4,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Color(0xff484C52),
),
),
child: Text(
education!.duration!,
style: GoogleFonts.quicksand(
fontSize: 10,
fontWeight: FontWeight.w600,
color: Color(0xff484C52),
),
),
),
],
),
if (speakerName != "") SizedBox(height: 4),
if (speakerName != "")
Row(
children: [
Container(
height: 24.w,
width: 24.w,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
image: DecorationImage(
image: CachedNetworkImageProvider(
ApiConst.BASE_URL +
'assets/file_upload/member_profile_images/' +
speakerImage,
),
fit: BoxFit.cover,
),
),
),
SizedBox(
width: 8.w,
),
Text(
speakerName,
style: GoogleFonts.quicksand(
fontSize: 13.sp,
fontWeight: FontWeight.w600,
color: Color(
0xff484C52,
),
),
),
],
),
SizedBox(height: 12.w),
Row(
children: [
Image.asset(
"assets/v3_assets/calendar_icon.png",
width: 22.w,
height: 22.w,
color: Color(0xff484C52),
),
SizedBox(width: 8.w),
Text(
Jiffy(education!.publishDate)
.format("dd MMM yyyy HH:mm") +
" (GMT +7)",
style: GoogleFonts.quicksand(
fontSize: 12.sp,
fontWeight: FontWeight.w600,
color: Color(
0xff484C52,
),
),
),
],
),
SizedBox(height: 13.5.w),
InkWell(
onTap: () {
videoPlayerController!.pause();
chewieController!.pause();
PersistentNavBarNavigator.pushNewScreen(
context,
screen: Archive(focus: "Trading Strategy"),
withNavBar: false,
);
},
child: Container(
//underline only
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: AppColors.primary,
width: 1,
),
),
),
child: Text(
"View All Videos",
style: GoogleFonts.quicksand(
fontSize: 13.sp,
color: AppColors.primary,
),
),
),
),
SizedBox(height: 13.5.w),
],
),
),
BlocBuilder<SessionBloc, SessionState>(
builder: (BuildContext context, SessionState state) {
if (state is LoadSuccess) {
SessionProfile? sessionProfile = state.posts;
return CommentFeature(
type: "video",
id: education!.id.toString(),
member: sessionProfile!.member_id!,
memberType: sessionProfile.member_type!,
);
}
return Container();
},
),
],
),
),
),
BlocBuilder<SessionBloc, SessionState>(
builder: (BuildContext context, SessionState state) {
if (state is LoadSuccess) {
SessionProfile? sessionProfile = state.posts;
return GetBuilder(
tag: "video" + education!.id.toString(),
builder: (commentController) {
return Container(
padding: EdgeInsets.only(
left: 24.w,
right: 24.w,
top: 10.w,
bottom: 10.w,
),
color: Colors.white,
child: Container(
color: Colors.white,
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.symmetric(
horizontal: 0.h, vertical: 5.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (commentController.isReplying.value)
Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
"Reply to ${commentController.activeReplyComment.value.createdBy!.displayName}",
style: GoogleFonts.quicksand(
fontSize: 14.sp,
fontWeight: FontWeight.w600,
color: Color(0xff484C52),
),
),
IconButton(
onPressed: () {
commentController.resetAll();
},
icon: Icon(
Icons.close,
color: AppColors.primary,
),
),
],
),
SizedBox(height: 10.w),
Text(
commentController
.activeReplyComment.value.comment
.toString(),
style: GoogleFonts.quicksand(
fontSize: 12.sp,
fontWeight: FontWeight.w600,
color: Color(0xff484C52),
),
),
SizedBox(height: 10.w),
],
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10.h,
),
sessionProfile!.member_profile_image != ""
? AvatarView(
radius: 20.h,
borderColor: Colors.white,
borderWidth: 1,
avatarType: AvatarType.CIRCLE,
backgroundColor:
AppColors.primary,
imagePath: ApiConst
.profile_image_path +
sessionProfile
.member_profile_image!,
placeHolder: Container(
child: Icon(
Icons.person,
size: 10.sp,
),
),
errorWidget: Container(
child: Icon(
Icons.error,
size: 10.sp,
),
),
)
: Container(),
SizedBox(
width: 5.h,
),
Expanded(
child: Container(
padding: EdgeInsets.only(
top: commentController
.isReplying.value
? 0.w
: 0.w,
),
child: TextFormField(
maxLines: null,
controller: _comment,
autocorrect: false,
textCapitalization:
TextCapitalization.sentences,
decoration: InputDecoration(
isDense: true,
contentPadding:
EdgeInsets.all(10),
enabledBorder: OutlineInputBorder(
borderRadius:
BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.0.w,
),
),
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderRadius:
BorderRadius.circular(25.0),
borderSide: BorderSide(
color: Colors.grey,
width: 1.0.w,
),
),
),
),
),
),
SizedBox(
height: 40.w,
child: FloatingActionButton(
backgroundColor: Colors.white,
onPressed: () async {
if (_comment.text
.toString()
.length >
0) {
await commentController
.saveComment(_comment.text);
_comment.text = "";
}
},
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Icon(
Icons.send,
color: AppColors.primary,
size: 18.sp,
),
],
),
),
),
],
),
],
),
),
);
},
);
}
return Container();
},
),
],
),
);
}
}