Repository navigation
Slider with transparent track colors and custom trackHeight cannot reach the extreme ends #161210
Copy link
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.27Found to occur in 3.27Found to occur in 3.27frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
Steps to reproduce
- run the example code.
- long-pressed to the indicator.
- schroll to best left.
Expected results
i can drag the indicator to the best left and right.
Actual results
i can't drag the indicator to the best left and right.
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Color Simulation',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double _value = 0.5;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
height: 44,
width: 200,
alignment: Alignment.centerLeft,
child: Stack(
alignment: Alignment.centerLeft,
children: [
Container(
height: 4,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [
Colors.red,
Colors.blue,
]),
borderRadius: BorderRadius.circular(2),
),
),
SliderTheme(
data: SliderThemeData(
trackHeight: 44,
thumbColor: Colors.white,
activeTrackColor: Colors.transparent,
inactiveTrackColor: Colors.transparent,
thumbShape: RoundSliderThumbShape(
enabledThumbRadius: 12,
elevation: 4,
),
overlayShape: RoundSliderOverlayShape(
overlayRadius: 24,
),
),
child: Slider(
value: _value,
onChanged: (newValue) {
setState(() {
_value = newValue;
});
},
),
),
],
),
),
SizedBox(
width: 50,
child: Text(
'${(_value * 100).round()}%',
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
textAlign: TextAlign.end,
),
)
],
),
),
);
}
}Screenshots or Video
RPReplay_Final1736231161.MP4
Logs
No response
Flutter Doctor output
zengyang@zengyangdeMac-mini lomod % flutter doctor -v
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.0 23A344 darwin-arm64, locale en-CN)
• Flutter version 3.24.3 on channel stable at /Users/zengyang/fvm/versions/3.24.3
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2663184aa7 (4 months ago), 2024-09-11 16:27:48 -0500
• Engine revision 36335019a8
• Dart version 3.5.3
• DevTools version 2.37.3
• Flutter download mirror https://storage.flutter-io.cn
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/zengyang/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/zengyang/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
[✓] VS Code (version 1.96.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.102.0
[✓] Connected device (6 available)
• aasaaaa 11 aaaa (mobile) • 00008030-0019082236E2802E • ios • iOS 17.6.1 21G93
• qqqqqqq1iPhone (mobile) • 00008030-000171CE1168802E • ios • iOS 18.2 22C152
• iPhone 11 Pro Max (mobile) • 00008030-000224190CE8802E • ios • iOS 18.1.1 22B91
• macOS (desktop) • macos • darwin-arm64 • macOS 14.0 23A344 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.0 23A344 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.205
[✓] Network resources
• All expected network resources are available.
• No issues found!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.27Found to occur in 3.27Found to occur in 3.27frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Type
Projects
- StatusShow more project fieldsDone (PR merged)
Activity
ahyangnb commentedon Jan 7, 2025
overlayShape: RoundSliderOverlayShape(
overlayRadius: 0,
),
TahaTesser commentedon Jan 7, 2025
This might be a genuine bug. Reopening. I'll take a close look this week.
ahyangnb commentedon Jan 10, 2025
but it's normal after seted
ahyangnb commentedon Jan 10, 2025
Any bug left? @TahaTesser
TahaTesser commentedon Jan 10, 2025
I'm working on another bug at the moment. I'll get back to this issue soon.
2 remaining items
ahyangnb commentedon Jan 14, 2025
Using this will not change behavior and it makes evethings normal.
RPReplay_Final1736850756.MP4
TahaTesser commentedon Jan 14, 2025
@ahyangnb
Appreciate you getting back. I ran the code sample you provided with
overlayRadius: 0(On mobile and desktop)I cannot get Slider to reach the end. Am I missing something?
Code Sample
expand to view the code sample
ahyangnb commentedon Jan 15, 2025
@TahaTesser You miss nothing, i've tred copy codes you sent and run, it's normal.
What's your flutter version? i was use the flutter 3.24.3.
[-][Material] the Slider Widget can not to edge.[/-][+]`Slider` cannot be reach the edges [/+]TahaTesser commentedon Jan 17, 2025
Hi @ahyangnb
First of all, thank you so much for providing the details.
At first, I was suspicious that this issue is probably same as rydmike/flex_color_picker#90. However, after studying this bug it seems to be slightly different bug but related.
Your issue to be caused by
SliderThemecustomization that are hidden by transparent active and inactive track colors.Slidertrack heightIn your
sliderThemeData, you're adjusting the track height which would respond to the track shape roundness and adjust how far it can be moved:But the change is hidden when you're setting the active track and inactive track colors to be transparent
Solution
I will make a quality of life fix to ignore the
trackHeightproperty when the user hides the tracks by settingactiveTrackColorandinactiveTrackColorwith transparent color.SliderpaddingThe reason you were able to fix the thumb not reaching the edges by setting
overlayRadius: 0because of the defaultSliderpadding.The default
Sliderpadding takes track overlay radius into account . You can view it in the layout inspector.However, I've added new
SliderThemeData.paddingproperty in a recent PR. In the next major stable release, you can use this property directly to adjust default Slider padding and set toEdgeInsets.zeroto remove the default padding for your use case.[-]`Slider` cannot be reach the edges [/-][+]Constrained `Slider` with custom `trackHeight` cannot reach the extreme ends [/+][-]Constrained `Slider` with custom `trackHeight` cannot reach the extreme ends [/-][+]`Slider` with transparent track colors and custom `trackHeight` cannot reach the extreme ends [/+]Fix `Slider` renders track when track colors are transparent (#161814)
github-actions commentedon Feb 20, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.