dialog static method
Implementation
static String dialog() => r'''
import 'package:flutter/material.dart';
import '../tokens/app_spacing.dart';
import '../tokens/app_typography.dart';
import 'app_button.dart';
import 'app_surface.dart';
class AppDialog extends StatelessWidget {
const AppDialog({
super.key,
required this.title,
required this.body,
this.primaryLabel = 'OK',
this.secondaryLabel,
this.onPrimary,
this.onSecondary,
});
final String title;
final String body;
final String primaryLabel;
final String? secondaryLabel;
final VoidCallback? onPrimary;
final VoidCallback? onSecondary;
static Future<void> show(
BuildContext context, {
required String title,
required String body,
String primaryLabel = 'OK',
String? secondaryLabel,
}) {
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AppDialog(
title: title,
body: body,
primaryLabel: primaryLabel,
secondaryLabel: secondaryLabel,
onPrimary: () => Navigator.of(context).pop(),
onSecondary: secondaryLabel == null
? null
: () => Navigator.of(context).pop(),
);
},
);
}
@override
Widget build(BuildContext context) {
return Dialog(
backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.all(AppSpacing.lg),
child: AppSurface(
depth: AppSurfaceDepth.floating,
padding: const EdgeInsets.all(AppSpacing.lg),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(title, style: AppTypography.headline),
const SizedBox(height: AppSpacing.sm),
Text(body, style: AppTypography.body),
const SizedBox(height: AppSpacing.lg),
Wrap(
alignment: WrapAlignment.end,
spacing: AppSpacing.sm,
children: <Widget>[
if (secondaryLabel != null)
AppButton(
label: secondaryLabel!,
variant: AppButtonVariant.text,
onPressed: onSecondary,
),
AppButton(
label: primaryLabel,
onPressed: onPrimary,
),
],
),
],
),
),
);
}
}
''';