From 6d31323971d4cfc58033a78a4bc0bf19e6e46b7b Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 8 Feb 2019 10:47:59 -0500 Subject: [PATCH] Create slider with editable numerical value in gallery (#23506) * Update doc header in Opacity class to fix issue #23311 * Added slider with editable numerical value to gallery. Fixes flutter#1542 * Revert "Update doc header in Opacity class to fix issue #23311" This reverts commit 2d3642bbda6e00389e78631360f8274e9bb7d675. * Fix typo in slider description * Increase TextField size to pass accessibility test * Added Semantics widget to pass accessibility test * Made description start with caps to match other examples * Removed unnecessary spacing Container widget * Update authors file * Fix indent * Removed decimal and replaced boundaries with .clamp Signed-off-by: Martin Staadecker * Undo line wrap from previous commit Signed-off-by: Martin Staadecker * Update onSubmitted to only call setState when value has changed Signed-off-by: Martin Staadecker --- AUTHORS | 1 + .../lib/demo/material/slider_demo.dart | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/AUTHORS b/AUTHORS index 265c7daf4b..2b9f1a8a2b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -36,3 +36,4 @@ TruongSinh Tran-Nguyen Sander Dalby Larsen Marco Scannadinari Frederik Schweiger +Martin Staadecker diff --git a/examples/flutter_gallery/lib/demo/material/slider_demo.dart b/examples/flutter_gallery/lib/demo/material/slider_demo.dart index 1c28d1fe2f..d825f5df3b 100644 --- a/examples/flutter_gallery/lib/demo/material/slider_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/slider_demo.dart @@ -159,6 +159,49 @@ class _SliderDemoState extends State { const Text('Continuous'), ], ), + Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + children: [ + Expanded( + child: Slider( + value: _value, + min: 0.0, + max: 100.0, + onChanged: (double value) { + setState(() { + _value = value; + }); + }, + ), + ), + Semantics( + label: 'Editable numerical value', + child: Container( + width: 48, + height: 48, + child: TextField( + onSubmitted: (String value) { + final double newValue = double.tryParse(value); + if (newValue != null && newValue != _value) { + setState(() { + _value = newValue.clamp(0, 100); + }); + } + }, + keyboardType: TextInputType.number, + controller: TextEditingController( + text: _value.toStringAsFixed(0), + ), + ), + ), + ), + ], + ), + const Text('Continuous with Editable Numerical Value'), + ], + ), Column( mainAxisSize: MainAxisSize.min, children: const [