138 lines
4.5 KiB
Dart
138 lines
4.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:fl_chart/fl_chart.dart';
|
|
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/home_entity.dart';
|
|
|
|
class PowerCard extends StatelessWidget {
|
|
final HomeEntity data;
|
|
|
|
const PowerCard({super.key, required this.data});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
height: 140,
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
colors: [
|
|
Color(0xFF165DFF),
|
|
Color(0xFF4080FF),
|
|
Color(0xFF7CB3FF),
|
|
Color(0xFFB8D4FF),
|
|
],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
color: Color(0x0D000000),
|
|
blurRadius: 4,
|
|
offset: Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 12, 16),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Text(
|
|
'实时发电功率',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Flexible(
|
|
child: Text(
|
|
data.realTimePower.toStringAsFixed(1),
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 32,
|
|
fontWeight: FontWeight.bold,
|
|
height: 1.0,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
const Padding(
|
|
padding: EdgeInsets.only(bottom: 4),
|
|
child: Text(
|
|
'kW',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
IconButton(
|
|
icon: const Icon(Icons.more_horiz, size: 20, color: Colors.white),
|
|
onPressed: () => print('点击更多'),
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints(),
|
|
),
|
|
],
|
|
),
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 70,
|
|
child: LineChart(
|
|
LineChartData(
|
|
gridData: const FlGridData(show: false),
|
|
titlesData: const FlTitlesData(show: false),
|
|
borderData: FlBorderData(show: false),
|
|
lineBarsData: [
|
|
LineChartBarData(
|
|
spots: _generateSpots(),
|
|
isCurved: true,
|
|
color: Colors.white,
|
|
barWidth: 1.5,
|
|
dotData: const FlDotData(show: false),
|
|
belowBarData: BarAreaData(
|
|
show: true,
|
|
color: Colors.white.withOpacity(0.2),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<FlSpot> _generateSpots() {
|
|
return data.powerTrendData
|
|
.asMap()
|
|
.entries
|
|
.map((e) => FlSpot(e.key.toDouble(), e.value.power))
|
|
.toList();
|
|
}
|
|
}
|