| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- import 'package:flutter/material.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- import 'package:gobang/themes/app_colors.dart';
- class TipsDialog {
- static Future<void> show(
- BuildContext context,
- String title,
- String tips,
- ) {
- return showGeneralDialog<void>(
- context: context,
- barrierDismissible: false,
- barrierLabel: 'dialog',
- barrierColor: const Color(0xB0070D10),
- transitionDuration: const Duration(milliseconds: 280),
- pageBuilder: (ctx, a1, a2) {
- return const SizedBox.shrink();
- },
- transitionBuilder: (ctx, anim, _, __) {
- final curved = CurvedAnimation(parent: anim, curve: Curves.easeOutBack);
- return FadeTransition(
- opacity: anim,
- child: ScaleTransition(
- scale: Tween(begin: 0.88, end: 1.0).animate(curved),
- child: Center(
- child: Material(
- color: Colors.transparent,
- child: Container(
- width: MediaQuery.of(ctx).size.width * 0.82,
- padding: const EdgeInsets.fromLTRB(24, 28, 24, 20),
- decoration: BoxDecoration(
- color: AppColors.ivory,
- borderRadius: BorderRadius.circular(28),
- boxShadow: [
- BoxShadow(
- color: Colors.black.withValues(alpha: 0.28),
- blurRadius: 40,
- offset: const Offset(0, 16),
- ),
- ],
- ),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Container(
- width: 64,
- height: 64,
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- gradient: LinearGradient(
- colors: title.contains('恭喜')
- ? const [
- AppColors.pumpkinSoft,
- AppColors.pumpkin,
- ]
- : const [Color(0xFF4A4A4A), Color(0xFF1A1A1A)],
- ),
- ),
- ),
- const SizedBox(height: 16),
- Text(
- title,
- style: const TextStyle(
- color: AppColors.ink,
- fontSize: 24,
- fontWeight: FontWeight.w800,
- ),
- ),
- const SizedBox(height: 8),
- Text(
- tips,
- textAlign: TextAlign.center,
- style: const TextStyle(
- color: Color(0xFF5A736A),
- fontSize: 14,
- height: 1.4,
- ),
- ),
- const SizedBox(height: 20),
- SizedBox(
- width: double.infinity,
- child: FilledButton(
- style: FilledButton.styleFrom(
- backgroundColor: title.contains('恭喜')
- ? AppColors.ink
- : AppColors.pumpkin,
- foregroundColor: AppColors.ivory,
- padding: const EdgeInsets.symmetric(vertical: 14),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(14),
- ),
- ),
- onPressed: () => Navigator.of(ctx).pop(),
- child: Text(
- title.contains('恭喜') ? '再来一局' : '确定',
- style: const TextStyle(fontWeight: FontWeight.w700),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- );
- },
- );
- }
- static Future<bool?> showByChoose(
- BuildContext context,
- String title,
- String tips,
- String yes,
- String no,
- ) {
- return showGeneralDialog<bool>(
- context: context,
- barrierDismissible: false,
- barrierLabel: 'choose',
- barrierColor: const Color(0x99070D10),
- transitionDuration: const Duration(milliseconds: 240),
- pageBuilder: (ctx, a1, a2) => const SizedBox.shrink(),
- transitionBuilder: (ctx, anim, _, __) {
- return FadeTransition(
- opacity: anim,
- child: ScaleTransition(
- scale: Tween(begin: 0.92, end: 1.0).animate(
- CurvedAnimation(parent: anim, curve: Curves.easeOutCubic),
- ),
- child: Center(
- child: Material(
- color: Colors.transparent,
- child: Container(
- width: MediaQuery.of(ctx).size.width * 0.8,
- padding: const EdgeInsets.all(24),
- decoration: BoxDecoration(
- color: AppColors.ivory,
- borderRadius: BorderRadius.circular(24),
- ),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- title,
- style: const TextStyle(
- color: AppColors.ink,
- fontSize: 20,
- fontWeight: FontWeight.w800,
- ),
- ),
- const SizedBox(height: 10),
- Text(
- tips,
- textAlign: TextAlign.center,
- style: const TextStyle(
- color: Color(0xFF5A736A),
- fontSize: 14,
- ),
- ),
- const SizedBox(height: 20),
- Row(
- children: [
- Expanded(
- child: TextButton(
- style: TextButton.styleFrom(
- backgroundColor: AppColors.mist,
- foregroundColor: AppColors.ink,
- padding:
- const EdgeInsets.symmetric(vertical: 12),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- ),
- ),
- onPressed: () => Navigator.of(ctx).pop(false),
- child: Text(no),
- ),
- ),
- const SizedBox(width: 12),
- Expanded(
- child: FilledButton(
- style: FilledButton.styleFrom(
- backgroundColor: title.contains('投降')
- ? AppColors.pumpkin
- : AppColors.ink,
- foregroundColor: AppColors.ivory,
- padding:
- const EdgeInsets.symmetric(vertical: 12),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- ),
- ),
- onPressed: () => Navigator.of(ctx).pop(true),
- child: Text(yes),
- ),
- ),
- ],
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- );
- },
- );
- }
- static void toast(String message) {
- Fluttertoast.showToast(msg: message, gravity: ToastGravity.CENTER);
- }
- }
|