risk profile api
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:async/async.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import 'package:scgateway_flutter_plugin/scgateway_flutter_plugin.dart';
|
||||
import 'package:traderscircuit/Utils/Common/CommonBottomNavigation.dart';
|
||||
import 'package:traderscircuit/Utils/Common/commonBotton.dart';
|
||||
import 'package:traderscircuit/Utils/text.dart';
|
||||
import 'package:traderscircuit/view/MainScreen/MainScreen.dart';
|
||||
import 'package:traderscircuit/view/MainScreen/Portfolio/Holdings.dart';
|
||||
import 'package:traderscircuit/view/Sidemenu/Sidemenu.dart';
|
||||
import 'package:traderscircuit/view/onBoarding/splashScreen1.dart';
|
||||
|
||||
import '../../../model/SmallCaseModel/broker_account_model.dart';
|
||||
import '../../../view_model/SmallCaseApi/smallcase_api_methods.dart';
|
||||
|
||||
class Portfolio extends StatefulWidget {
|
||||
const Portfolio({super.key});
|
||||
|
||||
@@ -20,13 +29,238 @@ class _PortfolioState extends State<Portfolio> {
|
||||
GlobalKey<ScaffoldState> _scaffoldKey1 = GlobalKey<ScaffoldState>();
|
||||
List<String> containerTexts = ["Swing Trade", "Multibagger", "Options"];
|
||||
final selectedIndex = 0.obs;
|
||||
|
||||
FutureGroup fetchUserIdAndBrokerAccounts = FutureGroup();
|
||||
List<BrokerAccountModel> myBrokerAccounts = [];
|
||||
@override
|
||||
void initState() {
|
||||
// fetchUserIdAndBrokerAccounts.add(getUserId()); // TODO Need to add userid here
|
||||
fetchUserIdAndBrokerAccounts.add(fetchBrokerAccounts());
|
||||
fetchUserIdAndBrokerAccounts.close();
|
||||
// fetchUserIdAndBrokerAccounts.future.then((value) {
|
||||
// int userId = value[0];
|
||||
// List<BrokerAccountModel> brokerAccounts = value[1];
|
||||
// try {
|
||||
// myBrokerAccounts.addAll(brokerAccounts
|
||||
// .where((element) => element.userId == userId.toString()));
|
||||
// } catch (e) {}
|
||||
// debugPrint("myBrokerAccounts.length ${myBrokerAccounts.length}");
|
||||
// debugPrint("BrokerAccounts.length ${brokerAccounts.length}");
|
||||
// if (myBrokerAccounts.isEmpty) {
|
||||
// setState(() {
|
||||
// body = Center(
|
||||
// child: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// children: [
|
||||
// const Text("You need to add broker account"),
|
||||
// const Text("to fetch holdings"),
|
||||
// const SizedBox(height: 6),
|
||||
// OutlinedButton(
|
||||
// onPressed: () {
|
||||
// //Get.off(Broker());
|
||||
// Get.to(() => Broker());
|
||||
// },
|
||||
// child: const Text("Brokerage Account"),
|
||||
// )
|
||||
// ],
|
||||
// ));
|
||||
// });
|
||||
// } else {
|
||||
// setBodyToBrokers();
|
||||
// }
|
||||
// });
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
// void setBodyToBrokers() {
|
||||
// setState(() {
|
||||
// body = Padding(
|
||||
// padding: const EdgeInsets.only(top: 28, left: 28, right: 28),
|
||||
// child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
// const Text("Please select your broker account"),
|
||||
// const SizedBox(height: 8),
|
||||
// Expanded(
|
||||
// child: ListView.builder(
|
||||
// itemCount: myBrokerAccounts.length,
|
||||
// itemBuilder: (context, index) {
|
||||
// return OutlinedButton(
|
||||
// onPressed: () {
|
||||
// setState(() {
|
||||
// body = const Center(child: CircularProgressIndicator());
|
||||
// });
|
||||
// fetchHoldingsImportTxnId(
|
||||
// myBrokerAccounts.elementAt(index).authToken!)
|
||||
// .then((txnIdResponse) {
|
||||
// if (txnIdResponse.statusCode == 200) {
|
||||
// debugPrint('SESSION STARTED');
|
||||
// debugPrint(
|
||||
// 'AUTH TOKEN: ${myBrokerAccounts.elementAt(index).authToken!}');
|
||||
// fetchHoldingsImportTxnId(
|
||||
// myBrokerAccounts.elementAt(index).authToken!)
|
||||
// .then((txnRes) {
|
||||
// String txnId =
|
||||
// jsonDecode(txnRes.body)['data']['transactionId'];
|
||||
// debugPrint('TXN ID $txnId');
|
||||
// ScgatewayFlutterPlugin.triggerGatewayTransaction(
|
||||
// txnId)
|
||||
// .then(
|
||||
// (txnRes) {
|
||||
// debugPrint('TXN RES $txnRes');
|
||||
// if (txnRes != null) {
|
||||
// fetchHoldings(
|
||||
// //holdingsAuthToken
|
||||
// myBrokerAccounts
|
||||
// .elementAt(index)
|
||||
// .authToken!)
|
||||
// .then(
|
||||
// (holdings) {
|
||||
// setState(() {
|
||||
// // body = netWorthPage(holdings);
|
||||
// });
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
// });
|
||||
// } else {
|
||||
// debugPrint('SESSION EXPIRED');
|
||||
// onTxnTimeout();
|
||||
// }
|
||||
// });
|
||||
// },
|
||||
// child: Text(myBrokerAccounts.elementAt(index).brokerName!),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// ]),
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
|
||||
// void onTxnTimeout() {
|
||||
// bool showDialogContent = true;
|
||||
// bool replaceDialogContentWithLoader = false;
|
||||
// showDialog(
|
||||
// barrierDismissible: false,
|
||||
// context: context,
|
||||
// builder: (context) => AlertDialog(content: StatefulBuilder(
|
||||
// builder: (context, setDialogState) {
|
||||
// return Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// children: [
|
||||
// Visibility(
|
||||
// visible: showDialogContent,
|
||||
// child: Column(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// const Text("Transaction Timeout",
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.bold,
|
||||
// fontSize: 18,
|
||||
// )),
|
||||
// const SizedBox(height: 18),
|
||||
// const Text("You need to login again to continue"),
|
||||
// const SizedBox(height: 18),
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.end,
|
||||
// children: [
|
||||
// OutlinedButton(
|
||||
// onPressed: () {
|
||||
// setBodyToBrokers();
|
||||
// Get.back();
|
||||
// },
|
||||
// child: const Text("Cancel"),
|
||||
// ),
|
||||
// const SizedBox(width: 12),
|
||||
// ElevatedButton(
|
||||
// onPressed: () {
|
||||
// setDialogState(() {
|
||||
// showDialogContent = false;
|
||||
// replaceDialogContentWithLoader = true;
|
||||
// });
|
||||
// //login again
|
||||
// fetchAuthToken().then((fetchedAuthToken) {
|
||||
// debugPrint(
|
||||
// "fetchedAuthToken $fetchedAuthToken");
|
||||
// fetchBrokerConnectTxnId(
|
||||
// authToken: fetchedAuthToken)
|
||||
// .then(
|
||||
// (txnId) =>
|
||||
// ScgatewayFlutterPlugin.initGateway(
|
||||
// fetchedAuthToken)
|
||||
// .then(
|
||||
// (value) => ScgatewayFlutterPlugin
|
||||
// .triggerGatewayTransaction(
|
||||
// txnId,
|
||||
// ).then(
|
||||
// (loginRes) {
|
||||
// if (loginRes != null) {
|
||||
// var data =
|
||||
// jsonDecode(loginRes)['data'];
|
||||
// if (data != null) {
|
||||
// String authToken = jsonDecode(
|
||||
// data)['smallcaseAuthToken'];
|
||||
// String brokerName =
|
||||
// jsonDecode(data)['broker'];
|
||||
// String txnId = jsonDecode(
|
||||
// data)['transactionId'];
|
||||
// getUserId().then((userId) {
|
||||
// postBrokerAccount(
|
||||
// userId: userId!
|
||||
// .toString(),
|
||||
// brokerName:
|
||||
// brokerName,
|
||||
// authToken: authToken,
|
||||
// txnId: txnId)
|
||||
// .then((isPosted) {
|
||||
// if (isPosted) {
|
||||
// // Get.back();
|
||||
// // setBodyToBrokers();
|
||||
// Get.off(Holdings());
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// });
|
||||
// },
|
||||
// child: const Text("Login Again"),
|
||||
// ),
|
||||
// ],
|
||||
// )
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// Visibility(
|
||||
// visible: replaceDialogContentWithLoader,
|
||||
// child: const Padding(
|
||||
// padding: EdgeInsets.symmetric(vertical: 28.0),
|
||||
// child: Center(
|
||||
// child: CircularProgressIndicator(),
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// },
|
||||
// )));
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
key: _scaffoldKey1,
|
||||
backgroundColor: Colors.black,
|
||||
drawerEnableOpenDragGesture: false,
|
||||
drawer: Container(child: SideMenu()),
|
||||
drawer: Container(child: const SideMenu()),
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
scrolledUnderElevation: 0.0,
|
||||
@@ -49,12 +283,13 @@ class _PortfolioState extends State<Portfolio> {
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
CommonBlurLeft(),
|
||||
CommonBlurRight(),
|
||||
const CommonBlurLeft(),
|
||||
const CommonBlurRight(),
|
||||
Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
@@ -75,15 +310,73 @@ class _PortfolioState extends State<Portfolio> {
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
const Spacer(),
|
||||
LottieBuilder.asset(
|
||||
"assets/images/empty.json",
|
||||
width: 200.w,
|
||||
height: 200.h,
|
||||
),
|
||||
Spacer(),
|
||||
CommonBtn(text: "Add"),
|
||||
Spacer(),
|
||||
const Spacer(),
|
||||
CommonBtn(
|
||||
text: "Add",
|
||||
onTap: () {
|
||||
// replaceAddAccountBtnWithLoader();
|
||||
// Timer.periodic(Duration(seconds: 8), (timer) {
|
||||
// // replaceLoaderWithAddAccountBtn();
|
||||
// timer.cancel();
|
||||
// });
|
||||
fetchAuthToken().then((fetchedAuthToken) {
|
||||
debugPrint("fetchedAuthToken $fetchedAuthToken");
|
||||
fetchBrokerConnectTxnId(authToken: fetchedAuthToken)
|
||||
.then(
|
||||
(txnId) => ScgatewayFlutterPlugin.initGateway(
|
||||
fetchedAuthToken)
|
||||
.then(
|
||||
(value) => ScgatewayFlutterPlugin
|
||||
.triggerGatewayTransaction(
|
||||
txnId,
|
||||
).then(
|
||||
(loginRes) {
|
||||
if (loginRes != null) {
|
||||
var data = jsonDecode(loginRes)['data'];
|
||||
if (data != null) {
|
||||
String authToken = jsonDecode(
|
||||
data)['smallcaseAuthToken'];
|
||||
String brokerName =
|
||||
jsonDecode(data)['broker'];
|
||||
String txnId =
|
||||
jsonDecode(data)['transactionId'];
|
||||
// getUserId().then((userId) {
|
||||
postBrokerAccount(
|
||||
userId: "12",
|
||||
brokerName: brokerName,
|
||||
authToken: authToken,
|
||||
txnId: txnId)
|
||||
.then((isPosted) {
|
||||
// replaceLoaderWithAddAccountBtn();
|
||||
// Navigator.pushReplacement(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) =>
|
||||
// Broker()));
|
||||
ScaffoldMessenger.of(context)
|
||||
.clearSnackBars();
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(
|
||||
content: Text(
|
||||
'New broker account is added')));
|
||||
});
|
||||
// });
|
||||
// replaceLoaderWithAddAccountBtn();
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user