221 lines
8.7 KiB
Dart
221 lines
8.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
|
|
import 'package:async/async.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.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 PastPerformance extends StatefulWidget {
|
|
const PastPerformance({super.key});
|
|
|
|
@override
|
|
State<PastPerformance> createState() => _PastPerformanceState();
|
|
}
|
|
|
|
class _PastPerformanceState extends State<PastPerformance> {
|
|
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();
|
|
|
|
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: Container(child: 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,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
body: Stack(
|
|
children: [
|
|
const CommonBlurLeft(),
|
|
const CommonBlurRight(),
|
|
Stack(
|
|
children: [
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
children: [
|
|
text25W600("Past Performances"),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 10.h,
|
|
),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
'How we proved possibles!',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontFamily: 'hiragino',
|
|
color: Colors.white,
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w400,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
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(),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
bottomNavigationBar: bottomnavigationbar(mainController),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<bool> _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;
|
|
}
|
|
}
|