Translate-Flutter/lib/widget/t_remind_dialog.dart
2024-07-24 11:59:36 +08:00

119 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
class TRemindDialog extends StatelessWidget {
const TRemindDialog({
super.key,
this.title,
this.content,
this.showCancelBtn = true,
this.cancelText,
this.confirmText,
this.confirmOnTap,
this.popScope = false,
});
final String? title;
final String? content;
final bool? showCancelBtn;
final String? cancelText;
final String? confirmText;
final Function()? confirmOnTap;
final bool popScope;
@override
Widget build(BuildContext context) {
return PopScope(
canPop: popScope,
child: Center(
child: Container(
width: MediaQuery.of(context).size.width * 0.8,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: IntrinsicHeight(
child: Column(
children: [
const SizedBox(height: 10),
Text(
title ?? 'Reminder',
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Text(
content ?? '',
textAlign: TextAlign.center,
style: const TextStyle(
color: Color(0xFF333333),
fontSize: 16,
),
),
),
const SizedBox(height: 12),
const Divider(
height: 1,
thickness: 1,
color: Color(0xFFE5E5E5),
),
SizedBox(
height: 52,
child: Row(
children: [
if (showCancelBtn!) ...[
_optionButton(cancelText ?? 'Cancel', false),
Container(
width: 1,
height: double.infinity,
color: const Color(0xFFE5E5E5),
),
],
_optionButton(confirmText ?? 'Confirm', true),
],
),
),
],
),
),
),
),
);
}
Widget _optionButton(String label, bool isConfirm) {
return Expanded(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () {
Get.back();
if (isConfirm && confirmOnTap != null) confirmOnTap!();
},
child: SizedBox(
height: double.infinity,
child: Center(
child: Text(
label,
textAlign: TextAlign.center,
style: TextStyle(
color: isConfirm ? Colors.black : const Color(0xFF666666),
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
),
),
),
);
}
}