feat: expandable text component

This commit is contained in:
Prajna Prayoga 2024-02-22 18:13:54 +07:00
parent d966108e9e
commit 38837bd4f8
6 changed files with 233 additions and 61 deletions

View File

@ -0,0 +1,119 @@
import 'package:cims_apps/application/component/expandable_widget/see_more_less_widget.dart';
import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:cims_apps/core/utils/size_config.dart';
import 'package:flutter/material.dart';
class ExpandableWidget extends StatelessWidget {
final String? content;
final double? fontSize;
final int maxLinesToShow;
final Alignment? alignmentMore;
final bool? hideTextMore;
final bool? hideIconMore;
ExpandableWidget({
super.key,
required this.content,
this.fontSize,
this.maxLinesToShow = 1,
this.alignmentMore,
this.hideTextMore = false,
this.hideIconMore = true,
});
ValueNotifier<bool> expanded = ValueNotifier(false);
@override
Widget build(BuildContext context) {
final TextSpan textSpan = TextSpan(
text: content ?? "",
style: TextStyle(
fontSize: fontSize ?? 16.0,
color: ColorPalette.slate400,
),
);
final TextPainter textPainter = TextPainter(
text: textSpan,
maxLines: expanded.value ? null : maxLinesToShow,
textDirection: TextDirection.ltr,
strutStyle: StrutStyle(
fontSize: fontSize ?? 16.0,
)
);
textPainter.layout(maxWidth: SizeConfig.width);
final int numberOfLines = textPainter.computeLineMetrics().length;
return ValueListenableBuilder(
valueListenable: expanded,
builder: (context, values, _) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
if (!expanded.value && numberOfLines >= maxLinesToShow) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
content ?? "",
maxLines: maxLinesToShow,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: fontSize ?? 16.0,
color: ColorPalette.slate400,
),
),
/* See More :: type 1 - See More | 2 - See Less */
SeeMoreLessWidget(
textData: 'See More',
type: 1,
section: 1,
onSeeMoreLessTap: () {
expanded.value = true;
},
alignment: alignmentMore,
hideIconMore: hideIconMore!,
hideTextMore: hideTextMore!,
),
/* See More :: type 1 - See More | 2 - See Less */
],
);
} else {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
content ?? "",
style: TextStyle(
fontSize: fontSize ?? 16.0,
color: ColorPalette.slate400,
),
),
if (expanded.value && numberOfLines >= maxLinesToShow)
/* See Less :: type 1 - See More | 2 - See Less */
SeeMoreLessWidget(
textData: 'See Less',
type: 2,
section: 1,
onSeeMoreLessTap: () {
expanded.value = false;
},
alignment: alignmentMore,
hideIconMore: hideIconMore!,
hideTextMore: hideTextMore!,
),
/* See Less :: type 1 - See More | 2 - See Less */
],
);
}
},
),
],
);
},
);
}
}

View File

@ -0,0 +1,74 @@
import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:flutter/material.dart';
class SeeMoreLessWidget extends StatelessWidget {
final String? textData;
final int? type; /* type 1 - See More | 2 - See Less */
final Function? onSeeMoreLessTap;
final int?
section; /* 1: About the course | 2 - Who can take up this course? | 3 - Mentors | 4 - Course Video Reviews */
final Alignment? alignment;
final bool hideTextMore;
final bool hideIconMore;
const SeeMoreLessWidget({
super.key,
required this.textData,
required this.type,
required this.onSeeMoreLessTap,
required this.section,
required this.alignment,
required this.hideTextMore,
required this.hideIconMore,
});
@override
Widget build(BuildContext context) {
return Align(
alignment: alignment ?? Alignment.centerLeft,
child: InkWell(
onTap: () {
if (onSeeMoreLessTap != null) {
onSeeMoreLessTap!();
}
},
child: Text.rich(
softWrap: true,
style: const TextStyle(
color: ColorPalette.primary,
),
textAlign: TextAlign.start,
TextSpan(
text: "",
children: [
if(!hideTextMore)
TextSpan(
text: textData,
style: const TextStyle(
color: ColorPalette.primary,
decoration: TextDecoration.underline,
),
),
if(!hideTextMore && !hideIconMore)
const WidgetSpan(
child: SizedBox(
width: 3.0,
),
),
if(!hideIconMore)
WidgetSpan(
child: Icon(
(type == 1)
? Icons.keyboard_arrow_down
: Icons.keyboard_arrow_up,
color: ColorPalette.slate300,
size: 28,
),
),
],
),
),
),
);
}
}

View File

@ -1,3 +1,4 @@
import 'package:cims_apps/application/component/expandable_widget/expandable_widget.dart';
import 'package:cims_apps/application/theme/color_palette.dart'; import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -44,28 +45,11 @@ class RadioAgreement extends StatelessWidget {
width: 12, width: 12,
), ),
Expanded( Expanded(
child: Column( child: ExpandableWidget(
crossAxisAlignment: CrossAxisAlignment.start, content: desc,
children: [ maxLinesToShow: 3,
Text( )
desc, )
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: ColorPalette.slate400),
),
GestureDetector(
onTap: () {},
child: const Text(
'Read More',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
decoration: TextDecoration.underline,
color: ColorPalette.primary),
))
],
))
], ],
), ),
); );

View File

@ -1,4 +1,5 @@
import 'package:cims_apps/application/assets/path_assets.dart'; import 'package:cims_apps/application/assets/path_assets.dart';
import 'package:cims_apps/application/component/expandable_widget/expandable_widget.dart';
import 'package:cims_apps/application/theme/color_palette.dart'; import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:cims_apps/core/utils/size_config.dart'; import 'package:cims_apps/core/utils/size_config.dart';
import 'package:cims_apps/features/auth/registration/view/submission_data/risk_profile/risk_profile_view_model/risk_profile_view_model.dart'; import 'package:cims_apps/features/auth/registration/view/submission_data/risk_profile/risk_profile_view_model/risk_profile_view_model.dart';
@ -73,20 +74,20 @@ class RiskProfile extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Container( Container(
padding: EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
riskProfile.type, riskProfile.type,
style: TextStyle( style: const TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 24, fontSize: 24,
color: ColorPalette.white color: ColorPalette.white
), ),
), ),
SizedBox(height: 16,), const SizedBox(height: 16,),
Text('Total Score :', const Text('Total Score :',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16, fontSize: 16,
@ -94,7 +95,7 @@ class RiskProfile extends StatelessWidget {
), ),
), ),
Text('$totalScore', Text('$totalScore',
style: TextStyle( style: const TextStyle(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 28, fontSize: 28,
color: ColorPalette.white color: ColorPalette.white
@ -107,20 +108,20 @@ class RiskProfile extends StatelessWidget {
), ),
), ),
), ),
SizedBox( const SizedBox(
height: 24, height: 24,
), ),
Text( ExpandableWidget(
riskProfile.desc, content: riskProfile.desc,
style: TextStyle( hideTextMore: true,
color: ColorPalette.slate500, hideIconMore: false,
fontSize: 16 maxLinesToShow: 4,
) alignmentMore: Alignment.center,
), ),
SizedBox( const SizedBox(
height: 24, height: 24,
), ),
Text( const Text(
'Suitable Product', 'Suitable Product',
style: TextStyle( style: TextStyle(
color: ColorPalette.slate800, color: ColorPalette.slate800,
@ -128,7 +129,7 @@ class RiskProfile extends StatelessWidget {
fontSize: 18 fontSize: 18
), ),
), ),
SizedBox( const SizedBox(
height: 16, height: 16,
), ),
rowSuitableProduct ? rowSuitableProduct ?
@ -137,7 +138,7 @@ class RiskProfile extends StatelessWidget {
return Expanded( return Expanded(
child: Container( child: Container(
margin: EdgeInsets.only(left: e.key != 0 ? 12 : 0), margin: EdgeInsets.only(left: e.key != 0 ? 12 : 0),
padding: EdgeInsets.all(16), padding: const EdgeInsets.all(16),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all(color: ColorPalette.slate200), border: Border.all(color: ColorPalette.slate200),
borderRadius: BorderRadius.circular(6) borderRadius: BorderRadius.circular(6)
@ -146,18 +147,18 @@ class RiskProfile extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( Container(
padding: EdgeInsets.all(8), padding: const EdgeInsets.all(8),
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
color: riskProfile.color.withOpacity(0.1) color: riskProfile.color.withOpacity(0.1)
), ),
child: Image.asset(e.value['icon'], width: SizeConfig.width * 0.07, color: riskProfile.color) child: Image.asset(e.value['icon'], width: SizeConfig.width * 0.07, color: riskProfile.color)
), ),
SizedBox( const SizedBox(
height: 12, height: 12,
), ),
Text(e.value['desc'], Text(e.value['desc'],
style: TextStyle( style: const TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: ColorPalette.slate800 color: ColorPalette.slate800
@ -173,7 +174,7 @@ class RiskProfile extends StatelessWidget {
runSpacing: 16, runSpacing: 16,
children: riskProfile.suitableProduct.map((e) { children: riskProfile.suitableProduct.map((e) {
return Container( return Container(
padding: EdgeInsets.all(16), padding: const EdgeInsets.all(16),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6), borderRadius: BorderRadius.circular(6),
border: Border.all(color: ColorPalette.slate200), border: Border.all(color: ColorPalette.slate200),
@ -181,7 +182,7 @@ class RiskProfile extends StatelessWidget {
child: Row( child: Row(
children: [ children: [
Container( Container(
padding: EdgeInsets.all(8), padding: const EdgeInsets.all(8),
alignment: Alignment.center, alignment: Alignment.center,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
@ -189,12 +190,12 @@ class RiskProfile extends StatelessWidget {
), ),
child: Image.asset(e['icon'], width: SizeConfig.width * 0.07, color: riskProfile.color) child: Image.asset(e['icon'], width: SizeConfig.width * 0.07, color: riskProfile.color)
), ),
SizedBox( const SizedBox(
width: 12, width: 12,
), ),
Expanded( Expanded(
child: Text(e['desc'], child: Text(e['desc'],
style: TextStyle( style: const TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
color: ColorPalette.slate800 color: ColorPalette.slate800

View File

@ -139,9 +139,8 @@ class TotalPaymentView extends StatelessWidget {
), ),
RadioAgreement( RadioAgreement(
isAgree: isAgree, isAgree: isAgree,
desc: 'I agree to buy the mutual fund on this page and have read and agreed to all the contents of the Prospectus and summary information and understand the risks of my investment decision. Read More', desc: 'I agree to buy the mutual fund on this page and have read and agreed to all the contents of the Prospectus and summary information and understand the risks of my investment decision.',
onTap: () { onTap: () {
print('gagaga');
onTapAgree(); onTapAgree();
}, },
), ),

View File

@ -1,12 +1,8 @@
import 'package:cims_apps/application/component/button/button_view.dart';
import 'package:cims_apps/application/component/custom_app_bar/custom_app_bar.dart'; import 'package:cims_apps/application/component/custom_app_bar/custom_app_bar.dart';
import 'package:cims_apps/application/component/subscribe/goal_investing_view.dart'; import 'package:cims_apps/application/component/subscribe/goal_investing_view.dart';
import 'package:cims_apps/application/component/subscribe/input_investment_view.dart'; import 'package:cims_apps/application/component/subscribe/input_investment_view.dart';
import 'package:cims_apps/application/component/numeric_pad/numeric_pad.dart';
import 'package:cims_apps/application/component/risk_profile.dart'; import 'package:cims_apps/application/component/risk_profile.dart';
import 'package:cims_apps/application/component/text_form/text_form_view.dart';
import 'package:cims_apps/application/theme/color_palette.dart'; import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:cims_apps/core/utils/number_formatter.dart';
import 'package:cims_apps/core/utils/size_config.dart'; import 'package:cims_apps/core/utils/size_config.dart';
import 'package:cims_apps/features/dashboard/dashboard_account/view/plan/view/step_invest_plan/options_starting_invest.dart'; import 'package:cims_apps/features/dashboard/dashboard_account/view/plan/view/step_invest_plan/options_starting_invest.dart';
import 'package:cims_apps/features/dashboard/dashboard_account/view/plan/view_model/plan_view_model.dart'; import 'package:cims_apps/features/dashboard/dashboard_account/view/plan/view_model/plan_view_model.dart';
@ -46,33 +42,32 @@ class _PlanViewState extends State<PlanView> {
appBar: CustomAppBar( appBar: CustomAppBar(
height: SizeConfig.height * 0.08, height: SizeConfig.height * 0.08,
title: 'Investment Plan', title: 'Investment Plan',
leading: SizedBox(), leading: const SizedBox(),
), ),
body: SingleChildScrollView( body: SingleChildScrollView(
padding: EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
RiskProfile( const RiskProfile(
totalScore: 26, totalScore: 26,
rowSuitableProduct: true rowSuitableProduct: true
), ),
SizedBox( const SizedBox(
height: 32, height: 32,
), ),
Text('Your Goal in Investing', const Text('Your Goal in Investing',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
color: ColorPalette.slate800, color: ColorPalette.slate800,
fontSize: 18 fontSize: 18
), ),
), ),
SizedBox( const SizedBox(
height: 24, height: 24,
), ),
GoalInvestingView( GoalInvestingView(
onListSelected: (p0) { onListSelected: (p0) {
print(p0);
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
isScrollControlled: true, isScrollControlled: true,
@ -103,7 +98,7 @@ class _PlanViewState extends State<PlanView> {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text("It's time to invest", const Text("It's time to invest",
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w600 fontWeight: FontWeight.w600
@ -113,12 +108,12 @@ class _PlanViewState extends State<PlanView> {
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(context);
}, },
child: Icon(Icons.close_rounded) child: const Icon(Icons.close_rounded)
) )
], ],
), ),
), ),
Divider(color: ColorPalette.slate200, height: 1), const Divider(color: ColorPalette.slate200, height: 1),
InputInvestmentView( InputInvestmentView(
selectedPlan: text, selectedPlan: text,
nextMove: (value) { nextMove: (value) {