348 lines
9.7 KiB
Dart
348 lines
9.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
/// 挖矿状态枚举
|
|
enum MiningStatus {
|
|
pending, // 待开启
|
|
mining, // 挖矿中
|
|
paused, // 已暂停
|
|
}
|
|
|
|
/// 矿机页面 - 显示挖矿状态和控制
|
|
/// 展示用户序列号、社区信息和挖矿开关
|
|
class MiningPage extends ConsumerStatefulWidget {
|
|
const MiningPage({super.key});
|
|
|
|
@override
|
|
ConsumerState<MiningPage> createState() => _MiningPageState();
|
|
}
|
|
|
|
class _MiningPageState extends ConsumerState<MiningPage> {
|
|
// 当前挖矿状态
|
|
MiningStatus _miningStatus = MiningStatus.pending;
|
|
|
|
// 模拟用户数据
|
|
final String _serialNumber = '12345';
|
|
final String _community = '星空社区';
|
|
final String _province = '广东';
|
|
final String _city = '深圳';
|
|
|
|
/// 显示帮助信息
|
|
void _showHelpInfo() {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('矿机说明'),
|
|
content: const Text('矿机是您参与挖矿的核心工具。\n\n'
|
|
'开启挖矿后,您将开始获得收益。\n\n'
|
|
'收益与您的算力和团队规模相关。'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('知道了'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 切换挖矿状态
|
|
void _toggleMining() {
|
|
setState(() {
|
|
if (_miningStatus == MiningStatus.pending) {
|
|
_miningStatus = MiningStatus.mining;
|
|
} else if (_miningStatus == MiningStatus.mining) {
|
|
_miningStatus = MiningStatus.paused;
|
|
} else {
|
|
_miningStatus = MiningStatus.mining;
|
|
}
|
|
});
|
|
}
|
|
|
|
/// 获取状态文本
|
|
String _getStatusText() {
|
|
switch (_miningStatus) {
|
|
case MiningStatus.pending:
|
|
return '挖矿待开启';
|
|
case MiningStatus.mining:
|
|
return '挖矿中';
|
|
case MiningStatus.paused:
|
|
return '挖矿已暂停';
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [
|
|
Color(0xFFFFF5E6),
|
|
Color(0xFFFFE4B5),
|
|
],
|
|
),
|
|
),
|
|
child: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
// 顶部标题栏
|
|
_buildAppBar(),
|
|
// 用户信息区域
|
|
_buildUserInfo(),
|
|
const SizedBox(height: 24),
|
|
// 挖矿状态区域
|
|
Expanded(
|
|
child: _buildMiningStatusArea(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 构建顶部标题栏
|
|
Widget _buildAppBar() {
|
|
return Container(
|
|
height: 56,
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
children: [
|
|
// 占位
|
|
const SizedBox(width: 48),
|
|
// 标题
|
|
const Expanded(
|
|
child: Text(
|
|
'矿机',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontFamily: 'Inter',
|
|
fontWeight: FontWeight.w700,
|
|
height: 1.25,
|
|
letterSpacing: -0.27,
|
|
color: Color(0xFF5D4037),
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
// 帮助按钮
|
|
GestureDetector(
|
|
onTap: _showHelpInfo,
|
|
child: Container(
|
|
width: 48,
|
|
height: 48,
|
|
alignment: Alignment.center,
|
|
child: Container(
|
|
width: 24,
|
|
height: 24,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(
|
|
color: const Color(0xFF8B5A2B),
|
|
width: 2,
|
|
),
|
|
),
|
|
child: const Center(
|
|
child: Text(
|
|
'i',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
color: Color(0xFF8B5A2B),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 构建用户信息区域
|
|
Widget _buildUserInfo() {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
children: [
|
|
// 头像
|
|
Container(
|
|
width: 80,
|
|
height: 80,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(40),
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: [
|
|
Color(0xFFFF6B6B),
|
|
Color(0xFFFFE66D),
|
|
Color(0xFF4ECDC4),
|
|
],
|
|
),
|
|
),
|
|
child: const Center(
|
|
child: Icon(
|
|
Icons.person,
|
|
size: 40,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
// 用户信息
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'序列号$_serialNumber',
|
|
style: const TextStyle(
|
|
fontSize: 20,
|
|
fontFamily: 'Inter',
|
|
fontWeight: FontWeight.w700,
|
|
height: 1.25,
|
|
letterSpacing: -0.3,
|
|
color: Color(0xFF5D4037),
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'社区: $_community / 省市: $_province · $_city',
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontFamily: 'Inter',
|
|
height: 1.5,
|
|
color: Color(0xFF8B5A2B),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 构建挖矿状态区域
|
|
Widget _buildMiningStatusArea() {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
color: const Color(0x66FFFFFF),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
// 挖矿开关按钮
|
|
GestureDetector(
|
|
onTap: _toggleMining,
|
|
child: Container(
|
|
width: 100,
|
|
height: 100,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: _miningStatus == MiningStatus.mining
|
|
? const Color(0xFFD4AF37)
|
|
: Colors.transparent,
|
|
border: Border.all(
|
|
color: _miningStatus == MiningStatus.mining
|
|
? const Color(0xFFD4AF37)
|
|
: const Color(0xFFD4AF37).withOpacity(0.5),
|
|
width: 3,
|
|
),
|
|
),
|
|
child: Icon(
|
|
Icons.power_settings_new,
|
|
size: 48,
|
|
color: _miningStatus == MiningStatus.mining
|
|
? Colors.white
|
|
: const Color(0xFFD4AF37).withOpacity(0.5),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
// 状态文本
|
|
Text(
|
|
_getStatusText(),
|
|
style: const TextStyle(
|
|
fontSize: 18,
|
|
fontFamily: 'Inter',
|
|
fontWeight: FontWeight.w500,
|
|
height: 1.56,
|
|
color: Color(0xFF8B5A2B),
|
|
),
|
|
),
|
|
// 挖矿中显示额外信息
|
|
if (_miningStatus == MiningStatus.mining) ...[
|
|
const SizedBox(height: 24),
|
|
_buildMiningStats(),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 构建挖矿统计信息
|
|
Widget _buildMiningStats() {
|
|
return Container(
|
|
padding: const EdgeInsets.all(16),
|
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0x33D4AF37),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildStatRow('个人算力', '100 H/s'),
|
|
const SizedBox(height: 8),
|
|
_buildStatRow('团队算力', '1,000 H/s'),
|
|
const SizedBox(height: 8),
|
|
_buildStatRow('今日收益', '0.00 DST'),
|
|
const SizedBox(height: 8),
|
|
_buildStatRow('累计收益', '0.00 DST'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 构建统计行
|
|
Widget _buildStatRow(String label, String value) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontFamily: 'Inter',
|
|
height: 1.5,
|
|
color: Color(0xFF8B5A2B),
|
|
),
|
|
),
|
|
Text(
|
|
value,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontFamily: 'Inter',
|
|
fontWeight: FontWeight.w600,
|
|
height: 1.5,
|
|
color: Color(0xFF5D4037),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|