main
 1import 'package:flutter/material.dart';
 2
 3/// A [ListTile] with a [Slider] attached to it.
 4class SliderListTile extends StatelessWidget {
 5  /// Creates a [ListTile] with an attached [Slider].
 6  const SliderListTile({
 7    super.key,
 8    required this.title,
 9    this.subtitle,
10    required this.onChanged,
11    required this.value,
12    required this.min,
13    required this.max,
14    this.stepSize = 1,
15    this.leading,
16    this.trailing,});
17
18  /// The primary content of the list tile.
19  final Widget title;
20
21  /// A widget to display below the title.
22  final Widget? subtitle;
23
24  /// A widget to display before the title.
25  final Widget? leading;
26
27  /// A widget to display after the title.
28  final Widget? trailing;
29
30  /// Minimum selectable value on the slider.
31  final double min;
32
33  /// Maximum selectable value on the slider.
34  final double max;
35
36  /// Amount of units after which a selectable step is placed on the slider.
37  final double stepSize;
38
39  /// Current position of the slider thumb.
40  ///
41  /// Should be a value that is selectable by the user.
42  final double value;
43
44  /// Called during a drag when the user is selecting a new value for the slider by dragging.
45  final void Function(double newValue) onChanged;
46
47  @override
48  Widget build(BuildContext context) => ListTile(
49      title: title,
50      leading: leading,
51      trailing: trailing,
52      subtitle: (subtitle == null) ? _buildSlider() : Column(
53        crossAxisAlignment: CrossAxisAlignment.start,
54        children: [
55          subtitle!,
56          _buildSlider(),
57        ],
58      ),
59    );
60
61  Widget _buildSlider() => SizedBox(
62      height: 30,
63      child: Slider(
64        value: value,
65        min: min,
66        max: max,
67        divisions: (max - min) ~/ stepSize,
68        onChanged: onChanged,
69      ),
70    );
71
72}