creek
The AI Image Editor of 2030git clone https://github.com/maydayv7/creek
lib/ui/widgets/dialog.dart (3308B)
1import 'package:flutter/material.dart';
2import 'package:creekui/ui/styles/variables.dart';
3import 'package:creekui/ui/widgets/primary_button.dart';
4import 'package:creekui/ui/widgets/secondary_button.dart';
5
6class ShowDialog extends StatelessWidget {
7 final String title;
8 final String? description;
9 final Widget? content;
10 final String primaryButtonText;
11 final VoidCallback onPrimaryPressed;
12 final String secondaryButtonText;
13 final VoidCallback? onSecondaryPressed;
14 final bool isDestructive;
15 final bool isLoading;
16
17 const ShowDialog({
18 super.key,
19 required this.title,
20 this.description,
21 this.content,
22 required this.primaryButtonText,
23 required this.onPrimaryPressed,
24 this.secondaryButtonText = "Cancel",
25 this.onSecondaryPressed,
26 this.isDestructive = false,
27 this.isLoading = false,
28 });
29
30 static Future<T?> show<T>(
31 BuildContext context, {
32 required String title,
33 String? description,
34 Widget? content,
35 required String primaryButtonText,
36 required VoidCallback onPrimaryPressed,
37 String secondaryButtonText = "Cancel",
38 VoidCallback? onSecondaryPressed,
39 bool isDestructive = false,
40 bool isLoading = false,
41 }) {
42 return showDialog<T>(
43 context: context,
44 builder:
45 (context) => Dialog(
46 backgroundColor: Colors.white,
47 shape: RoundedRectangleBorder(
48 borderRadius: BorderRadius.circular(Variables.radiusLarge),
49 ),
50 child: ShowDialog(
51 title: title,
52 description: description,
53 content: content,
54 primaryButtonText: primaryButtonText,
55 onPrimaryPressed: onPrimaryPressed,
56 secondaryButtonText: secondaryButtonText,
57 onSecondaryPressed: onSecondaryPressed,
58 isDestructive: isDestructive,
59 isLoading: isLoading,
60 ),
61 ),
62 );
63 }
64
65 @override
66 Widget build(BuildContext context) {
67 return Padding(
68 padding: const EdgeInsets.all(24.0),
69 child: Column(
70 mainAxisSize: MainAxisSize.min,
71 crossAxisAlignment: CrossAxisAlignment.start,
72 children: [
73 Text(title, style: Variables.headerStyle.copyWith(fontSize: 18)),
74 if (description != null) ...[
75 const SizedBox(height: 8),
76 Text(
77 description!,
78 style: Variables.bodyStyle.copyWith(
79 color: Variables.textSecondary,
80 ),
81 ),
82 ],
83 if (content != null) ...[const SizedBox(height: 16), content!],
84 const SizedBox(height: 24),
85 Row(
86 children: [
87 Expanded(
88 child: SecondaryButton(
89 text: secondaryButtonText,
90 onPressed: onSecondaryPressed ?? () => Navigator.pop(context),
91 ),
92 ),
93 const SizedBox(width: 12),
94 Expanded(
95 child: PrimaryButton(
96 text: primaryButtonText,
97 onPressed: onPrimaryPressed,
98 isLoading: isLoading,
99 backgroundColor: isDestructive ? Colors.red : null,
100 ),
101 ),
102 ],
103 ),
104 ],
105 ),
106 );
107 }
108}