Created
February 10, 2019 19:00
-
-
Save Jatra/2affec6f58e4aca8fc72c3c47fc64e75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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