import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/svg.dart'; import 'package:gap/gap.dart'; import 'package:get/get.dart'; import 'package:glassmorphism/glassmorphism.dart'; import 'package:traderscircuit/Utils/Common/CommonBottomNavigation.dart'; import 'package:traderscircuit/Utils/Common/CommonTabBar.dart'; import 'package:traderscircuit/Utils/Common/commonBotton.dart'; import 'package:traderscircuit/Utils/Common/comonGlassmorphicContainer.dart'; import 'package:traderscircuit/Utils/Common/sized_box.dart'; import 'package:traderscircuit/Utils/text.dart'; import 'package:traderscircuit/Utils/utils.dart'; import 'package:traderscircuit/controller/contact_us_controller.dart'; import 'package:traderscircuit/controller/products_controller.dart'; import 'package:traderscircuit/model/ProductsModel/call_recommendations_model.dart'; import 'package:traderscircuit/view/MainScreen/MainScreen.dart'; import 'package:traderscircuit/view/MainScreen/stockDetails/stock_details_screen.dart'; import 'package:traderscircuit/view/Sidemenu/Sidemenu.dart'; import 'package:traderscircuit/view/onBoarding/splashScreen1.dart'; import 'package:traderscircuit/view_model/ProductsApi/products_api.dart'; class ShortTrade extends StatefulWidget { const ShortTrade({super.key}); @override State createState() => _ShortTradeState(); } class _ShortTradeState extends State { final GlobalKey _scaffoldKey1 = GlobalKey(); List containerTexts = ["Swing Trade", "Multibagger", "Options"]; ProductsController productsController = Get.put(ProductsController()); @override void initState() { productsController.isLoaded.value = true; ProductsApi().getSwingTradeRecommendationsApi().then((value) { productsController.swingTradeModel = CallRecommendationsModel.fromJson(value.data); ProductsApi().getMultibaggerRecommendationsApi().then((value) { productsController.multibaggerModel = CallRecommendationsModel.fromJson(value.data); ProductsApi().getOptionsRecommendationsApi().then((value) { productsController.optionModel = CallRecommendationsModel.fromJson(value.data); productsController.isLoaded.value = false; }); }); }); super.initState(); } @override Widget build(BuildContext context) { return WillPopScope( onWillPop: () async { _onBackButtonPressed(context); return true; // Return true to allow the pop action }, child: Scaffold( key: _scaffoldKey1, backgroundColor: Colors.black, drawerEnableOpenDragGesture: false, drawer: const SideMenu(), extendBody: true, appBar: AppBar( scrolledUnderElevation: 0.0, backgroundColor: Colors.black, elevation: 0, automaticallyImplyLeading: false, titleSpacing: 0, leading: InkWell( onTap: () { _scaffoldKey1.currentState?.openDrawer(); }, child: Center( child: Image.asset( 'assets/images/png/menu.png', height: 15.h, width: 20.w, ), ), ), // title: text22W600('Short'), ), // CommonAppbar( // titleTxt: '', // // preferredSize: Size.fromHeight(60.h), // showLeading: false, // customleading: InkWell( // onTap: () { // _scaffoldKey1.currentState?.openDrawer(); // }, // child: Center( // child: Image.asset( // 'assets/images/png/menu.png', // height: 15.h, // width: 20.w, // ), // ), // // Icon( // // Icons.menu, // // color: Colors.white, // // size: 27.sp, // // ), // ), // ),j body: Obx( () => Stack( children: [ const CommonBlurLeft(), const CommonBlurRight(), Stack(children: [ Padding( padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 16), child: ListView( physics: const NeverScrollableScrollPhysics(), children: [ sizedBoxHeight(15.h), SizedBox( height: 60, width: double.infinity, // color: Colors.amber, child: ListView.builder( shrinkWrap: true, scrollDirection: Axis.horizontal, itemCount: containerTexts.length, itemBuilder: (context, index) { return GestureDetector( onTap: () { productsController.selectedIndex.value = index; }, child: Row( children: [ topContainer( containerTexts[index], index), sizedBoxWidth(10.w) ], ), ); }), ), sizedBoxHeight(20.h), productsController.isLoaded.value ? const Center( child: CircularProgressIndicator( color: Color(0xFF0093FF), ), ) : DefaultTabController( length: 2, // initialIndex: selectedIndex.value, child: Column( children: [ MyTabBar(), SizedBox( height: 0.57.sh, child: TabBarView( children: [ ActiveCallsTab(productsController .selectedIndex.value == 0 ? productsController .swingTradeModel : productsController .selectedIndex .value == 1 ? productsController .multibaggerModel : productsController .optionModel), ExitedCallsTab(productsController .selectedIndex.value == 0 ? productsController .swingTradeModel : productsController .selectedIndex .value == 1 ? productsController .multibaggerModel : productsController .optionModel), ], ), ), ], ), ), sizedBoxHeight(20.h), ])) ]) ], ), ), bottomNavigationBar: bottomnavigationbar(mainController), ), ); } Future _onBackButtonPressed(BuildContext context) async { bool? exitApp = await showDialog( context: context, builder: (context) { return AlertDialog( backgroundColor: const Color(0xFFFFF3E4), title: const Text('Exit App'), content: const Text('Do you really want to close the app?'), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(false); }, child: const Text( 'No', style: TextStyle( color: Color(0xff1B243D), ), ), ), TextButton( onPressed: () { SystemNavigator.pop(); Navigator.pop(context); }, child: const Text( 'Yes', style: TextStyle( color: Color(0xff1B243D), ), ), ) ], ); }); return exitApp ?? false; } Widget ActiveCallsTab(CallRecommendationsModel callRecommendationsModel) { return callRecommendationsModel.data!.activeCalls!.isEmpty ? Center( child: Column( children: [ const Gap(200), text22W600("No Data Available !"), ], )) : ListView.builder( itemCount: callRecommendationsModel.data!.activeCalls!.length, itemBuilder: (ctx, index) { return Padding( padding: EdgeInsets.only(top: 20.h, bottom: 5.h), child: productsController.selectedIndex.value == 0 ? cardSwingWidget( instrumentName: callRecommendationsModel .data!.activeCalls![index].instrumentKey!, pdfLink: "", image: callRecommendationsModel .data!.activeCalls![index].stockImage!, text: callRecommendationsModel .data!.activeCalls![index].stockName!, amount: '₹ 196.50 - ₹ 197', targetamount: '₹ ${callRecommendationsModel.data!.activeCalls![index].targetPrice}', stoploss: '₹ ${callRecommendationsModel.data!.activeCalls![index].stopLoss}', time: '${callRecommendationsModel.data!.activeCalls![index].duration}', action: callRecommendationsModel .data!.activeCalls![index].actionData!.name!, ) : productsController.selectedIndex.value == 1 ? cardMultibaggerWidget( instrumentName: callRecommendationsModel .data!.activeCalls![index].instrumentKey!, image: callRecommendationsModel .data!.activeCalls![index].stockImage!, action: callRecommendationsModel .data!.activeCalls![index].actionData!.name!, text: callRecommendationsModel .data!.activeCalls![index].stockName!, price: "₹ ${callRecommendationsModel.data!.activeCalls![index].buyPrice}", date: callRecommendationsModel .data!.activeCalls![index].createdAt!, returns: "₹ ${callRecommendationsModel.data!.activeCalls![index].targetPrice}", stoploss: "₹ ${callRecommendationsModel.data!.activeCalls![index].stopLoss}", duration: callRecommendationsModel .data!.activeCalls![index].duration!, pdfname: "Download Pdf", pdfLink: callRecommendationsModel .data!.activeCalls![index].docs!, ) : cardOptionWidget( instrumentName: callRecommendationsModel .data!.activeCalls![index].instrumentKey!, pdfLink: "", image: callRecommendationsModel .data!.activeCalls![index].stockImage!, action: callRecommendationsModel .data!.activeCalls![index].actionData!.name!, text: callRecommendationsModel .data!.activeCalls![index].stockName!, optiontype: callRecommendationsModel.data! .activeCalls![index].optionTypeData!.name!, price: "₹ ${callRecommendationsModel.data!.activeCalls![index].buyPrice}", date: callRecommendationsModel .data!.activeCalls![index].createdAt!, premium: "₹ ${callRecommendationsModel.data!.activeCalls![index].currentPrice}", price1: "₹ ${callRecommendationsModel.data!.activeCalls![index].targetPrice}", stoploss: "₹ ${callRecommendationsModel.data!.activeCalls![index].stopLoss}", ), ); }); } void _unlockbottomsheet() { Get.bottomSheet( commonGlassContainer( width: double.infinity, height: 439.h, borderradius: 4, customWidget: Center( child: Padding( padding: EdgeInsets.symmetric(horizontal: 35.w), child: Column( children: [ sizedBoxHeight(50.h), // Image.asset( // 'assets/images/png/Group 1000003722.png', // height: 100.h, // ), // sizedBoxHeight(25.h), text20W400('Please subscribed to unlock'), sizedBoxHeight(30.h), CommonBtn( text: 'Subscribe Now', onTap: () {}, ), const SizedBox( height: 100, ) ], ), ), ), ), backgroundColor: Colors.black.withOpacity(0.3), ); } Widget ExitedCallsTab(CallRecommendationsModel callRecommendationsModel) { return callRecommendationsModel.data!.exitedCalls!.isEmpty ? Center( child: Column( children: [ const Gap(200), text22W600("No Data Available !"), ], )) : ListView.builder( itemCount: callRecommendationsModel.data!.exitedCalls!.length, itemBuilder: (ctx, index) { return Padding( padding: EdgeInsets.only(top: 20.h, bottom: 5.h), child: productsController.selectedIndex.value == 0 ? cardSwingWidget( instrumentName: callRecommendationsModel .data!.exitedCalls![index].instrumentKey!, pdfLink: callRecommendationsModel .data!.exitedCalls![index].docs!, image: callRecommendationsModel .data!.exitedCalls![index].stockImage!, text: callRecommendationsModel .data!.exitedCalls![index].stockName!, amount: '₹ 196.50 - ₹ 197', targetamount: '₹ ${callRecommendationsModel.data!.exitedCalls![index].targetPrice}', stoploss: '₹ ${callRecommendationsModel.data!.exitedCalls![index].stopLoss}', time: '${callRecommendationsModel.data!.exitedCalls![index].duration}', action: callRecommendationsModel .data!.exitedCalls![index].actionData!.name!, ) : productsController.selectedIndex.value == 1 ? cardMultibaggerWidget( instrumentName: callRecommendationsModel .data!.exitedCalls![index].instrumentKey!, image: callRecommendationsModel .data!.exitedCalls![index].stockImage!, action: callRecommendationsModel .data!.exitedCalls![index].actionData!.name!, text: callRecommendationsModel .data!.exitedCalls![index].stockName!, price: "₹ ${callRecommendationsModel.data!.exitedCalls![index].buyPrice}", date: callRecommendationsModel .data!.exitedCalls![index].createdAt!, returns: "₹ ${callRecommendationsModel.data!.exitedCalls![index].targetPrice}", stoploss: "₹ ${callRecommendationsModel.data!.exitedCalls![index].stopLoss}", duration: callRecommendationsModel .data!.exitedCalls![index].duration!, pdfname: "Download Pdf", pdfLink: callRecommendationsModel .data!.exitedCalls![index].docs!, ) : cardOptionWidget( instrumentName: callRecommendationsModel .data!.exitedCalls![index].instrumentKey!, pdfLink: callRecommendationsModel .data!.exitedCalls![index].docs!, image: callRecommendationsModel .data!.exitedCalls![index].stockImage!, action: callRecommendationsModel .data!.exitedCalls![index].actionData!.name!, text: callRecommendationsModel .data!.exitedCalls![index].stockName!, optiontype: callRecommendationsModel.data! .exitedCalls![index].optionTypeData!.name!, price: "₹ ${callRecommendationsModel.data!.exitedCalls![index].buyPrice}", date: callRecommendationsModel .data!.exitedCalls![index].createdAt!, premium: "₹ ${callRecommendationsModel.data!.exitedCalls![index].currentPrice}", price1: "₹ ${callRecommendationsModel.data!.exitedCalls![index].targetPrice}", stoploss: "₹ ${callRecommendationsModel.data!.exitedCalls![index].stopLoss}", ), ); }); } Widget cardOptionWidget({ required String text, required String optiontype, required String price, required String date, required String premium, required String price1, required String stoploss, required String action, required String pdfLink, required String image, required String instrumentName, }) { ContactUsController contactUsController = Get.put(ContactUsController()); return InkWell( onTap: () { Get.to(const StockDetailsScreen(), arguments: { "instrument_name": instrumentName, }); }, child: Container( padding: const EdgeInsets.all(15), width: 398, height: 300, decoration: ShapeDecoration( color: const Color(0x232C79ED), shape: RoundedRectangleBorder( side: const BorderSide(width: 1, color: Color(0x994A73FB)), borderRadius: BorderRadius.circular(8), ), ), child: Stack( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ CachedNetworkImage( imageUrl: image, width: 78.29, height: 31, ), const Gap(10), text16W700(text), const Spacer(), Container( width: 62.w, height: 25.h, decoration: BoxDecoration( borderRadius: BorderRadius.circular(15.r), color: action == "Buy" ? const Color(0xFF00FF19) : action == "Exit" ? const Color(0Xff6C0000) : const Color(0xFFFFCE00), ), child: Center( child: text14W600_1B1B1B( action, clr: action == "Exit" ? Colors.white : const Color(0Xff1B1B1B), )), ), const Gap(15), ], ), const Gap(30), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(optiontype), sizedBoxHeight(5.h), text12W400_979797('Option Type'), ], ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(price), sizedBoxHeight(5.h), text12W400_979797('Strike Price'), ], ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600( contactUsController.formatedDateMethod(date)), sizedBoxHeight(5.h), text12W400_979797('Expiry Date'), ], ), ], ), const Gap(25), Row( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(price1), sizedBoxHeight(5.h), text12W400_979797('Target Price'), ], ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(stoploss), sizedBoxHeight(5.h), text12W400_979797('Stop Loss'), ], ), ], ), const Gap(30), Container( width: 398, height: 52, decoration: const ShapeDecoration( color: Color(0x332C79ED), shape: RoundedRectangleBorder( side: BorderSide(width: 1, color: Color(0x994A73FB)), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ text15W600(premium), const Gap(5), text14W400_979797('/ Premium'), ], ), ) ], ), Positioned( right: 0, child: SvgPicture.asset("assets/images/svg/card_decoration.svg")) ], ), ), ); } Widget cardMultibaggerWidget({ required String text, required String price, required String date, required String returns, required String stoploss, required String duration, required String pdfname, required String action, required String pdfLink, required String image, required String instrumentName, }) { ContactUsController contactUsController = Get.put(ContactUsController()); return InkWell( onTap: () { Get.to(const StockDetailsScreen(), arguments: { "instrument_name": instrumentName, }); }, child: Container( padding: const EdgeInsets.all(15), width: 398, height: 300, decoration: ShapeDecoration( color: const Color(0x232C79ED), shape: RoundedRectangleBorder( side: const BorderSide(width: 1, color: Color(0x994A73FB)), borderRadius: BorderRadius.circular(8), ), ), child: Stack( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ CachedNetworkImage( imageUrl: image, width: 78.29, height: 31, ), const Gap(10), text16W700(text), const Spacer(), Container( width: 62.w, height: 25.h, decoration: BoxDecoration( borderRadius: BorderRadius.circular(15.r), color: action == "Buy" ? const Color(0xFF00FF19) : action == "Exit" ? const Color(0Xff6C0000) : const Color(0xFFFFCE00), ), child: Center( child: text14W600_1B1B1B( action, clr: action == "Exit" ? Colors.white : const Color(0Xff1B1B1B), )), ), const Gap(15), ], ), const Gap(30), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(price), sizedBoxHeight(5.h), text12W400_979797('Entry Price'), ], ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600( contactUsController.formatedDateMethod(date)), sizedBoxHeight(5.h), text12W400_979797('Date Of Recommendation'), ], ), ], ), const Gap(25), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(returns), sizedBoxHeight(5.h), text12W400_979797('Target Price'), ], ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(stoploss), sizedBoxHeight(5.h), text12W400_979797('Stop Loss'), ], ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(duration), sizedBoxHeight(5.h), text12W400_979797('Duration'), ], ), ], ), const Gap(30), GestureDetector( onTap: () { Utils.openFile( url: pdfLink, fileName: "${text}_report.pdf"); }, child: Container( width: 398, height: 52, decoration: const ShapeDecoration( color: Color(0x332C79ED), shape: RoundedRectangleBorder( side: BorderSide(width: 1, color: Color(0x994A73FB)), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Image.asset( 'assets/images/png/pdf.png', height: 20.h, width: 20.w, ), Gap(8), text15W600("Download Pdf"), ], ), ), ) ], ), Positioned( right: 0, child: SvgPicture.asset("assets/images/svg/card_decoration.svg")) ], ), ), ); } Widget cardSwingWidget({ required String image, required String text, required String amount, required String targetamount, required String stoploss, required String time, required String pdfLink, required String action, required String instrumentName, }) { return InkWell( onTap: () { Get.to(const StockDetailsScreen(), arguments: { "instrument_name": instrumentName, }); }, child: Container( padding: const EdgeInsets.all(15), width: 398, height: 285, decoration: ShapeDecoration( color: const Color(0x232C79ED), shape: RoundedRectangleBorder( side: const BorderSide(width: 1, color: Color(0x994A73FB)), borderRadius: BorderRadius.circular(8), ), ), child: Stack( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ CachedNetworkImage( imageUrl: image, width: 78.29, height: 31, ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), text16W700(text), const Spacer(), Container( width: 62.w, height: 25.h, decoration: BoxDecoration( borderRadius: BorderRadius.circular(15.r), color: action == "Buy" ? const Color(0xFF00FF19) : action == "Exit" ? const Color(0Xff6C0000) : const Color(0xFFFFCE00), ), child: Center( child: text14W600_1B1B1B( action, clr: action == "Exit" ? Colors.white : const Color(0Xff1B1B1B), )), ), const Gap(15), ], ), const Gap(30), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(amount), sizedBoxHeight(5.h), text12W400_979797('Entry Price'), ], ), const Gap(10), Container( width: 2, height: 35, color: Colors.white.withOpacity(0.30000001192092896), ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(targetamount), sizedBoxHeight(5.h), text12W400_979797('Target Price'), ], ), // const Gap(10), // Container( // width: 2, // height: 35, // color: Colors.white.withOpacity(0.30000001192092896), // ), // const Gap(10), ], ), const Gap(10), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ text15W600(stoploss), sizedBoxHeight(5.h), text12W400_979797('Stop Loss'), ], ), const Gap(30), Container( width: 398, height: 52, decoration: const ShapeDecoration( color: Color(0x332C79ED), shape: RoundedRectangleBorder( side: BorderSide(width: 1, color: Color(0x994A73FB)), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ text15W600(time), const Gap(5), text14W400_979797('/ Time Horizon'), ], ), ) ], ), Positioned( right: 0, child: SvgPicture.asset("assets/images/svg/card_decoration.svg")) ], ), ), ); } Widget topContainer(String text, int index) { return Obx(() { return productsController.selectedIndex.value == index ? Container( height: 40.h, width: 126.w, decoration: BoxDecoration( borderRadius: BorderRadius.circular(5), color: const Color(0Xff0093FF), ), child: Center(child: text16W500(text)), ) : commonGlassContainer( width: 126.w, height: 40.h, borderradius: 5, customWidget: Center(child: text16W400(text)), ); }); } }