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),
          ),
相关推荐
花开彼岸天~1 小时前
Flutter跨平台开发鸿蒙化定位组件使用指南
flutter·华为·harmonyos
hudawei9964 小时前
flutter路由传参接收时机
开发语言·flutter·异步
花开彼岸天~6 小时前
Flutter跨平台开发鸿蒙化日志测试组件使用指南
flutter·elasticsearch·harmonyos
昼-枕7 小时前
【实战分享】我用Flutter为小餐馆开发的点餐系统
flutter
开心-开心急了7 小时前
ai + fluent_ui 实现自定义winUI风格窗口
flutter·ui
儿歌八万首8 小时前
Flutter自定义组件: 为横向列表自定义“进度条”式滚动指示器
flutter
PWRJOY11 小时前
【flutter】项目配置文件 pubspec.yaml
flutter
徐安安ye13 小时前
Flutter 与 Rust 混合开发:打造毫秒级响应的高性能计算引擎
开发语言·flutter·rust
xianjixiance_1 天前
Flutter跨平台三方库鸿蒙化适配指南
flutter·华为·harmonyos
SoaringHeart1 天前
Flutter组件封装:视频播放组件全局封装
前端·flutter