of method Null safety

SliderThemeData of(
  1. BuildContext context
)

Returns the data from the closest SliderTheme instance that encloses the given context.

Defaults to the ambient ThemeData.sliderTheme if there is no SliderTheme in the given build context.

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

  @override
  State createState() => LaunchState();
}

class LaunchState extends State<Launch> {
  double _rocketThrust = 0;

  @override
  Widget build(BuildContext context) {
    return SliderTheme(
      data: SliderTheme.of(context).copyWith(activeTrackColor: const Color(0xff804040)),
      child: Slider(
        onChanged: (double value) { setState(() { _rocketThrust = value; }); },
        value: _rocketThrust,
      ),
    );
  }
}

See also:

  • SliderThemeData, which describes the actual configuration of a slider theme.

Implementation

static SliderThemeData of(BuildContext context) {
  final SliderTheme? inheritedTheme = context.dependOnInheritedWidgetOfExactType<SliderTheme>();
  return inheritedTheme != null ? inheritedTheme.data : Theme.of(context).sliderTheme;
}