apskel-pos-flutter/lib/core/components/custom_modal_dialog.dart

116 lines
3.7 KiB
Dart
Raw Normal View History

2025-07-31 23:22:34 +07:00
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
2025-08-01 01:17:00 +07:00
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
2025-07-31 23:22:34 +07:00
import 'package:flutter/material.dart';
class CustomModalDialog extends StatelessWidget {
final String title;
final String? subtitle;
final Widget child;
final VoidCallback? onClose;
2025-08-01 01:40:33 +07:00
final double? minWidth;
final double? maxWidth;
final double? minHeight;
final double? maxHeight;
2025-08-01 15:30:33 +07:00
final EdgeInsets? contentPadding;
2025-07-31 23:22:34 +07:00
2025-08-01 01:40:33 +07:00
const CustomModalDialog({
super.key,
required this.title,
this.subtitle,
required this.child,
this.onClose,
this.minWidth,
this.maxWidth,
this.minHeight,
this.maxHeight,
2025-08-01 15:30:33 +07:00
this.contentPadding,
2025-08-01 01:40:33 +07:00
});
2025-07-31 23:22:34 +07:00
@override
Widget build(BuildContext context) {
return Dialog(
backgroundColor: AppColors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
child: ConstrainedBox(
constraints: BoxConstraints(
2025-08-01 01:40:33 +07:00
minWidth: minWidth ?? context.deviceWidth * 0.3,
maxWidth: maxWidth ?? context.deviceWidth * 0.8,
minHeight: minHeight ?? context.deviceHeight * 0.3,
maxHeight: maxHeight ?? context.deviceHeight * 0.8,
2025-07-31 23:22:34 +07:00
),
2025-08-01 01:17:00 +07:00
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.all(16),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
const Color.fromARGB(255, 81, 40, 134),
AppColors.primary,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.vertical(
top: Radius.circular(16),
),
2025-07-31 23:22:34 +07:00
),
2025-08-01 01:17:00 +07:00
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2025-07-31 23:22:34 +07:00
Text(
2025-08-01 01:17:00 +07:00
title,
2025-07-31 23:22:34 +07:00
style: TextStyle(
2025-08-01 01:17:00 +07:00
color: AppColors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
2025-07-31 23:22:34 +07:00
),
),
2025-08-01 01:17:00 +07:00
if (subtitle != null)
Text(
subtitle ?? '',
style: TextStyle(
color: AppColors.grey,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
],
),
2025-07-31 23:22:34 +07:00
),
2025-08-01 01:17:00 +07:00
SpaceWidth(12),
IconButton(
icon: Icon(Icons.close, color: AppColors.white),
onPressed: () {
if (onClose != null) {
onClose!();
} else {
Navigator.of(context).pop();
}
},
),
],
),
2025-07-31 23:22:34 +07:00
),
2025-08-01 15:30:33 +07:00
Padding(
padding: contentPadding ?? EdgeInsets.zero,
child: child,
),
2025-08-01 01:17:00 +07:00
],
),
2025-07-31 23:22:34 +07:00
),
),
);
}
}