我认为您在谈论对话框背景中的黑色推子......是材料/cupertino 实现的一部分,在材料中有一个固定值 Colors.black54。
您将不得不复制showDialog()
代码并对其进行修改。
演示:
// common Dialog widget shown in both implementation.
Widget buildDialog(BuildContext context) {
return CupertinoDialogAction(
child: Text(
'Delete',
style: TextStyle(color: Colors.red),
),
onPressed: () async {
Navigator.of(context).pop();
},
);
}
void openDialog(BuildContext context) {
// open custom dialog.
openCustomDialog(context);
// open default dialog.
// openFlutterDialog(context);
}
// regular Fluter showDialog()
void openFlutterDialog(BuildContext context) {
showDialog(
context: context,
builder: (ctx) {
return buildDialog(ctx);
},
);
}
void openCustomDialog(BuildContext context) {
showCustomDialog(
context: context,
builder: (ctx) {
return buildDialog(ctx);
},
);
}
// custom implementation of showDialog()...
Future<T> showCustomDialog<T>({
@required BuildContext context,
bool barrierDismissible = true,
WidgetBuilder builder,
}) {
assert(debugCheckHasMaterialLocalizations(context));
final ThemeData theme = Theme.of(context, shadowThemeOnly: true);
return showGeneralDialog(
context: context,
pageBuilder: (BuildContext buildContext, Animation<double> animation,
Animation<double> secondaryAnimation) {
final Widget pageChild = Builder(builder: builder);
return SafeArea(
child: Builder(builder: (BuildContext context) {
return theme != null
? Theme(data: theme, child: pageChild)
: pageChild;
}),
);
},
barrierDismissible: barrierDismissible,
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
// KEY PART TO MODIFY, Flutter doesn't allow a transparent Color,
// values under opacity .01 are considered transparent and will throw an error.
// But this value is transparent enough.
barrierColor: Colors.black.withOpacity(0.01),
// you can modify the default FadeTransition duration here.
transitionDuration: const Duration(milliseconds: 2000),
);
}
这是你要找的吗?