Option to add custom fields or widgets in dialog
ebelevics opened this issue · 2 comments
ebelevics commented
So far it seems it is just limited to predefined set of widgets to use dialogs. For example it seems is not possible to add something like in image above or just adding some other fields like my own pin code field. I hoped that builder(context, child): would allow to do this thing, but it seems like it's not currently available.
mono0926 commented
This package doesn't support that kind of flexibility as described here: #19 (comment)
You can implement it by using CupertinoAlertDialog class - cupertino library - Dart API etc.
ebelevics commented
So I have copied the code and added content parameter, so that it is now possible to add other components, for those who are interested
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:animations/animations.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// Show alert dialog, whose appearance is adaptive according to platform
///
/// [useActionSheetForCupertino] (default: false) only works for
/// cupertino style. If it is set to true, [showModalActionSheet] is called
/// instead.
/// [actionsOverflowDirection] works only for Material style currently.
Future<T?> showMyAlertDialog<T>({
required BuildContext context,
String? title,
String? message,
Widget? content, //added possibility to add content
List<AlertDialogAction<T>> actions = const [],
bool barrierDismissible = true,
AdaptiveStyle style = AdaptiveStyle.adaptive,
bool useActionSheetForCupertino = false,
bool useRootNavigator = true,
VerticalDirection actionsOverflowDirection = VerticalDirection.up,
bool fullyCapitalizedForMaterial = true,
WillPopCallback? onWillPop,
AdaptiveDialogBuilder? builder,
}) {
void pop(T? key) => Navigator.of(
context,
rootNavigator: useRootNavigator,
).pop(key);
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
final isCupertinoStyle = style.isCupertinoStyle(theme);
if (isCupertinoStyle && useActionSheetForCupertino) {
return showModalActionSheet(
context: context,
title: title,
message: message,
cancelLabel: actions.findCancelLabel(),
actions: actions.convertToSheetActions(),
style: style,
useRootNavigator: useRootNavigator,
onWillPop: onWillPop,
builder: builder,
);
}
final titleText = title == null ? null : Text(title);
final messageText = message == null ? null : Text(message);
final contentWidget = content == null
? messageText
: Column(children: [
if (messageText != null) messageText,
Material(color: Colors.transparent, child: content),
]); // if content is present then material is used as container as not all widgets support cupertino
return style.isCupertinoStyle(theme)
? showCupertinoDialog(
context: context,
useRootNavigator: useRootNavigator,
builder: (context) {
final dialog = WillPopScope(
onWillPop: onWillPop,
child: CupertinoAlertDialog(
title: titleText,
content: contentWidget, // replace
actions: actions.convertToCupertinoDialogActions(
onPressed: pop,
),
// TODO(mono): Set actionsOverflowDirection if available
// https://twitter.com/_mono/status/1261122914218160128
),
);
return builder == null ? dialog : builder(context, dialog);
},
)
: showModal(
context: context,
useRootNavigator: useRootNavigator,
configuration: FadeScaleTransitionConfiguration(
barrierDismissible: barrierDismissible,
),
builder: (context) {
final dialog = WillPopScope(
onWillPop: onWillPop,
child: AlertDialog(
title: titleText,
content: contentWidget, // replace
actions: actions.convertToMaterialDialogActions(
onPressed: pop,
destructiveColor: colorScheme.error,
fullyCapitalized: fullyCapitalizedForMaterial,
),
actionsOverflowDirection: actionsOverflowDirection,
scrollable: true,
),
);
return builder == null ? dialog : builder(context, dialog);
},
);
}
// Used to specify [showOkCancelAlertDialog]'s [defaultType]
enum OkCancelAlertDefaultType {
ok,
cancel,
}