Skip to content

Instantly share code, notes, and snippets.

@kodenatan17
Created November 27, 2022 14:43
Show Gist options
  • Save kodenatan17/84e069680c35d401b417df09a6ab05bd to your computer and use it in GitHub Desktop.
Save kodenatan17/84e069680c35d401b417df09a6ab05bd to your computer and use it in GitHub Desktop.
part of 'ts_dialog.dart';
class TSModalPopup extends StatelessWidget {
final double height;
final String title, subtitle;
final String previousTitle;
final String nextTitle;
final VoidCallback? nextProcess;
final VoidCallback? previousProcess;
final String imageUrl;
final TypePopup typePopup;
final TypeOverlayIcon? typeOverlayIcon;
final TypeApproval typeApproval;
const TSModalPopup({
super.key,
required this.title,
required this.subtitle,
this.previousTitle = '',
this.nextTitle = '',
this.nextProcess,
this.previousProcess,
required this.imageUrl,
required this.typePopup,
required this.height,
this.typeOverlayIcon,
required this.typeApproval,
});
@override
Widget build(BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(kDefaultRadius),
),
elevation: 0,
backgroundColor: Colors.transparent,
child: contentBox(context),
);
}
Widget contentBox(BuildContext context) {
if (typePopup == TypePopup.popup) {
return Container(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(imageUrl),
TSText.batik(
text: title,
fontSize: 20,
fontWeight: bold,
),
TSText.poppins(text: subtitle, fontSize: 12),
getTypeApproval(),
],
),
);
}
if (typePopup == TypePopup.overlay) {
return Stack(
children: [
getTypeOverlayIcon(),
Container(
height: height,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TSText.batik(
text: title,
fontSize: 20,
fontWeight: bold,
),
const SizedBox(height: 10),
TSText.poppins(
text: subtitle,
fontSize: 12,
),
const SizedBox(height: 30),
getTypeApproval(),
],
),
),
],
);
}
return const SizedBox.shrink();
}
Widget getTypeOverlayIcon() {
if (typeOverlayIcon == TypeOverlayIcon.topRight) {
return Align(
alignment: Alignment.topRight,
child: Image.asset(imageUrl),
);
}
if (typeOverlayIcon == TypeOverlayIcon.topCenter) {
return Align(
alignment: Alignment.topCenter,
child: Image.asset(imageUrl),
);
}
if(typeOverlayIcon == TypeOverlayIcon.topLeft){
return Align(
alignment: Alignment.topLeft,
child: Image.asset(imageUrl),
);
}
return const SizedBox.shrink();
}
Widget getTypeApproval() {
if (typeApproval == TypeApproval.approved) {
return TSMasterButton(
buttonType: ButtonType.filled,
text: nextTitle,
onPressed: nextProcess,
);
}
if (typeApproval == TypeApproval.yesno) {
return Column(
children: [
TSMasterButton(
buttonType: ButtonType.filled,
text: nextTitle,
onPressed: nextProcess,
),
TSMasterButton(
buttonType: ButtonType.text,
text: previousTitle,
onPressed: previousProcess,
),
],
);
}
return const SizedBox.shrink();
}
}
enum TypeOverlayIcon { topLeft, topCenter, topRight }
enum TypePopup { overlay, popup }
enum TypeApproval { approved, yesno }
TSModalPopup(
title: 'Ketahui Jenis-Jenis Survey\nyang Ada di tSurvey',
subtitle:
'Yuk berkenalan dengan survey yang\nterdapat di tSurvey untuk memudahkan\nAnda dalam menggunakan aplikasi ini',
imageUrl: 'assets/vector/popup_first.png',
typePopup: TypePopup.overlay,
height: Get.height * .5,
typeOverlayIcon: TypeOverlayIcon.topLeft,
typeApproval: TypeApproval.yesno,
nextTitle: 'Cari Tahu Lebih Lanjut',
nextProcess: () {},
previousTitle: 'Nanti Saja',
previousProcess: () {},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment