app_dialog.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../styles/theme.dart';
  4. const _horizontalEdge = 20.0;
  5. const _cardHeight = 225.4;
  6. double _getCardTop(BuildContext context) {
  7. return (context.height - _cardHeight) / 2.7;
  8. }
  9. class AppDialog extends StatelessWidget {
  10. final VoidCallback? onConfirm;
  11. final VoidCallback? onCancel;
  12. final String? onConfirmText;
  13. final String? onCancelText;
  14. final Widget title;
  15. final Widget? content;
  16. const AppDialog(
  17. {super.key,
  18. this.onConfirm,
  19. this.onCancel,
  20. this.onConfirmText,
  21. this.onCancelText,
  22. required this.title,
  23. this.content});
  24. @override
  25. Widget build(BuildContext context) {
  26. final style = (context.textTheme.titleLarge ?? const TextStyle()).copyWith(
  27. color: Colors.white, fontSize: 35.93, fontWeight: FontWeight.w700);
  28. final children = <Widget>[
  29. DefaultTextStyle(
  30. style: const TextStyle(
  31. fontSize: 17.42,
  32. color: Colors.white,
  33. ),
  34. child: title),
  35. const SizedBox(height: 6)
  36. ];
  37. if (content != null) {
  38. children.add(
  39. DefaultTextStyle(
  40. style: const TextStyle(
  41. fontSize: 15.24,
  42. color: Colors.white,
  43. ),
  44. child: content!),
  45. );
  46. }
  47. final actions = <Widget>[];
  48. actions.add(OutlinedButton(
  49. onPressed: onCancel ?? () => Get.back(),
  50. child: Text(onCancelText ?? '取消')));
  51. if (onConfirm != null) {
  52. actions.add(FilledButton(
  53. onPressed: onConfirm, child: Text(onConfirmText ?? '确定')));
  54. }
  55. var ali = MainAxisAlignment.center;
  56. if (actions.length > 1) {
  57. ali = MainAxisAlignment.spaceBetween;
  58. }
  59. children.add(SizedBox(
  60. width: 220,
  61. child: Padding(
  62. padding: const EdgeInsets.fromLTRB(15, 22, 15, 0),
  63. child: Row(
  64. mainAxisAlignment: ali,
  65. children: actions,
  66. ))));
  67. return Stack(alignment: Alignment.center, children: [
  68. Card(
  69. color: Colors.transparent,
  70. surfaceTintColor: Colors.transparent,
  71. shadowColor: Colors.transparent,
  72. child: Container(
  73. decoration: BoxDecoration(
  74. color: const Color(0x70000000),
  75. borderRadius: BorderRadius.circular(7.62)),
  76. padding: const EdgeInsets.all(15),
  77. child: Column(
  78. mainAxisSize: MainAxisSize.min,
  79. children: children,
  80. )))
  81. ]);
  82. }
  83. }
  84. class _Empty extends StatelessWidget {
  85. @override
  86. Widget build(BuildContext context) {
  87. _showDialog();
  88. return const Scaffold();
  89. }
  90. }
  91. Future<void> _showDialog() async {
  92. await Future.delayed(2.seconds);
  93. if (Get.isOverlaysOpen) {
  94. Get.back();
  95. }
  96. Get.dialog(AppDialog(
  97. onConfirm: () {},
  98. onCancel: () {},
  99. title: const Text('退出比赛'),
  100. content: const Text('是否强制结束?'),
  101. onCancelText: '否',
  102. onConfirmText: '是',
  103. ));
  104. }
  105. void main() async {
  106. runApp(GetMaterialApp(theme: appThemeData(), home: _Empty()));
  107. }