New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discrete Slider/RangeSlider has interpolation (?) errors #39510
Comments
CC @clocksmith - maybe we're missing a clamp? |
Reproducible on the latest master flutter doctor -v
|
You mentioned this issue in your merged PR @guidezpl . Should this be closed? |
That PR was just a fix for #60715. This is still reproducible on flutter doctor -v
|
This is still happening on flutter 2.2.0 |
It is, also if you use
and you slide to the last value you will get as value
And it won't render! |
cc @clocksmith |
Nice find @apoleo88 😩
|
How to get float value? Here is my code. RangeValues _caratRangeValues = const RangeValues(0, 6); RangeSlider(
|
Hi @repentsinner, I can no longer reproduce it, I believe the bug is fixed, However, I do see some inconsistency, on Web the labels are shown as integer while it is double on mobile devices, and the Desktop. @clocksmith Do you think we should file a separate issue for it? Screen.Recording.2022-12-29.at.1.25.00.AM.movcode sampleimport 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
theme: ThemeData.dark(),
home: const Home(),
);
}
}
class Home extends StatefulWidget {
const Home({super.key});
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
final TextEditingController _controller =
TextEditingController(text: 'Some long text to test the TextField');
double sliderValue = 0.0;
RangeValues _currentRangeValues = const RangeValues(40, 80);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RangeSlider(
values: _currentRangeValues,
max: 100,
divisions: 5,
labels: RangeLabels(
_currentRangeValues.start.toString(),
_currentRangeValues.end.toString(),
),
onChanged: (RangeValues values) {
setState(() {
_currentRangeValues = values;
});
},
),
const SizedBox(height: 20),
Slider.adaptive(
value: sliderValue,
label: sliderValue.toString(),
onChanged: (x) {
setState(() {
sliderValue = x;
});
},
min: 0,
max: 5,
divisions: 5 ~/ 0.2,
)
],
)));
}
}
flutter doctor -v (mac)
Closing as the original issue has been resolved. Incase anyon still encounters the issue, then please feel free to write in the comments and we will reopen it. Thank you. |
Oops, I was able to reproduce it, Reopening! code sampleimport 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Slider/RangeSlider Test'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
static const int divisions = 35;
double _value = 0.0;
RangeValues _values = RangeValues(0.0, divisions.toDouble());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Slider(
min: 0.0,
max: divisions.toDouble(),
divisions: divisions,
value: _value,
onChanged: (double value) {
setState(() {
_value = value;
});
},
),
Text('$_value'),
RangeSlider(
min: 0.0,
max: divisions.toDouble(),
divisions: divisions,
values: _values,
onChanged: (RangeValues value) {
print(_values);
setState(() {
_values = value;
});
},
),
Text(
'$_values',
),
],
),
),
);
}
}
logsmahesh@Maheshs-MacBook-Air-M1 flutter_issue % flutterm run -d chrome
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome... 11.6s
This app is linked to the debug service: ws://127.0.0.1:63049/SzjEIEMw61I=/ws
Debug service listening on ws://127.0.0.1:63049/SzjEIEMw61I=/ws
💪 Running with sound null safety 💪
🔥 To hot restart changes while running, press "r" or "R".
For a more detailed help message, press "h". To quit, press "q".
An Observatory debugger and profiler on Chrome is available at: http://127.0.0.1:63049/SzjEIEMw61I=
The Flutter DevTools debugger and profiler on Chrome is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:63049/SzjEIEMw61I=
Performing hot restart... 2,545ms
Restarted application in 2,549ms.
RangeValues(0, 35)
RangeValues(1, 35)
RangeValues(2, 35)
RangeValues(3, 35)
RangeValues(4, 35)
RangeValues(5, 35)
RangeValues(6, 35)
RangeValues(7, 35)
RangeValues(8, 35)
RangeValues(9, 35)
RangeValues(10, 35)
RangeValues(11, 35)
RangeValues(12, 35)
RangeValues(13, 35)
RangeValues(14, 35)
RangeValues(15, 35)
RangeValues(16, 35)
RangeValues(17, 35)
RangeValues(18, 35)
RangeValues(19, 35)
RangeValues(20, 35)
RangeValues(21, 35)
RangeValues(22, 35)
RangeValues(21, 35)
RangeValues(20, 35)
RangeValues(19, 35)
RangeValues(18, 35)
RangeValues(17, 35)
RangeValues(16, 35)
RangeValues(15, 35)
RangeValues(14, 35)
RangeValues(13, 35)
RangeValues(12, 35)
RangeValues(10, 35)
RangeValues(9, 35)
RangeValues(8, 35)
RangeValues(7, 35)
RangeValues(6, 35)
RangeValues(5, 35)
RangeValues(4, 35)
RangeValues(3, 35)
RangeValues(2, 35)
RangeValues(1, 35)
RangeValues(0, 35)
RangeValues(1, 35)
RangeValues(2, 35)
RangeValues(4, 35)
RangeValues(7, 35)
RangeValues(11, 35)
RangeValues(14, 35)
RangeValues(17, 35)
RangeValues(20, 35)
RangeValues(21, 35)
RangeValues(23, 35)
RangeValues(24, 35)
RangeValues(26, 35)
RangeValues(27, 35)
RangeValues(28, 35)
RangeValues(29.000000000000004, 35)
RangeValues(30, 35)
RangeValues(31, 35)
RangeValues(30, 35)
RangeValues(29.000000000000004, 35)
RangeValues(28, 35)
RangeValues(27, 35)
RangeValues(26, 35)
RangeValues(25, 35)
RangeValues(24, 35)
RangeValues(23, 35)
RangeValues(22, 35)
RangeValues(21, 35)
RangeValues(22, 35)
RangeValues(23, 35)
RangeValues(24, 35)
RangeValues(25, 35)
RangeValues(26, 35)
RangeValues(25, 35)
RangeValues(24, 35)
RangeValues(23, 35)
RangeValues(22, 35)
RangeValues(21, 35)
RangeValues(20, 35)
RangeValues(19, 35)
RangeValues(18, 35)
RangeValues(17, 35)
RangeValues(16, 35)
RangeValues(15, 35)
RangeValues(14, 35)
RangeValues(13, 35)
RangeValues(12, 35)
RangeValues(11, 35)
RangeValues(10, 35)
RangeValues(9, 35)
RangeValues(10, 35)
RangeValues(11, 35)
RangeValues(12, 35)
RangeValues(13, 35)
RangeValues(14, 35)
RangeValues(15, 35)
RangeValues(16, 35)
RangeValues(17, 35)
RangeValues(18, 35)
RangeValues(19, 35)
RangeValues(20, 35)
RangeValues(21, 35)
RangeValues(22, 35)
RangeValues(23, 35)
RangeValues(24, 35)
RangeValues(25, 35)
RangeValues(26, 35)
RangeValues(27, 35)
RangeValues(28, 35)
RangeValues(29.000000000000004, 35)
RangeValues(30, 35)
RangeValues(29.000000000000004, 35)
RangeValues(28, 35)
flutter doctor -v (mac)
|
Seen this issue often as well, you can of course take care of the rounding issue outside the sliders and visual presentation of the values. I now always do that, but if it can be solved in the Widget already that would be nice. |
Our team end up using this package: https://pub.dev/packages/carousel_slider Because that one does not have this issue 👀 |
Steps to Reproduce
min:0.0
,max:35.0
,divisions: 35
(or see main.dart)This also happens with:
Current workaround is to insert
.roundToDouble()
methods in all of theonChange*
callbacks to clean up the values before passing them out to the consumer.Thanks for considering!
Logs
The text was updated successfully, but these errors were encountered: