905086
2026-11-09 cbb26873e88a7a13e868448c1cc578ce70b8c6ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import 'package:flutter/material.dart';
import 'package:fluttergamebox/api/api_service.dart';
import 'package:fluttergamebox/common/theme.dart';
import 'package:fluttergamebox/store/app_state.dart';
import 'package:fluttergamebox/utils/util.dart';
 
/// 会员激活弹窗
void showActivateDialog(BuildContext context) {
  showDialog(
    context: context,
    barrierColor: Colors.black54,
    builder: (context) => const _ActivateDialog(),
  );
}
 
class _ActivateDialog extends StatefulWidget {
  const _ActivateDialog();
  @override
  State<_ActivateDialog> createState() => _ActivateDialogState();
}
 
class _ActivateDialogState extends State<_ActivateDialog> {
  final _codeCtrl = TextEditingController();
  bool _loading = false;
 
  Future<void> _activate() async {
    final code = _codeCtrl.text.trim();
    if (code.isEmpty) {
      _tip('请输入您的激活码!', error: true);
      return;
    }
    setState(() => _loading = true);
    try {
      final machine = await getMachineCode();
      final res = await ApiService.activateKey(code, machine);
      if (!mounted) return;
      if (res['code'] == 0) {
        await AppState.instance.refreshUserInfo();
        if (mounted) {
          _tip(res['msg'] ?? '激活成功');
          Future.delayed(const Duration(milliseconds: 1200), () {
            if (mounted) Navigator.pop(context);
          });
        }
      } else {
        _tip(res['msg'] ?? '激活失败', error: true);
      }
    } catch (e) {
      _tip('网络错误,请稍后重试', error: true);
    } finally {
      if (mounted) setState(() => _loading = false);
    }
  }
 
  void _tip(String msg, {bool error = false}) {
    final overlay = Overlay.of(context);
    final entry = OverlayEntry(
      builder: (context) => Positioned(
        top: 60,
        left: MediaQuery.of(context).size.width / 2 - 140,
        child: Material(
          color: Colors.transparent,
          child: Container(
            width: 280,
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
            decoration: BoxDecoration(
              color: error ? AppColors.red : AppColors.green,
              borderRadius: BorderRadius.circular(6),
            ),
            child: Row(
              children: [
                Icon(error ? Icons.error_outline : Icons.check_circle,
                    color: Colors.white, size: 18),
                const SizedBox(width: 8),
                Expanded(
                  child: Text(msg,
                      style: const TextStyle(color: Colors.white, fontSize: 13)),
                ),
              ],
            ),
          ),
        ),
      ),
    );
    overlay.insert(entry);
    Future.delayed(const Duration(seconds: 2), () => entry.remove());
  }
 
  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.white,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
      child: Container(
        width: 400,
        padding: const EdgeInsets.all(24),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Container(
                  padding: const EdgeInsets.all(4),
                  decoration: BoxDecoration(
                    color: AppColors.accent,
                    shape: BoxShape.circle,
                  ),
                  child: const Icon(Icons.vpn_key,
                      color: Colors.white, size: 14),
                ),
                const SizedBox(width: 8),
                const Text('会员激活',
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 16,
                        fontWeight: FontWeight.bold)),
                const Spacer(),
                GestureDetector(
                  onTap: () => Navigator.pop(context),
                  child: const Icon(Icons.close, color: Colors.grey, size: 18),
                ),
              ],
            ),
            const SizedBox(height: 18),
            Container(
              width: double.infinity,
              padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
              decoration: BoxDecoration(
                color: const Color(0xFFE8F1FF),
                borderRadius: BorderRadius.circular(4),
              ),
              child: const Text('请输入您的激活码!',
                  style: TextStyle(
                      color: Color(0xFF2B7FFF), fontSize: 13)),
            ),
            const SizedBox(height: 16),
            const Text('激活码',
                style: TextStyle(color: Color(0xFF666666), fontSize: 13)),
            const SizedBox(height: 8),
            TextField(
              controller: _codeCtrl,
              style: const TextStyle(color: Color(0xFF333333), fontSize: 14),
              decoration: InputDecoration(
                hintText: 'XXXX-XXXX-XXXX-XXXX (右键粘贴)',
                hintStyle: const TextStyle(
                    color: Color(0xFFAAAAAA), fontSize: 13),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(4),
                  borderSide: const BorderSide(color: Color(0xFFDDDDDD)),
                ),
                contentPadding:
                    const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
              ),
            ),
            const SizedBox(height: 24),
            Row(
              children: [
                Expanded(
                  child: OutlinedButton(
                    onPressed: () => Navigator.pop(context),
                    style: OutlinedButton.styleFrom(
                      foregroundColor: Color(0xFF666666),
                      side: const BorderSide(color: Color(0xFFDDDDDD)),
                      padding: const EdgeInsets.symmetric(vertical: 12),
                    ),
                    child: const Text('取消'),
                  ),
                ),
                const SizedBox(width: 12),
                Expanded(
                  child: ElevatedButton(
                    onPressed: _loading ? null : _activate,
                    style: ElevatedButton.styleFrom(
                      backgroundColor: AppColors.accent,
                      foregroundColor: Colors.white,
                      padding: const EdgeInsets.symmetric(vertical: 12),
                    ),
                    child: _loading
                        ? const SizedBox(
                            width: 16,
                            height: 16,
                            child: CircularProgressIndicator(
                                strokeWidth: 2, color: Colors.white))
                        : const Text('激活'),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}