showSliderDialog function

void showSliderDialog({
  1. required BuildContext context,
  2. required String title,
  3. required int divisions,
  4. required double min,
  5. required double max,
  6. String valueSuffix = '',
  7. required double value,
  8. required Stream<double> stream,
  9. required ValueChanged<double> onChanged,
})

Shows a slider dialog for selecting a value.

Implementation

void showSliderDialog({
  required BuildContext context, // Build context for the dialog
  required String title, // Title of the dialog
  required int divisions, // Number of divisions for the slider
  required double min, // Minimum value for the slider
  required double max, // Maximum value for the slider
  String valueSuffix = '', // Suffix to display with the value
  required double value, // Initial value of the slider
  required Stream<double> stream, // Stream to provide slider values
  required ValueChanged<double> onChanged, // Callback for value change
}) {
  // final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
  // final Color iconColor = isDarkMode ? Colors.white : Colors.black;
  showDialog<void>(
    context: context,
    builder: (context) => AlertDialog(
      backgroundColor: Theme.of(context).scaffoldBackgroundColor,
      title: Text(title, textAlign: TextAlign.center), // Dialog title
      content: StreamBuilder<double>(
        stream: stream, // Stream to listen for value changes
        builder: (context, snapshot) => SizedBox(
          height: 100.0, // Height of the dialog content
          child: Column(
            children: [
              // Display the current value with the specified suffix
              Text('${snapshot.data?.toStringAsFixed(1)}$valueSuffix',
                style:  TextStyle(
                  fontFamily: 'Fixed', // Font family
                  color: Theme.of(context).primaryColor,
                  fontWeight: FontWeight.bold, // Font weight
                  fontSize: 24.0,),), // Font size
              Slider(
                divisions: divisions, // Number of divisions for the slider
                min: min, // Minimum value for the slider
                max: max, // Maximum value for the slider
                value: snapshot.data ??
                    value, // Current value from the stream or initial value
                onChanged: onChanged, // Callback for value change
              ),
            ],
          ),
        ),
      ),
    ),
  );
}