Skip to content
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

Add ability to customize the default RangeSlider padding #165317

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TahaTesser
Copy link
Member

Fixes Ability to change RangeSlider padding

Add ability to override default padding so the RangeSlider 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> {
  RangeValues _sliderValues = const RangeValues(0.0, 1.0);

  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        sliderTheme: const SliderThemeData(
          // padding: EdgeInsets.symmetric(vertical: 4),
          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 EdgeInsetsDirectional.all(16),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    const Placeholder(fallbackHeight: 100.0),
                    RangeSlider(
                      values: _sliderValues,
                      onChanged: (RangeValues values) {
                        setState(() {
                          _sliderValues = values;
                        });
                      },
                    ),
                    const Placeholder(fallbackHeight: 100.0),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Before

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

Screenshot 2025-03-17 at 17 08 35

After

Can adjust default RangeSlider padding via SliderThemeData,padding or RangeSlider.padding)

Screenshot 2025-03-17 at 17 08 26

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 Mar 17, 2025
@TahaTesser TahaTesser force-pushed the range_slider_padding branch from 736e7c6 to 2881414 Compare March 17, 2025 16:22
@TahaTesser TahaTesser marked this pull request as ready for review March 18, 2025 08:28
@TahaTesser TahaTesser requested a review from QuncCccccc March 18, 2025 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 RangeSlider padding
1 participant