gpt4 book ai didi

flutter - 如何在 Flutter 中制作这个自定义的 RangeSlider?

转载 作者:行者123 更新时间:2023-12-03 03:21:51 28 4
gpt4 key购买 nike

我想制作一个如下所示的自定义范围 slider :

Expected result

但是,我试过了,但我的 RangeSlider 看起来像:

enter image description here

我的代码:

                      data: SliderTheme.of(context).copyWith(
trackShape: RectangularSliderTrackShape(),
trackHeight: 2.0,
thumbShape:
RoundSliderThumbShape(enabledThumbRadius: 9.0),
overlayShape:
RoundSliderOverlayShape(overlayRadius: 18.0),
valueIndicatorShape: RoundSliderOverlayShape(),
valueIndicatorColor: Color(0xffF5F5F5),
valueIndicatorTextStyle:
TextStyle(color: Color(0xff7E3338), fontSize: 14.0),
rangeThumbShape: RoundRangeSliderThumbShape(),
rangeValueIndicatorShape:
PaddleRangeSliderValueIndicatorShape(),
),
child: RangeSlider(
values: selectedRange,
min: 0.0,
max: 50000.0,
semanticFormatterCallback: (RangeValues rangeValues) {
return '${rangeValues.start.round()} - ${rangeValues.end.round()} dollars';
},
//added talk back feature for android
labels: RangeLabels(
'${selectedRange.start}', '${selectedRange.end}'),
activeColor: Color(0xff7E3338),
inactiveColor: Color(0xffD7D8DD),
onChanged: (RangeValues newRange) {
setState(() => selectedRange = newRange);
},
),
),

我可以在代码中做哪些不同的事情来获得预期的输出?

最佳答案

请检查此插件,您可以根据需要在其中自定义 slider 我已经根据上述图像创建了示例。但您可以根据需要对其进行自定义。

插件:https://pub.dev/packages/flutter_xlider

检查下面的代码:

import 'package:flutter/material.dart';
import 'package:flutter_xlider/flutter_xlider.dart';

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

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
//
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

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

final String title;

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

class _MyHomePageState extends State<MyHomePage> {
double _lowerValue = 50;
double _upperValue = 180;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 50, left: 20, right: 20),
alignment: Alignment.centerLeft,
child: FlutterSlider(
values: [1000, 15000],
rangeSlider: true,

//rtl: true,
ignoreSteps: [
FlutterSliderIgnoreSteps(from: 8000, to: 12000),
FlutterSliderIgnoreSteps(from: 18000, to: 22000),
],
max: 25000,
min: 0,
step: FlutterSliderStep(step: 100),

jump: true,

trackBar: FlutterSliderTrackBar(
activeTrackBarHeight: 2,
activeTrackBar: BoxDecoration(color: Colors.brown),
),
tooltip: FlutterSliderTooltip(
textStyle: TextStyle(fontSize: 17, color: Colors.lightBlue),
),
handler: FlutterSliderHandler(
decoration: BoxDecoration(),
child: Container(
decoration: BoxDecoration(
color: Colors.brown,
borderRadius: BorderRadius.circular(25)),
padding: EdgeInsets.all(10),
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25)),
),
),
),
rightHandler: FlutterSliderHandler(
decoration: BoxDecoration(),
child: Container(
decoration: BoxDecoration(
color: Colors.brown,
borderRadius: BorderRadius.circular(25)),
padding: EdgeInsets.all(10),
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25)),
),
),
),
disabled: false,

onDragging: (handlerIndex, lowerValue, upperValue) {
_lowerValue = lowerValue;
_upperValue = upperValue;
setState(() {});
},
)),
],
),
),
);
}
}

这是图像输出

enter image description here您可以相应地更改颜色。

让我知道它是否有效。

查看此代码以获得工具提示:

tooltip: FlutterSliderTooltip(
disableAnimation: true,
alwaysShowTooltip: true,
textStyle: TextStyle(fontSize: 17, color: Colors.lightBlue),
),

关于flutter - 如何在 Flutter 中制作这个自定义的 RangeSlider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62343728/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com