import 'package:flutter/material.dart'; import 'panel_toggle_affordance.dart'; class SpeedButton extends StatelessWidget { final double currentRate; final bool isPanelOpen; final VoidCallback onTogglePanel; const SpeedButton({ super.key, required this.currentRate, required this.isPanelOpen, required this.onTogglePanel, }); static const speeds = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0]; static String formatRate(double rate) { return rate == rate.roundToDouble() ? '${rate.toInt()}x' : '${rate}x'; } @override Widget build(BuildContext context) { return PanelToggleAffordance( isOpen: isPanelOpen, onTap: onTogglePanel, tooltip: '播放速度', child: Text( formatRate(currentRate), style: const TextStyle( color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500, fontFeatures: [FontFeature.tabularFigures()], ), ), ); } }