diff --git a/lib/application/component/subscribe/input_investment_view.dart b/lib/application/component/subscribe/input_investment_view.dart index 1dd8a22..ad553bb 100644 --- a/lib/application/component/subscribe/input_investment_view.dart +++ b/lib/application/component/subscribe/input_investment_view.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:cims_apps/application/component/button/button_view.dart'; import 'package:cims_apps/application/component/numeric_pad/numeric_pad.dart'; import 'package:cims_apps/application/theme/color_palette.dart'; @@ -6,9 +8,13 @@ import 'package:cims_apps/core/utils/size_config.dart'; import 'package:flutter/material.dart'; class InputInvestmentView extends StatefulWidget { - final String selectedPlan; + final String? currentPlan; + final void Function()? changePlan; + final int? currentPrice; + final int? minimumPrice; + final int? maximumPrice; final void Function(String value) nextMove; - const InputInvestmentView({super.key, required this.selectedPlan, required this.nextMove}); + const InputInvestmentView({super.key, required this.nextMove, this.currentPlan, this.minimumPrice, this.maximumPrice, this.currentPrice, this.changePlan}); @override State createState() => _InputInvestmentViewState(); @@ -17,10 +23,35 @@ class InputInvestmentView extends StatefulWidget { class _InputInvestmentViewState extends State { TextEditingController inputController = TextEditingController(); + void validationInputValue(String currentValue) { + currentValue = currentValue.replaceAll('Rp ', '').replaceAll('.', ''); + if(currentValue.isEmpty){ + currentValue = '0'; + } + double parseValue = double.parse(currentValue); + if(widget.minimumPrice != null){ + if(parseValue <= widget.minimumPrice!){ + parseValue = widget.minimumPrice!.toDouble(); + } + } + + if(widget.maximumPrice != null){ + if(parseValue >= widget.maximumPrice!){ + parseValue = widget.maximumPrice!.toDouble(); + } + } + + inputController.text = NumberFormatter.numberCurrency(parseValue, 'Rp ', 'id_ID', decimalDigits: 0); + } + @override void initState() { // TODO: implement initState - inputController.text = 'Rp 0'; + if(widget.currentPrice != null){ + inputController.text = NumberFormatter.numberCurrency(widget.currentPrice, 'Rp ', 'id_ID', decimalDigits: 0); + }else{ + inputController.text = 'Rp 0'; + } super.initState(); } @@ -41,55 +72,53 @@ class _InputInvestmentViewState extends State { child: Column( mainAxisSize: MainAxisSize.min, children: [ - SizedBox(height: 16), Padding( - padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12), + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(widget.selectedPlan, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w700, + if(widget.currentPlan != null) + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(widget.currentPlan ?? '', + style: const TextStyle( + fontSize: 20, + fontWeight: FontWeight.w700, + ), ), - ), - Row( - children: [ - Icon(Icons.change_circle_outlined, color: ColorPalette.primary, size: 20), - SizedBox(width: 4), - Text('Change', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: ColorPalette.primary - ), - ) - ], - ) - ], - ), + InkWell( + borderRadius: BorderRadius.circular(16), + onTap: widget.changePlan, + child: const Row( + children: [ + Icon(Icons.change_circle_outlined, color: ColorPalette.primary, size: 20), + SizedBox(width: 4), + Text('Change', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: ColorPalette.primary + ), + ) + ], + ), + ) + ], + ), TextField( controller: inputController, textAlign: TextAlign.center, - style: TextStyle( + style: const TextStyle( fontSize: 28, fontWeight: FontWeight.w600, color: ColorPalette.slate800 ), keyboardType: TextInputType.number, onChanged: (value) { - value = value.replaceAll('Rp ', '').replaceAll('.', ''); - double parseValue = double.parse(value); - if(value.isNotEmpty){ - inputController.text = NumberFormatter.numberCurrency(parseValue, 'Rp ', 'id_ID', decimalDigits: 0); - }else{ - inputController.text = NumberFormatter.numberCurrency(0, 'Rp ', 'id_ID', decimalDigits: 0); - } + validationInputValue(value); }, - decoration: InputDecoration( + decoration: const InputDecoration( enabledBorder: UnderlineInputBorder( borderSide: BorderSide( color: ColorPalette.primary, @@ -98,30 +127,36 @@ class _InputInvestmentViewState extends State { ) ), ), - SizedBox(height: 12), - Text('Minimum Budget Rp1,000,000', - style: TextStyle( - color: ColorPalette.slate400, - fontSize: 16, - fontWeight: FontWeight.w600 + const SizedBox(height: 12), + if(widget.minimumPrice != null) + Text('Minimum ${NumberFormatter.numberCurrency(widget.minimumPrice, 'Rp ', 'id_ID')}', + style: const TextStyle( + color: ColorPalette.slate400, + fontSize: 16, + fontWeight: FontWeight.w600 + ), ), - ), - SizedBox(height: 16), + if(widget.maximumPrice != null) + Text('Maximum ${NumberFormatter.numberCurrency(widget.maximumPrice, 'Rp ', 'id_ID')}', + style: const TextStyle( + color: ColorPalette.slate400, + fontSize: 16, + fontWeight: FontWeight.w600 + ), + ), + const SizedBox(height: 16), NumericPad(onNumberSelected: (p0) { - String checkIsZeroInput = inputController.text.replaceAll('Rp ', '').replaceAll(',', ''); - String getNumeric = p0; + String currentValue = inputController.text; if(p0.isNotEmpty){ - if(checkIsZeroInput != '0'){ - getNumeric = checkIsZeroInput + getNumeric; + if(currentValue != '0'){ + currentValue = currentValue + p0; } }else{ - getNumeric = checkIsZeroInput.substring(0, checkIsZeroInput.length - 1); + currentValue = currentValue.substring(0, currentValue.length - 1); } - String formatNumeric = NumberFormatter.numberCurrency( - double.parse(getNumeric), 'Rp ', 'id_ID', decimalDigits: 0).replaceAll('.', ','); - inputController.text = formatNumeric; + validationInputValue(currentValue); }), - SizedBox(height: 8), + const SizedBox(height: 24), ButtonView( name: 'Next', onPressed: () { @@ -129,7 +164,7 @@ class _InputInvestmentViewState extends State { }, width: SizeConfig.width, heightWrapContent: true, - contentPadding: EdgeInsets.symmetric(vertical: 16), + contentPadding: const EdgeInsets.symmetric(vertical: 16), marginVertical: 0, ) ], @@ -137,6 +172,6 @@ class _InputInvestmentViewState extends State { ), ], ), - );; + ); } } diff --git a/lib/features/dashboard/dashboard_account/view/plan/view/plan_view.dart b/lib/features/dashboard/dashboard_account/view/plan/view/plan_view.dart index 1ed5d1a..149ffbd 100644 --- a/lib/features/dashboard/dashboard_account/view/plan/view/plan_view.dart +++ b/lib/features/dashboard/dashboard_account/view/plan/view/plan_view.dart @@ -115,10 +115,13 @@ class _PlanViewState extends State { ), const Divider(color: ColorPalette.slate200, height: 1), InputInvestmentView( - selectedPlan: text, + currentPlan: text, + changePlan: () { + Navigator.pop(context); + }, nextMove: (value) { Navigator.pop(context); - int formatIntParse = int.parse(value.replaceAll('Rp ', '').replaceAll(',', '')); + int formatIntParse = int.parse(value.replaceAll('Rp ', '').replaceAll('.', '')); showModalBottomSheet(context: context, builder: (context) => OptionsStartingInvest(totalInvest: formatIntParse)); }, ), diff --git a/lib/features/dashboard/dashboard_account/view/portfolio/redeem_product/view/change_amount.dart b/lib/features/dashboard/dashboard_account/view/portfolio/redeem_product/view/change_amount.dart index e5d5a0a..13431c9 100644 --- a/lib/features/dashboard/dashboard_account/view/portfolio/redeem_product/view/change_amount.dart +++ b/lib/features/dashboard/dashboard_account/view/portfolio/redeem_product/view/change_amount.dart @@ -4,6 +4,7 @@ import 'package:cims_apps/application/assets/path_assets.dart'; import 'package:cims_apps/application/component/button/button_view.dart'; import 'package:cims_apps/application/component/image/image_view.dart'; import 'package:cims_apps/application/component/numeric_pad/numeric_pad.dart'; +import 'package:cims_apps/application/component/subscribe/input_investment_view.dart'; import 'package:cims_apps/application/component/text_title/text_title.dart'; import 'package:cims_apps/application/theme/color_palette.dart'; import 'package:cims_apps/core/utils/number_formatter.dart'; @@ -82,98 +83,33 @@ class _ChangeAmountState extends State { ), ), const Divider(height: 1, color: ColorPalette.slate200,), - Padding( - padding: EdgeInsets.all(24), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - cardProduct(), - SizedBox(height: 24), - TextField( - controller: amountController, - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 28, - fontWeight: FontWeight.w600, - color: ColorPalette.slate800 - ), - keyboardType: TextInputType.number, - onChanged: (value) { - value = value.replaceAll('Rp ', '').replaceAll('.', ''); - double parseValue = double.parse(value); - if(value.isNotEmpty){ - amountController.text = NumberFormatter.numberCurrency(parseValue, 'Rp ', 'id_ID', decimalDigits: 0); - }else{ - amountController.text = NumberFormatter.numberCurrency(0, 'Rp ', 'id_ID', decimalDigits: 0); - } - }, - decoration: const InputDecoration( - enabledBorder: UnderlineInputBorder( - borderSide: BorderSide( - color: ColorPalette.primary, - width: 2 - ), - ) - ), - ), - SizedBox(height: 12), - Text( - 'Min Redeem: ${(NumberFormatter.numberCurrency(10000, 'Rp ', 'id_ID', decimalDigits: 0))}', - style: TextStyle( - color: ColorPalette.slate400, - fontWeight: FontWeight.w600, - ), - ), - Text( - 'Max Redeem: ${(NumberFormatter.numberCurrency((provider.getCurrentProduct.priceUnit! * provider.getCurrentProduct.totalUnit!).toInt(), 'Rp ', 'id_ID', decimalDigits: 0))}', - style: TextStyle( - color: ColorPalette.slate400, - fontWeight: FontWeight.w600, - ), - ), - const SizedBox(height: 24), - NumericPad(onNumberSelected: (p0) { - String checkIsZeroInput = amountController.text.replaceAll('Rp ', '').replaceAll('.', ''); - String getNumeric = p0; - - if(p0.isNotEmpty){ - if(checkIsZeroInput != '0'){ - getNumeric = checkIsZeroInput + getNumeric; - } - }else{ - getNumeric = checkIsZeroInput.substring(0, checkIsZeroInput.length - 1); - } - if(getNumeric.isEmpty){ - getNumeric = '0'; - } - if(double.parse(getNumeric) >= provider.getCurrentProduct.priceUnit! * provider.getCurrentProduct.totalUnit!){ - getNumeric = (provider.getCurrentProduct.priceUnit! * provider.getCurrentProduct.totalUnit!).toString(); - } - String formatNumeric = NumberFormatter.numberCurrency( - double.parse(getNumeric).toInt(), 'Rp ', 'id_ID', decimalDigits: 0); - amountController.text = formatNumeric; - }), - const SizedBox(height: 24), - ButtonView( - name: 'Confirm', - textSize: 20, - marginVertical: 0, - onPressed: () { - String formatValueInput = amountController.text.replaceAll('Rp ', '').replaceAll('.', ''); - provider.setAmount(double.parse(formatValueInput)); - Navigator.pop(context); - showModalBottomSheet( - context: context, - isScrollControlled: true, - builder: (context) { - return const RedeemProduct(); - }, - ); - }, - ) - ], - ), - ) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: EdgeInsets.all(24), + child: cardProduct() + ), + InputInvestmentView( + minimumPrice: (provider.getCurrentProduct.priceUnit! * 1).toInt(), + maximumPrice: (provider.getCurrentProduct.priceUnit! * provider.getCurrentProduct.totalUnit!).toInt(), + currentPrice: provider.getAmount!.toInt(), + nextMove: (value) { + String formatValueInput = value.replaceAll('Rp ', '').replaceAll('.', ''); + provider.setAmount(double.parse(formatValueInput)); + Navigator.pop(context); + showModalBottomSheet( + context: context, + isScrollControlled: true, + builder: (context) { + return const RedeemProduct(); + }, + ); + }, + ) + ], + ), + SizedBox(height: 16,) ], ); } diff --git a/lib/features/dashboard/dashboard_account/view/product/view/step_subscribe/select_goal_investing.dart b/lib/features/dashboard/dashboard_account/view/product/view/step_subscribe/select_goal_investing.dart index f21532f..ab5cbe0 100644 --- a/lib/features/dashboard/dashboard_account/view/product/view/step_subscribe/select_goal_investing.dart +++ b/lib/features/dashboard/dashboard_account/view/product/view/step_subscribe/select_goal_investing.dart @@ -55,32 +55,43 @@ class SelectGoalInvesting extends StatelessWidget { create: (context) => ProductViewModel(), child: Consumer( builder: (context, provider, child) { - return InputInvestmentView( - selectedPlan: p0, - nextMove: (value) { - Navigator.pop(context); - int formatIntParse = int.parse(value.replaceAll('Rp ', '').replaceAll(',', '')); - showModalBottomSheet( - context: context, - isScrollControlled: true, - builder: (context) => - ChangeNotifierProvider( - create: (context) => ProductViewModel(), - child: Consumer( - builder: (context, provider, child) { - return TotalPaymentView( - listProduct: [ - provider.getSelectedProduct - ], - totalInvest: formatIntParse, - isAgree: provider.isAgree, - onTapAgree: provider.setAgree, - ); - } - ), - ) - ); - }, + return Padding( + padding: EdgeInsets.symmetric(vertical: 16), + child: InputInvestmentView( + currentPlan: p0, + changePlan: () { + Navigator.pop(context); + showModalBottomSheet( + context: context, + isScrollControlled: true, + builder: (context) => SelectGoalInvesting(), + ); + }, + nextMove: (value) { + Navigator.pop(context); + int formatIntParse = int.parse(value.replaceAll('Rp ', '').replaceAll('.', '')); + showModalBottomSheet( + context: context, + isScrollControlled: true, + builder: (context) => + ChangeNotifierProvider( + create: (context) => ProductViewModel(), + child: Consumer( + builder: (context, provider, child) { + return TotalPaymentView( + listProduct: [ + provider.getSelectedProduct + ], + totalInvest: formatIntParse, + isAgree: provider.isAgree, + onTapAgree: provider.setAgree, + ); + } + ), + ) + ); + }, + ), ); } ),