showChromiaDialog
Shows a customizable dialog.
Basic Usage
await showChromiaDialog(
context: context,
title: 'Confirm Action',
content: 'Are you sure you want to continue?',
actions: [
ChromiaDialogAction(
label: 'Cancel',
onPressed: () => Navigator.pop(context),
),
ChromiaDialogAction(
label: 'Confirm',
isPrimary: true,
onPressed: () => Navigator.pop(context, true),
),
],
);
Parameters
Custom title widget (overrides title)
Custom content widget (overrides content)
actions
List<ChromiaDialogAction>?
Action buttons
Whether the dialog can be dismissed by tapping outside
Color of the barrier (overlay)
ChromiaDialog
The dialog widget itself (usually used through showChromiaDialog).
Parameters
actions
List<ChromiaDialogAction>?
Action buttons
ChromiaDialogAction
An action button for dialogs.
Constructor
const ChromiaDialogAction({
required String label,
required VoidCallback onPressed,
bool isPrimary = false,
bool isDestructive = false,
})
Parameters
Whether this is the primary action (highlighted)
Whether this is a destructive action (shown in red)
showChromiaAlert
Shows an alert dialog with a single action.
Basic Usage
await showChromiaAlert(
context: context,
title: 'Success',
message: 'Your changes have been saved.',
);
Parameters
Label for the action button
Callback when pressed (defaults to closing dialog)
showChromiaConfirmDialog
Shows a confirmation dialog with cancel and confirm actions.
Basic Usage
final confirmed = await showChromiaConfirmDialog(
context: context,
title: 'Delete Item',
message: 'Are you sure you want to delete this item?',
confirmLabel: 'Delete',
isDestructive: true,
);
if (confirmed) {
// Delete the item
}
Parameters
Label for the cancel button
confirmLabel
String
default:"'Confirm'"
Label for the confirm button
Whether this is a destructive action
Returns
Returns Future<bool> - true if confirmed, false if cancelled.
showChromiaBottomSheet
Shows a bottom sheet dialog.
Basic Usage
await showChromiaBottomSheet(
context: context,
child: Container(
padding: EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: Icon(Icons.share),
title: Text('Share'),
onTap: () {
Navigator.pop(context);
},
),
ListTile(
leading: Icon(Icons.link),
title: Text('Copy Link'),
onTap: () {
Navigator.pop(context);
},
),
],
),
),
);
Parameters
Whether the sheet can be dismissed by tapping outside
Whether the sheet can be dragged to dismiss
ChromiaLoadingDialog
A loading dialog that shows a progress indicator.
Show Loading
ChromiaLoadingDialog.show(
context: context,
message: 'Loading...',
);
// Do some work
await Future.delayed(Duration(seconds: 2));
// Hide loading
ChromiaLoadingDialog.hide(context);
Parameters
Loading message to display
Methods
Shows the loading dialogstatic Future<void> show({
required BuildContext context,
String? message,
})
Hides the loading dialogstatic void hide(BuildContext context)
Complete Example
class DialogExample extends StatelessWidget {
Future<void> _saveChanges(BuildContext context) async {
// Show confirmation
final confirmed = await showChromiaConfirmDialog(
context: context,
title: 'Save Changes',
message: 'Do you want to save your changes?',
confirmLabel: 'Save',
);
if (!confirmed) return;
// Show loading
ChromiaLoadingDialog.show(
context: context,
message: 'Saving changes...',
);
try {
// Simulate API call
await Future.delayed(Duration(seconds: 2));
// Hide loading
ChromiaLoadingDialog.hide(context);
// Show success
await showChromiaAlert(
context: context,
title: 'Success',
message: 'Your changes have been saved successfully.',
);
} catch (e) {
// Hide loading
ChromiaLoadingDialog.hide(context);
// Show error
await showChromiaAlert(
context: context,
title: 'Error',
message: 'Failed to save changes: $e',
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: ChromiaAppBar(title: 'Dialog Example'),
body: Center(
child: ChromiaButton(
label: 'Save Changes',
onPressed: () => _saveChanges(context),
),
),
);
}
}