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),
          ),
相关推荐
IT陈图图4 分钟前
优雅管理,智慧阅读:基于 Flutter × OpenHarmony 构建图书馆读者列表模块
flutter·华为·鸿蒙·openharmony
2401_zq136y039 分钟前
Flutter for OpenHarmony:从零搭建今日资讯App(二十九)深色模式适配全攻略
flutter
时光慢煮26 分钟前
从零构建跨端图书馆管理页面:Flutter × OpenHarmony 实战指南-架构搭建
flutter·开源·openharmony
向前V33 分钟前
Flutter for OpenHarmony数独游戏App实战:单元格交互与选中
flutter·游戏·交互
小白阿龙39 分钟前
鸿蒙+flutter 跨平台开发——简易井字棋小游戏实现
flutter·华为·harmonyos·鸿蒙
夜雨声烦丿42 分钟前
Flutter 框架跨平台鸿蒙开发 - 打造随机抽奖/点名器应用
flutter·华为·harmonyos
时光慢煮1 小时前
Flutter 编译开发 OpenHarmony 全流程实战教程-基于开源仓库GitCode 搜索工具 v1.0.3 的跨平台实践
flutter·开源·gitcode
小白阿龙1 小时前
鸿蒙+flutter 跨平台开发——Placeholder 控件的基础使用场景
flutter·华为·harmonyos·鸿蒙
时光慢煮1 小时前
基于 Flutter × OpenHarmony 图书馆管理系统之构建书籍管理模块
flutter·华为·开源·openharmony
IT陈图图1 小时前
智慧图书馆的数字名片:基于 Flutter × OpenHarmony 的读者卡片构建实践
flutter·鸿蒙·openharmony