Skip to content

Instantly share code, notes, and snippets.

@Jatra
Created February 10, 2019 19:00
Show Gist options
  • Select an option

  • Save Jatra/2affec6f58e4aca8fc72c3c47fc64e75 to your computer and use it in GitHub Desktop.

Select an option

Save Jatra/2affec6f58e4aca8fc72c3c47fc64e75 to your computer and use it in GitHub Desktop.
class _ColourSliderState extends State<ColourSlider> {
var fraction = 0.0;
@override
Widget build(BuildContext context) {
debugPaintPointersEnabled = true;
return GestureDetector(
onPanUpdate: (DragUpdateDetails details) {
RenderBox box = context.findRenderObject();
Offset localOffset = box.globalToLocal(details.globalPosition);
setState(() {
fraction = localOffset.dx.clamp(0.0, 300) / 300;
});
},
child: Container(
width: 300,
height: 50,
child: CustomMultiChildLayout(
delegate: _ColourSliderDelegate(),
children: <Widget>[
LayoutId(
id: ColourSlider.track,
child: Container(
width: 300,
height: 20,
color: Colors.white,
),
),
LayoutId(
id: ColourSlider.thumb,
child: Transform.translate(
offset: Offset(fraction * 300, 0),
child: Container(
width: 50,
height: 50,
color: Colors.red,
),
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment