import 'package:edge_alert/edge_alert.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:job_app/config/palette.dart'; import 'package:job_app/models/APiResponse.dart'; import 'package:job_app/models/CV.dart'; import 'package:job_app/models/CvModel.dart'; import 'package:job_app/models/fonts.dart'; import 'package:job_app/services/cv/addCvToUser.dart'; import 'package:job_app/services/cv/get_all_cv_models.dart'; import 'package:job_app/services/cv/submit%20cv/submit_cv.dart'; import 'package:job_app/singletons/user_info.dart'; import 'package:job_app/widgets/loading_screen.dart'; import 'package:webview_flutter/webview_flutter.dart'; import 'package:fluttertoast/fluttertoast.dart'; class Apply extends StatefulWidget { final CvModel cv; final List cvModels; final FontsModel font; final offerId; Apply({Key key,this.cvModels,this.cv,this.font,this.offerId}) : super(key: key); @override _ApplyState createState() => _ApplyState(); } class _ApplyState extends State { List cvModels = []; CvModel cv; FontsModel font; WebViewController _controller; bool isLoading = false; bool isApply = true; bool isBuy = false; int modelToBuyId ; CvModelModel modelToBuy ; int offerId; @override Widget build(BuildContext context) { cvModels = widget.cvModels; cv= widget.cv; font=widget.font; offerId=widget.offerId; return Scaffold( backgroundColor: Palette.backgroundColor, body: Stack( children: [ Padding( padding: const EdgeInsets.fromLTRB(20, 20, 20, 20), child: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Column(children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ IconButton( onPressed: () { Navigator.pop(context); }, icon: SvgPicture.asset( "assets/icons/arrow_left.svg", height: 20, color: Colors.black, )), Text( "Select your CV", style: TextStyle(fontFamily: 'Montserrat', fontSize: 20), ), Container( height: 27, width: 70, decoration: BoxDecoration( color: Palette.primary, borderRadius: BorderRadius.circular(4) ), padding: EdgeInsets.symmetric(horizontal: 2), child: TextButton( style: ButtonStyle( overlayColor: MaterialStateProperty .resolveWith((states) => Colors.transparent)),onPressed: (){ Navigator.pushNamed(context, '/build_cv_general',arguments: { "firstName" :userInfo.user.firstName, "lastName":userInfo.user.lastName, "phoneNumber" :userInfo.user.phonenumber, "jobTitle" :userInfo.user.jobtitle }); }, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Icon(Icons.add,color: Colors.white,size: 10,), Text("Add CV",style: TextStyle( color: Colors.white, fontSize: 9, fontFamily: 'MontserratMedium' ),), ], )), ), ], ), SizedBox( height: 50, ), Row( children: [ Container( width: 62, height: 168, decoration: BoxDecoration( color: Palette.secendary, borderRadius: BorderRadius.circular(11)), child: IconButton( onPressed: () async { setState(() { isLoading = true; }); GetAllCvModels getAllCvModels = GetAllCvModels(); ApiResponseModel responseModels = await getAllCvModels.getAllModels(); setState(() { isLoading = false; }); if (responseModels.statusCode == 200 || responseModels.statusCode == 201) { Navigator.pushNamed(context, '/add_model', arguments: { 'userCvModels': cvModels, 'allCvModels': responseModels.data, }).then((value) { if(value!=null){ modelToBuy = value; bool isOwned =cvModels.where( (element) => element.id == modelToBuy.id).isNotEmpty; if(isOwned){ setState(() { isBuy=false; isApply=true; }); }else{ setState(() { isBuy=true; isApply=false; modelToBuyId=modelToBuy.id; }); } String url = "https://server.thejob.net${modelToBuy.file.url}"; _controller.loadUrl(url); } }); } }, icon: Icon(Icons.add), highlightColor: Palette.backgroundColor, color: Colors.white, )), Container( height: 166, width: 290.7, child: ListView.builder( scrollDirection: Axis.horizontal, physics: BouncingScrollPhysics(), shrinkWrap: true, itemCount: cvModels.length, itemBuilder: (context, index) => Padding( padding: const EdgeInsets.only(left: 18.0), child: Container( width: 120, height: 168, child: Image( fit: BoxFit.fitHeight, image: NetworkImage( "https://server.thejob.net" + cvModels[index].file.preview.url, )), ), ), ), ), ], ), SizedBox( height: 30, ), Container( width: double.maxFinite, height: 452, child: WebView( initialUrl: "", onPageFinished: (String url) { _controller.evaluateJavascript( 'document.getElementById("IMAGE").src = "https://server.thejob.net${userInfo.user.image}"'); _controller.evaluateJavascript( 'document.getElementById("CITY").innerHTML = "${userInfo.user.city}"'); _controller.evaluateJavascript( 'document.getElementById("COUNTRY").innerHTML = "${userInfo.user.country}"'); _controller.evaluateJavascript( 'document.getElementById("EMAIL").innerHTML = "${userInfo.user.email}"'); _controller.evaluateJavascript( 'document.getElementById("PHONENUMBER").innerHTML = "${userInfo.user.phonenumber}"'); _controller.evaluateJavascript( 'document.getElementById("SIDEBAR").style.backgroundColor = "${cv.color}" ; '); _controller.evaluateJavascript( 'document.getElementById("INTRO").innerHTML = "${cv.intro}"'); _controller.evaluateJavascript( 'document.getElementById("JOBTITLE").innerHTML = "${cv.usercv.jobtitle}"'); _controller.evaluateJavascript( 'document.getElementById("SKILL").innerHTML = "${cv.skill}"'); _controller.evaluateJavascript( 'document.getElementById("EXPERIENCES").innerHTML = "${cv.experiences}"'); _controller.evaluateJavascript( 'document.getElementById("LANGUAGE").innerHTML = "${cv.language}"'); _controller.evaluateJavascript( 'document.getElementById("FIRSTNAME").innerHTML = "${cv.usercv.firstName}"'); _controller.evaluateJavascript( 'document.getElementById("LASTNAME").innerHTML = "${cv.usercv.lastName}"'); String url = 'https://server.thejob.net${font.url}'; _controller.evaluateJavascript( "var newFont = new FontFace('theFont','url($url)',{});" "newFont.load().then(function (LoadedFace){document.fonts.add(LoadedFace);document.body.style.fontFamily='theFont,serif'});"); // _controller.evaluateJavascript( // "var newFont = new FontFace('theFont','url($fontUrl)',{});" // "newFont.load().then(function (LoadedFace){document.fonts.add(LoadedFace);document.body.style.fontFamily='theFont,serif'});"); }, onWebViewCreated: (WebViewController webViewController) { _controller = webViewController; _controller.loadUrl( "https://server.thejob.net${cvModels.first.file.url}"); //loadLocalHTML(); }, // gestureRecognizers: Set() // ..add(Factory( // () => VerticalDragGestureRecognizer(), // )), javascriptMode: JavascriptMode.unrestricted, ), ), SizedBox( height: 20, ), Row( children: [ Text( "Motivation Letter", style: TextStyle(fontFamily: 'Montserrat', fontSize: 20), ), ], ), SizedBox( height: 10, ), Container( width: double.maxFinite, decoration: BoxDecoration(border: Border.all(color: Colors.black)), child: Padding( padding: const EdgeInsets.all(8.0), child: Text( cv.motivationletter, style: TextStyle( fontFamily: 'MontserratRegular', fontSize: 18, height: 1.5), ), ), ), SizedBox( height: 30, ), if (isBuy) Container( width: 180, height: 40, decoration: BoxDecoration( color: Palette.primary, borderRadius: BorderRadius.circular(8)), child: TextButton( onPressed: () async { setState(() { isLoading=true; }); AddCvToUserService request = AddCvToUserService(); ApiResponseModel response = await request.buyCvModel(modelToBuyId); setState(() { isLoading=false; }); print("status"); print(response.statusCode); if(response.statusCode==200||response.statusCode==201){ setState(() { cvModels.insert(0, modelToBuy); modelToBuy=null; modelToBuyId=null; isBuy=false; isApply=true; }); }else{ print("error"); print(response.errorMessage); } }, child: Text( "Buy model", style: TextStyle( color: Colors.white, fontFamily: 'MontserratSemiBold'), )), ), if (isBuy) SizedBox( height: 15, ), Container( width: 180, height: 40, decoration: BoxDecoration( color: isApply ? Palette.primary : Colors.grey, borderRadius: BorderRadius.circular(8)), child: TextButton( onPressed: () async { SubmitCvService request = SubmitCvService(); ApiResponseModel response =await request.submit(offerId, cv.id, cvModels.first.id); if(response.statusCode==302){ EdgeAlert.show(context, title: response.data, gravity: EdgeAlert.BOTTOM, duration: EdgeAlert.LENGTH_LONG, backgroundColor: Palette.hintText, ); } }, child: Text( "Apply now", style: TextStyle( color: Colors.white, fontFamily: 'MontserratSemiBold'), )), ), ]), ), ), if (isLoading) LoadingScreen() ], )); } }