Skip to content

Instantly share code, notes, and snippets.

@kodenatan17
Last active November 25, 2022 04:30
Show Gist options
  • Save kodenatan17/544e7f8cf87d822d523b5c53c29af8ae to your computer and use it in GitHub Desktop.
Save kodenatan17/544e7f8cf87d822d523b5c53c29af8ae to your computer and use it in GitHub Desktop.
showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
context: context,
builder: (BuildContext context) => TSBottomDialog(
masterModal: MasterModal.notification,
title: 'Perkenalan diri (Survey Wajib)',
height: Get.height * .5,
backText: 'Ya, Batalkan',
backProcess: () => Navigator.pop(context),
nextText: 'Tidak, Lanjutkan Perubahan',
nextProcess: () => Navigator.pop(context),
lottieLibrary: const TSLottieWarning(),
),
),
showModalBottomSheet(
isScrollControlled: true,
backgroundColor: Colors.transparent,
context: context,
builder: (BuildContext context) => TSBottomDialog(
masterModal: MasterModal.survey,
title: 'Perkenalan diri (Survey Wajib)',
subtitle:
'Survey normal ini dapat Anda isi untuk mengetahui preferensi\nterhadap pelayanan bank digital',
amountSurvey: '5',
rewardSurvey: '10.000',
typeSurvey: 'Normal Survey',
height: Get.height * .6,
),
),
part of 'ts_dialog.dart';
class TSBottomDialog extends StatefulWidget {
final MasterModal masterModal;
final TypeModal? typeModal;
final double height;
final Widget? lottieLibrary;
final String typeSurvey;
final String title;
final String subtitle;
final Widget? content;
final VoidCallback? approvedProcess;
final String approvedText;
final bool isLottie;
final String nextText;
final String backText;
final VoidCallback? backProcess;
final VoidCallback? nextProcess;
final String amountSurvey;
final String rewardSurvey;
const TSBottomDialog({
super.key,
required this.masterModal,
this.typeModal,
required this.title,
this.subtitle = '',
this.content,
this.typeSurvey = '',
this.backProcess,
this.nextProcess,
this.approvedProcess,
this.nextText = '',
this.backText = '',
this.approvedText = '',
this.amountSurvey = '',
this.rewardSurvey = '',
required this.height,
this.lottieLibrary,
this.isLottie = true,
});
@override
State<TSBottomDialog> createState() => _TSBottomDialogState();
}
class _TSBottomDialogState extends State<TSBottomDialog> {
@override
Widget build(BuildContext context) {
if (widget.masterModal == MasterModal.tooltip) {
return Container(
height: widget.height,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
child: Stack(
children: [
Align(
alignment: Alignment.topCenter,
child: Image.asset('assets/vector/line.png'),
),
buildCarousel(context),
],
),
);
}
if (widget.masterModal == MasterModal.entry) {
return Container(
height: widget.height,
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
child: Column(
children: [
TSText.batik(text: widget.title),
Expanded(
child: widget.content!,
),
getTypeModal(),
],
),
);
}
if (widget.masterModal == MasterModal.notification) {
return Container(
height: widget.height,
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
color: whiteColor,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset('assets/vector/line.png'),
Visibility(
visible: widget.isLottie ? true : false,
child: Container(
alignment: Alignment.center,
height: 200,
width: 300,
child: widget.lottieLibrary,
),
),
Container(
child: Column(
children: [
TSText.batik(
text: widget.title,
fontSize: 20,
color: blueColor,
),
getTypeModal(),
],
),
),
],
),
);
}
if (widget.masterModal == MasterModal.survey) {
return Container(
height: widget.height,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
color: blueColor,
),
child: Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 15),
child: Align(
alignment: Alignment.topCenter,
child: Image.asset('assets/vector/line.png'),
),
),
Padding(
padding: const EdgeInsets.all(5),
child: Align(
alignment: Alignment.topRight,
child: Image.asset('assets/vector/survey.png'),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TSText.batik(
text: widget.typeSurvey,
fontSize: 10,
color: greyColor50,
),
TSText.batik(
text: widget.title,
fontSize: 16,
fontWeight: bold,
color: whiteColor,
)
],
),
),
buildSurveyContent(context),
],
),
],
),
);
}
return const SizedBox.shrink();
}
Widget buildSurveyContent(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
width: double.infinity,
height: Get.height * .48,
decoration: const BoxDecoration(
color: whiteColor,
borderRadius: BorderRadius.only(
topRight: Radius.circular(50),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TSText.batik(
text: widget.subtitle,
color: blueColor40,
fontSize: 10,
),
const Divider(),
Column(
children: [
Row(
children: [
Image.asset('assets/vector/survey_question.png'),
const SizedBox(width: 8),
TSText.batik(
text: 'Jumlah Pertanyaan',
color: blueColor,
fontWeight: semiBold,
fontSize: 12,
),
const Spacer(),
TSText.batik(
text: '${widget.amountSurvey} pertanyaan',
color: blueColor40,
),
],
),
Row(
children: [
Image.asset('assets/vector/survey_point.png'),
const SizedBox(width: 10),
TSText.batik(
text: 'Reward',
color: blueColor,
fontWeight: semiBold,
fontSize: 12,
),
const Spacer(),
TSText.batik(
text: '${widget.rewardSurvey} point',
color: blueColor40,
),
],
),
],
),
const SizedBox(height: 88),
const TSCustomSnackbar(
message:
'Mohon menjawab pertanyaan dengan jujur sesuai kondisi dan pendapat Anda.',
typeSnackBar: TypeSnackBar.info,
isDismissable: false,
),
buildSurveyFooter(context),
],
),
);
}
Widget buildSurveyFooter(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 10),
child: Column(
children: [
TSMasterButton(
text: 'KERJAKAN SURVEY',
buttonType: ButtonType.filled,
onPressed: () {
Navigator.pop(context);
},
),
const SizedBox(height: 10),
const TSAggrementUtils(
message: 'Dengan mengerjakan survey ini, saya menyetujui',
)
],
),
);
}
Widget getTypeModal() {
if (widget.typeModal == TypeModal.yesno) {
return Column(
children: [
TSMasterButton(
text: widget.nextText,
buttonType: ButtonType.filled,
onPressed: widget.nextProcess,
),
TSMasterButton(
text: widget.backText,
onPressed: widget.backProcess,
buttonType: ButtonType.text,
),
],
);
}
if (widget.typeModal == TypeModal.approved) {
return TSMasterButton(
text: widget.backText,
onPressed: widget.backProcess,
buttonType: ButtonType.text,
);
}
return const SizedBox.shrink();
}
Widget buildCarousel(BuildContext context) {
return Container(
child: Column(
children: [
CarouselSlider.builder(
itemCount: itemCount,
itemBuilder: (context, index, realIndex) {
final imgList = items[index];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(child: buildImage(imgList.path, index)),
const SizedBox(
height: 15,
),
buildText(imgList.itemName, index),
],
);
},,
options: CarouselOptions(
height: Get.height * .25,
viewportFraction: 1,
autoPlay: true,
enlargeCenterPage: true,
enlargeStrategy: CenterPageEnlargeStrategy.height,
autoPlayInterval: const Duration(seconds: 1),
onPageChanged: (index, reason) {
setState(() {
activeIndex = index;
});
},
),
)
],
),
);
}
}
enum MasterModal { survey, tooltip, notification, entry }
enum TypeModal { approved, yesno }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment