Flutter 颤振滑块标签重叠解决方法

Flutter 颤振滑块标签重叠解决方法,flutter,flutter-layout,Flutter,Flutter Layout,有一个打开的:滑块。标签引出序号放置在屏幕顶部附近时部分重叠: 在问题评论中,讨论了如何修复该问题。但在修复可用之前,我不知道如何实现解决方案 在我的应用程序中,我在滑块上方添加了一个容器,但当滑块位于可滚动的列表视图中时,它仍然重叠: 因此,欢迎任何想法,最好使用代码。这不是一个解决方案,而是一个棘手的问题 当我看到问题时,我使用一个FloatingActionButton.extended,在其标签内不显示滑块值。 (您可以更改浮动操作按钮的标签位置) 主要过程包括使actionButt

有一个打开的:
滑块。标签
引出序号放置在屏幕顶部附近时部分重叠:

在问题评论中,讨论了如何修复该问题。但在修复可用之前,我不知道如何实现解决方案

在我的应用程序中,我在
滑块
上方添加了一个
容器
,但当
滑块
位于可滚动的
列表视图
中时,它仍然重叠:


因此,欢迎任何想法,最好使用代码。

这不是一个解决方案,而是一个棘手的问题

当我看到问题时,我使用一个FloatingActionButton.extended,在其标签内不显示滑块值。
(您可以更改浮动操作按钮的标签位置)

主要过程包括使actionButton可见或不可见,在其标签内加载滑块值。
这是代码的一部分,加上变为垂直线的勾号:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

@override
  Widget build(BuildContext context) {
    return MaterialApp(
  title: 'Flutter Demo Custom Slider',
    debugShowCheckedModeBanner: false,
  theme: ThemeData(
    brightness: Brightness.dark,
    primarySwatch: Colors.blue,
  ),
  home: MyHomePage(title: 'Flutter Demo Custom Slider'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class tickMark_Line_Heigth extends SliderTickMarkShape {
  final double alturaTick;
  final double anchuraTick = 3;

  const tickMark_Line_Heigth(this.alturaTick);

  @override
  Size getPreferredSize({SliderThemeData sliderTheme, bool isEnabled}) {
    return Size.fromRadius(alturaTick);
  }

  @override
  void paint(PaintingContext context, Offset center,
      {RenderBox parentBox,
      SliderThemeData sliderTheme,
      Animation<double> enableAnimation,
      Offset thumbCenter,
      bool isEnabled,
      TextDirection textDirection}) {
    final Canvas canvas = context.canvas;

    final paint = Paint()
      ..color = Colors.yellowAccent
      ..style = PaintingStyle.fill;

    Offset centro = Offset(center.dx + 2, center.dy - alturaTick * 2);
    Rect puntos = centro & Size(anchuraTick, alturaTick * 4);
    canvas.drawRect(puntos, paint);
  }
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
            Expanded(
              child: slider(0),
              flex: 1,
            ),
            Expanded(
              child: slider(1),
              flex: 1,
            ),
            Expanded(
              child: slider(2),
              flex: 1,
        ),
            Expanded(
              child: slider(3),
              flex: 1,
            ),
            Expanded(
              child: slider(4),
              flex: 1,
            ),
            Expanded(
              child: slider(5),
              flex: 1,
            ),
            Expanded(
              child: slider(6),
              flex: 1,
            ),
            Expanded(
              child: slider(7),
              flex: 1,
            ),
           ],
        ),
      ),
      floatingActionButton: visibleActionButton
          ? FloatingActionButton.extended(
              onPressed: () {
                // Add your onPressed code here!
              },
              label: Row(
            children: <Widget>[
              Column(
                children: <Widget>[
                  Text('Slide',style: TextStyle(fontSize: 10)),
                  Text('$numSlider',style: TextStyle(fontSize: 10)),
                ],
              ),
              Text('$valueSlider',style: TextStyle(fontSize: 30)),
            ],
          ),
    backgroundColor: colorSlider(valueSlider),
  )
      : null,
  floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
    );
  }

  var valuesSlider = [0, 0, 0, 0, 0, 0, 0, 0];
  int valueSlider = 0;
  int numSlider = 0;
  bool visibleActionButton = false;

  Color colorSlider(valor) {
    Color color;
    switch (valor) {
      case 0:
      case 1:
        color = Colors.green;
        break;
      case 2:
      case 3:
        color = Colors.orange;
        break;
      default:
        color = Colors.red;
    }
    return color;
  }

  Widget slider(num) {
    return SliderTheme(
      data: SliderTheme.of(context).copyWith(
          trackHeight: 18,
          minThumbSeparation: 1,
          tickMarkShape: tickMark_Line_Heigth(4)),
      child: Slider(
        value: valuesSlider[num].toDouble(),
        min: 0,
        max: 5,
        divisions: 5,
        activeColor: colorSlider(valuesSlider[num]),
        inactiveColor: Colors.lightBlue,
        label: '${valuesSlider[num]}',
        onChangeStart: (newValue) {
          setState(() {
            valueSlider = newValue.round();
            numSlider = num + 1;
            visibleActionButton = true;
          });
        },
        onChangeEnd: (newValue) {
          setState(() {
            valueSlider = 0;
            visibleActionButton = false;
          });
        },
        onChanged: (newValue) {
          setState(() {
            valuesSlider[num] = newValue.round();
            valueSlider = newValue.round();
          });
        },
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示自定义滑块”,
debugShowCheckedModeBanner:false,
主题:主题数据(
亮度:亮度。暗,
主样本:颜色。蓝色,
),
主页:MyHomePage(标题:“颤振演示自定义滑块”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类标记线高度扩展滑块标记形状{
最终双交替;
最终双固定点=3;
恒刻度线高度(此为alturaTick);
@凌驾
大小getPreferredSize({SliderThemeData sliderTheme,bool isEnabled}){
返回大小.fromRadius(alturaTick);
}
@凌驾
空白绘制(绘制上下文、偏移中心、,
{RenderBox parentBox,
SliderThemeData sliderTheme,
动画制作,
偏移拇指中心,
布尔被捕了,
text方向(text方向}){
最终画布=context.Canvas;
最终油漆=油漆()
…color=Colors.yellowAccent
..风格=绘画风格。填充;
偏移中心=偏移(center.dx+2,center.dy-alturaTick*2);
矩形平顶=中心和尺寸(固定座,固定座*4);
画布。drawRect(puntos,油漆);
}
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:中(
//中心是一个布局小部件。它接受一个子元素并对其进行定位
/在父母的中间。
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
扩大(
子:滑块(0),
弹性:1,
),
扩大(
子项:滑块(1),
弹性:1,
),
扩大(
子项:滑块(2),
弹性:1,
),
扩大(
子项:滑块(3),
弹性:1,
),
扩大(
子项:滑块(4),
弹性:1,
),
扩大(
子项:滑块(5),
弹性:1,
),
扩大(
子:滑块(6),
弹性:1,
),
扩大(
子:滑块(7),
弹性:1,
),
],
),
),
浮动操作按钮:visibleActionButton
?浮动操作按钮。扩展(
已按下:(){
//在这里添加你的密码!
},
标签:Row(
儿童:[
纵队(
儿童:[
文本(“幻灯片”,样式:TextStyle(字体大小:10)),
文本(“$numSlider”,样式:TextStyle(fontSize:10)),
],
),
文本(“$valueSlider”,样式:TextStyle(fontSize:30)),
],
),
背景颜色:colorSlider(valueSlider),
)
:null,
floatingActionButtonLocation:floatingActionButtonLocation.endTop,
);
}
var valuesSlider=[0,0,0,0,0,0,0];
int-valueSlider=0;
int numSlider=0;
bool visibleActionButton=false;
颜色滑块(valor){
颜色;
开关(valor){
案例0:
案例1:
颜色=颜色。绿色;
打破
案例2:
案例3:
颜色=颜色。橙色;
打破
违约:
颜色=颜色。红色;
}
返回颜色;
}
小部件滑块(num){
返回滑块主题(
数据:SliderTheme.of(context).copyWith(
轨高:18,
三是分离:1,,
勾号形状:勾号线高度(4)),
子:滑块(
值:valuesSlider[num]。toDouble(),
分:0,,
最高:5,
分部:5,
activeColor:colorSlider(值滑动器[num]),
不活动颜色:颜色。浅蓝色,
标签:“${valuesSlider[num]}”,
onChangeStart:(newValue){
设置状态(){
valueSlider=newValue.round();
numSlider=num+1;
visibleActionButton=true;
});
},
onChangeEnd:(newValue){
设置状态(){
valueSlider=0;
visibleActionButton=false;
});
},
一旦更改:(newValue){
设置状态(){
valuesSlider[num]=newValue.round();
valueSlider=newValue.round();
});
},
),
);
}
}

这不是一个解决方案,而是一个棘手的问题

当我看到问题时,我使用一个FloatingActionButton.extended,在其标签内不显示滑块值。
(您可以更改