show<T> static method
Future<T?>
show<T>({
- required dynamic context,
- required Widget builder(),
- bool isDismissible = true,
- BoxConstraints? constraints,
- bool isExpanded = true,
- bool? useSafeArea,
- double? contentPadding,
- Widget? confirm,
- Widget? cancel,
- Widget? title,
- Widget? action,
- String? titleText,
- bool? showConfirm = false,
- bool? showCancel = false,
- void onConfirm()?,
- void onCancel()?,
- AlignmentGeometry? contentAlignment,
- double? height,
显示底部弹窗
Implementation
static Future<T?> show<T>({
required context,
required Widget Function(BuildContext) builder,
bool isDismissible = true,
BoxConstraints? constraints,
bool isExpanded = true,
bool? useSafeArea,
double? contentPadding,
Widget? confirm,
Widget? cancel,
Widget? title,
Widget? action,
String? titleText,
bool? showConfirm = false,
bool? showCancel = false,
void Function()? onConfirm,
void Function()? onCancel,
AlignmentGeometry? contentAlignment,
double? height,
}) async {
UtilInternal.unfocus();
return showModalBottomSheet<T>(
isDismissible: isDismissible,
isScrollControlled: true,
context: context,
useSafeArea: useSafeArea ?? true,
constraints: constraints ?? const BoxConstraints(),
builder: (BuildContext context) {
assert(title == null || titleText == null, '不能同时指定 title 和 titleText');
assert(
action == null ||
(showConfirm == null &&
showCancel == null &&
onConfirm == null &&
onCancel == null &&
confirm == null &&
cancel == null),
'不能同时指定 action 和其他参数',
);
assert(confirm == null || onConfirm == null, '不能同时指定 confirm 和 onConfirm');
assert(cancel == null || onCancel == null, '不能同时指定 cancel 和 onCancel');
ThemeData ctx = Theme.of(context);
ColorScheme colorScheme = ctx.colorScheme;
TextTheme textScheme = ctx.textTheme;
return GestureDetector(
onTap: () => UtilInternal.unfocus(),
child: KeyboardVisibilityBuilder(
builder: (context, isKeyboardVisible) {
return CustomAnnotatedRegion(
child: Padding(
padding: EdgeInsets.only(bottom: isKeyboardVisible ? context.keyboardHeight : 0),
child: SizedBox(
height: height ?? context.height * ConfigStore.to.config.app.bottomSheetHeight,
child: Column(
children: [
const CustomDragIndicator(),
const CustomSpaceHeightMini(),
// 标题栏
Padding(
padding: EdgeInsets.symmetric(horizontal: AppTheme.padding),
child:
action ??
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
showCancel == true
? cancel ??
CustomTextButton(
style: TextButton.styleFrom(foregroundColor: colorScheme.outline),
onPressed: onCancel ?? () => RouterService.instance.pop(),
child: Text('cancel'.tr(), style: textScheme.titleMedium),
)
: const SizedBox.shrink(),
?title,
if (titleText != null)
Align(
child: Text(titleText, style: textScheme.titleLarge),
),
showConfirm == true
? confirm ??
CustomTextButton(
onPressed: onConfirm,
child: Text(
'confirm'.tr(),
style: textScheme.titleMedium?.copyWith(color: colorScheme.primary),
),
)
: const SizedBox.shrink(),
],
),
),
if (title != null || titleText != null) const CustomSpaceHeightMini(),
// 内容
isExpanded
? Expanded(child: builder(context))
: Container(
margin: EdgeInsets.only(top: AppTheme.margin),
padding: EdgeInsets.symmetric(horizontal: contentPadding ?? AppTheme.padding),
child: builder(context),
),
const CustomSpaceHeightSmall(),
],
),
),
),
);
},
),
);
},
);
}