| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import '../styles/theme.dart';
- const _horizontalEdge = 20.0;
- const _cardHeight = 225.4;
- double _getCardTop(BuildContext context) {
- return (context.height - _cardHeight) / 2.7;
- }
- class AppDialog extends StatelessWidget {
- final VoidCallback? onConfirm;
- final VoidCallback? onCancel;
- final String? onConfirmText;
- final String? onCancelText;
- final Widget title;
- final Widget? content;
- const AppDialog(
- {super.key,
- this.onConfirm,
- this.onCancel,
- this.onConfirmText,
- this.onCancelText,
- required this.title,
- this.content});
- @override
- Widget build(BuildContext context) {
- final style = (context.textTheme.titleLarge ?? const TextStyle()).copyWith(
- color: Colors.white, fontSize: 35.93, fontWeight: FontWeight.w700);
- final children = <Widget>[
- DefaultTextStyle(
- style: const TextStyle(
- fontSize: 17.42,
- color: Colors.white,
- ),
- child: title),
- const SizedBox(height: 6)
- ];
- if (content != null) {
- children.add(
- DefaultTextStyle(
- style: const TextStyle(
- fontSize: 15.24,
- color: Colors.white,
- ),
- child: content!),
- );
- }
- final actions = <Widget>[];
- actions.add(OutlinedButton(
- onPressed: onCancel ?? () => Get.back(),
- child: Text(onCancelText ?? '取消')));
- if (onConfirm != null) {
- actions.add(FilledButton(
- onPressed: onConfirm, child: Text(onConfirmText ?? '确定')));
- }
- var ali = MainAxisAlignment.center;
- if (actions.length > 1) {
- ali = MainAxisAlignment.spaceBetween;
- }
- children.add(SizedBox(
- width: 220,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(15, 22, 15, 0),
- child: Row(
- mainAxisAlignment: ali,
- children: actions,
- ))));
- return Stack(alignment: Alignment.center, children: [
- Card(
- color: Colors.transparent,
- surfaceTintColor: Colors.transparent,
- shadowColor: Colors.transparent,
- child: Container(
- decoration: BoxDecoration(
- color: const Color(0x70000000),
- borderRadius: BorderRadius.circular(7.62)),
- padding: const EdgeInsets.all(15),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: children,
- )))
- ]);
- }
- }
- class _Empty extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- _showDialog();
- return const Scaffold();
- }
- }
- Future<void> _showDialog() async {
- await Future.delayed(2.seconds);
- if (Get.isOverlaysOpen) {
- Get.back();
- }
- Get.dialog(AppDialog(
- onConfirm: () {},
- onCancel: () {},
- title: const Text('退出比赛'),
- content: const Text('是否强制结束?'),
- onCancelText: '否',
- onConfirmText: '是',
- ));
- }
- void main() async {
- runApp(GetMaterialApp(theme: appThemeData(), home: _Empty()));
- }
|