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