dilemmaX<T> static method
Future<T?>
dilemmaX<T>(
- BuildContext context, {
- required SliverChildDelegate delegate,
- String rightButton = "OK",
- String leftButton = "CANCEL",
- bool centerContent = false,
- bool? dark,
- VoidCallback? onTapedRight,
- VoidCallback? onTapedLeft,
可扩展内容的对话框选择。
Implementation
static Future<T?> dilemmaX<T>(
BuildContext context, {
/// 列表内容
required SliverChildDelegate delegate,
/// 按钮名称
String rightButton = "OK",
String leftButton = "CANCEL",
bool centerContent = false,
bool? dark,
VoidCallback? onTapedRight,
VoidCallback? onTapedLeft,
}) {
double _width = MediaQuery.of(context).size.width * 72 / 100;
bool _dark = dark ?? (Theme.of(context).brightness == Brightness.dark);
Color _barrierColor = _dark ? Color(0xaa000000) : Color(0x9effffff);
Color _backgroundColor = _dark ? Colors.black45 : Colors.white60;
return showDialog<T>(
context: context,
barrierColor: _barrierColor,
builder: (context) {
return Dialog(
backgroundColor: _backgroundColor,
// 对话框区域背景色
elevation: 12.0,
insetPadding: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
shape: const RoundedRectangleBorder(
borderRadius: _borderRadius,
),
child: Container(
width: _width,
constraints: BoxConstraints(maxHeight: 348),
decoration: BoxDecoration(
color: Colors.lightBlueAccent,
// backgroundBlendMode: BlendMode.modulate,
gradient: LinearGradient(colors: [
Colors.transparent,
Colors.transparent,
Colors.lightBlueAccent,
Colors.transparent,
], stops: [
0.0,
0.4,
0.9,
1.0,
], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
child: Stack(
fit: StackFit.expand,
children: [
// 内容和按键
Positioned(
top: 100,
left: 0,
right: 0,
bottom: 0,
child: Column(
children: [
// Container(height: 28, color: Colors.transparent,),
ConstrainedBox(
constraints:
BoxConstraints(maxHeight: 200, maxWidth: _width),
child: ListView.custom(
shrinkWrap: true,
childrenDelegate:
SliverChildBuilderDelegate((context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
borderRadius: _borderRadius,
color: Colors.pinkAccent[400],
),
child: ListTile(
leading: Icon(
Icons.star,
size: 44,
color: Colors.lightGreenAccent,
),
title: Text("index$index, High light"),
subtitle: Text(
"we are list tile, and this is subtitle."),
),
),
);
}, childCount: 4),
),
),
Container(
height: 48,
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
bottomLeft: const Radius.circular(_radiusValue),
bottomRight: const Radius.circular(_radiusValue)),
color: Colors.orangeAccent.withOpacity(0.8),
boxShadow: kElevationToShadow[8],
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Cancel')),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('OK')),
],
),
)
],
),
),
// 图标
Positioned(
top: 0,
left: 0,
right: 0,
child: IgnorePointer(
child: Icon(
Icons.batch_prediction,
size: 128,
color: Colors.greenAccent,
),
),
),
],
),
),
);
},
);
}