Skip to content

Conversation

@TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Oct 3, 2024

Fixes Ability to change Sliders padding

Add ability to override default padding so the Slider can fit better in a layout.

Code sample

expand to view the code sample
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _sliderValue = 0.5;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        sliderTheme: const SliderThemeData(
          padding: EdgeInsets.symmetric(vertical: 4.0),
          thumbColor: Colors.red,
          inactiveTrackColor: Colors.amber,
        ),
      ),
      home: Scaffold(
        body: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: Card(
              shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(4.0)),
              ),
              color: Theme.of(context).colorScheme.surfaceContainerHighest,
              margin: const EdgeInsets.symmetric(horizontal: 16.0),
              child: Padding(
                padding: const EdgeInsets.all(16.0),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    const Placeholder(fallbackHeight: 100.0),
                    Slider(
                      value: _sliderValue,
                      onChanged: (double value) {
                        setState(() {
                          _sliderValue = value;
                        });
                      },
                    ),
                    const Placeholder(fallbackHeight: 100.0),

                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Before

(Cannot adjust default Slider padding to fill the horizontal space in a Column and reduce the padded height)

Screenshot 2024-10-03 at 15 45 18

After

Can adjust default Slider padding via SliderTheme)

Screenshot 2024-10-03 at 15 46 25

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Oct 3, 2024
@TahaTesser TahaTesser requested a review from QuncCccccc October 3, 2024 14:39
Copy link
Contributor

@bleroux bleroux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! with nits.

@TahaTesser TahaTesser force-pushed the slider_padding branch 2 times, most recently from 1e378ea to e4d8715 Compare October 7, 2024 15:00
@Piinks
Copy link
Contributor

Piinks commented Oct 15, 2024

The Google testing failures here were not related to this PR, but were caused by an issue that meant the tests did not actually run. So, there may still be failures, rebasing should kick off a new test run.

Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this really looks good to me! Next time I should check google testing earlier:)

Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM:) Thanks for adding it! Do you think if it's worth to add padding property to Slider class?

@TahaTesser
Copy link
Member Author

Do you think if it's worth to add padding property to Slider class?

Thank you for the reminder!

@TahaTesser TahaTesser added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 30, 2024
@auto-submit auto-submit bot merged commit 40c2274 into flutter:master Oct 30, 2024
74 checks passed
@TahaTesser TahaTesser deleted the slider_padding branch October 30, 2024 10:59
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 30, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 30, 2024
flutter/flutter@42132e8...fe71cad

2024-10-30 [email protected] Update CHANGELOG.md to correct ios vs macos issue (flutter/flutter#157822)
2024-10-30 [email protected] Add ability to customize the default `Slider` padding (flutter/flutter#156143)
2024-10-30 [email protected] Fix menu anchor state handling (flutter/flutter#157612)
2024-10-30 [email protected] Add test for `interactive_viewer.0.dart` (flutter/flutter#157773)
2024-10-30 [email protected] Add test for `scroll_metrics_notification.0.dart` (flutter/flutter#157768)
2024-10-30 [email protected] Add boundary feature to the drag gesture. (flutter/flutter#147521)
2024-10-30 [email protected] Fix `ResizeImage` documentation (flutter/flutter#157619)
2024-10-29 [email protected] Roll Flutter Engine from 795b5492f1b9 to 999797a2f690 (1 revision) (flutter/flutter#157825)
2024-10-29 [email protected] Avoid labeling all PRs as 'text-input' (flutter/flutter#157805)
2024-10-29 [email protected] Roll Packages from e0c4f55 to 028027e (8 revisions) (flutter/flutter#157813)
2024-10-29 [email protected] Roll Flutter Engine from 725c8e4bc379 to 795b5492f1b9 (5 revisions) (flutter/flutter#157820)
2024-10-29 [email protected] Fix and remove a few `no-shuffle` tags in `flutter_tools`. (flutter/flutter#157656)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to change Sliders padding

4 participants