dilemmaMaterial static method

Future<DialogResult?> dilemmaMaterial(
  1. BuildContext context, {
  2. required String title,
  3. required String content,
  4. String rightButton = "ACCEPT",
  5. String leftButton = "CANCEL",
  6. bool centerContent = false,
  7. bool? dark,
  8. VoidCallback? onTapedRight,
  9. VoidCallback? onTapedLeft,
})

两难选择模式,Android Material Design样式。

用途

  • 提示内容,两难选择

Implementation

static Future<DialogResult?> dilemmaMaterial(
  BuildContext context, {
  required String title,
  required String content,
  String rightButton = "ACCEPT",
  String leftButton = "CANCEL",
  bool centerContent = false,
  bool? dark,
  VoidCallback? onTapedRight,
  VoidCallback? onTapedLeft,
}) {
  bool _dark = dark ?? (Theme.of(context).brightness == Brightness.dark);
  Color _barrierColor = _dark ? Color(0xaa000000) : Color(0x9effffff);
  Color _backgroundColor = _dark ? Colors.black45 : Colors.white60;
  Color _fontColor = _dark ? Colors.white : Colors.black;
  // TextStyle getTextStyle(Set<MaterialState> states) {
  //   const Set<MaterialState> interactiveStates = <MaterialState>{
  //     MaterialState.pressed,
  //     MaterialState.hovered,
  //     MaterialState.focused,
  //   };
  //   if (states.any(interactiveStates.contains)) {
  //     return TextStyle(color: Color(0xFF6200EE));
  //   }
  //   return TextStyle(color: _fontColor);
  // }

  return showDialog<DialogResult>(
    context: context,
    barrierColor: _barrierColor,
    barrierDismissible: false,
    builder: (context) {
      return AlertDialog(
        backgroundColor: _backgroundColor,
        shape: const RoundedRectangleBorder(borderRadius: _borderRadius),
        title: Text(
          title,
          style: TextStyle(
              fontWeight: FontWeight.bold, fontSize: 20.0, color: _fontColor),
        ),
        content: Text(
          content,
          style: TextStyle(color: _fontColor),
        ),
        actions: [
          TextButton(
            onPressed: onTapedLeft ??
                () {
                  Navigator.of(context)
                      .pop(DialogResult(status: false, code: 200));
                },
            child: Text(
              leftButton,
              style: Theme.of(context)
                  .textTheme
                  .subtitle1!
                  .copyWith(color: Theme.of(context).primaryColor),
            ),
          ),
          TextButton(
            onPressed: onTapedRight ??
                () {
                  Navigator.of(context)
                      .pop(DialogResult(status: true, code: 200));
                },
            child: Text(
              rightButton,
              style: Theme.of(context)
                  .textTheme
                  .subtitle1!
                  .copyWith(color: Theme.of(context).primaryColor),
            ),
          )
        ],
      );
    },
  );
}