flutter---进度条(3)

效果图

垂直音量进度条

1.定义变量

Dart 复制代码
double _sliderValue9 = 0.65;

2.构造垂直音量条

Dart 复制代码
Widget _buildVerticalSliderCard({
    required String title, //卡片标题
    required double value, //当前值
    required ValueChanged<double> onChanged, //值变化回调
  }) {
    return Container(
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: const Color(0xFF1E293B),
        borderRadius: BorderRadius.circular(12),
        border: Border.all(color: Colors.white.withOpacity(0.1)),
      ),
      child: Column(
        children: [

          //标题
          Text(
            title,
            style: const TextStyle(
              color: Colors.white,
              fontSize: 14,
              fontWeight: FontWeight.w500,
            ),
          ),
          const SizedBox(height: 16),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [

              //垂直滑块区域
              SizedBox(
                height: 200, //固定宽高
                width: 60,
                child: RotatedBox( //旋转盒子(关键)
                  quarterTurns: 3, //旋转270度
                  //进度条核心
                  child: SliderTheme(
                    data: SliderThemeData(
                      trackHeight: 12, //轨道高度
                      thumbShape: const RoundSliderThumbShape(
                        enabledThumbRadius: 10, //滑块半径
                      ),
                      activeTrackColor: const Color(0xFF1E40AF), //激活颜色
                      inactiveTrackColor: Colors.white.withOpacity(0.1),//未激活颜色
                      thumbColor: Colors.white,
                    ),
                    child: Slider(
                      value: value,
                      onChanged: onChanged,
                    ),
                  ),
                ),
              ),
              const SizedBox(width: 20),
              //可视化进度容器
              Column(
                children: [
                  Container(
                    width: 80,
                    height: 180,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8),
                      border: Border.all(color: Colors.white.withOpacity(0.2)),
                    ),
                    child: Stack(
                      children: [
                        // 背景
                        Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(8),
                            color: Colors.white.withOpacity(0.05),
                          ),
                        ),
                        // 填充
                        Positioned(
                          bottom: 0,
                          child: AnimatedContainer(
                            duration: const Duration(milliseconds: 300),
                            width: 80,
                            height: 180 * value, //动态高度:总高度x进度值
                            decoration: BoxDecoration(
                              borderRadius: const BorderRadius.only(
                                bottomLeft: Radius.circular(8),
                                bottomRight: Radius.circular(8),
                              ),
                              gradient: LinearGradient(
                                begin: Alignment.bottomCenter,
                                end: Alignment.topCenter,
                                colors: [
                                  const Color(0xFF1E40AF),
                                  const Color(0xFF3B82F6),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(height: 8),
                  Text(
                    '${(value * 100).toInt()}%',
                    style: const TextStyle(
                      color: Colors.white,
                      fontSize: 16,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ],
      ),
    );
  }

3.使用垂直音量条

Dart 复制代码
         _buildVerticalSliderCard(
            title: '垂直音量条',
            value: _sliderValue9,
            onChanged: (value) => setState(() => _sliderValue9 = value),
          ),
相关推荐
恋猫de小郭1 天前
Amper 正式转正 Kotlin Toolchain ,Gradle 未来何去何从
android·前端·flutter
张风捷特烈1 天前
Flutter 类库大揭秘#02 | path_provider 各平台实现
前端·flutter
TT_Close2 天前
别劝退了!5秒搞定 Flutter 鸿蒙 FVM 起跑线
flutter·harmonyos·visual studio code
你听得到112 天前
用户说 App 卡,但说不清在哪?我把 Flutter 监控 SDK 升级成了链路观测工作台
前端·flutter·性能优化
stringwu4 天前
Flutter 开发必备:MVI 架构的高效实现指南
前端·flutter
程序员老刘5 天前
Flutter版本选择指南:3.44系列继续观望 | 2026年6月
flutter·ai编程·客户端
用户965597361906 天前
Provider vs Bloc vs GetX vs Riverpod:Flutter 状态管理方案怎么选?
flutter
恋猫de小郭6 天前
Flutter Patchwork,不用 Fork 改依赖包源码的第三方工具
android·前端·flutter
程序员老刘7 天前
跑分第一的编程大模型,我为啥不用?
flutter·ai编程·vibecoding
恋猫de小郭7 天前
苹果 AirPods 协议,Android 也可以使用完整版 AirPods 能力
android·前端·flutter