Commit 6c2ab9d3 authored by Collin Jackson's avatar Collin Jackson

Merge pull request #1847 from collinjackson/input_key

Don’t require global keys for Input, fixes #1828
parents ca4d10d3 d4533622
...@@ -241,9 +241,6 @@ class StockHomeState extends State<StockHome> { ...@@ -241,9 +241,6 @@ class StockHomeState extends State<StockHome> {
static const List<String> portfolioSymbols = const <String>["AAPL","FIZZ", "FIVE", "FLAT", "ZINC", "ZNGA"]; static const List<String> portfolioSymbols = const <String>["AAPL","FIZZ", "FIVE", "FLAT", "ZINC", "ZNGA"];
static GlobalKey searchFieldKey = new GlobalKey();
static GlobalKey companyNameKey = new GlobalKey();
// TODO(abarth): Should we factor this into a SearchBar in the framework? // TODO(abarth): Should we factor this into a SearchBar in the framework?
Widget buildSearchBar() { Widget buildSearchBar() {
return new ToolBar( return new ToolBar(
...@@ -255,7 +252,6 @@ class StockHomeState extends State<StockHome> { ...@@ -255,7 +252,6 @@ class StockHomeState extends State<StockHome> {
), ),
center: new Input( center: new Input(
value: _searchQuery, value: _searchQuery,
key: searchFieldKey,
autofocus: true, autofocus: true,
hintText: 'Search stocks', hintText: 'Search stocks',
onChanged: _handleSearchQueryChanged onChanged: _handleSearchQueryChanged
...@@ -272,7 +268,6 @@ class StockHomeState extends State<StockHome> { ...@@ -272,7 +268,6 @@ class StockHomeState extends State<StockHome> {
return new Column( return new Column(
children: <Widget>[ children: <Widget>[
new Input( new Input(
key: companyNameKey,
autofocus: true, autofocus: true,
hintText: 'Company Name' hintText: 'Company Name'
), ),
......
...@@ -15,7 +15,7 @@ export 'package:sky_services/editing/editing.mojom.dart' show KeyboardType; ...@@ -15,7 +15,7 @@ export 'package:sky_services/editing/editing.mojom.dart' show KeyboardType;
/// A material design text input field. /// A material design text input field.
class Input extends StatefulComponent { class Input extends StatefulComponent {
Input({ Input({
GlobalKey key, Key key,
this.value: InputValue.empty, this.value: InputValue.empty,
this.keyboardType: KeyboardType.text, this.keyboardType: KeyboardType.text,
this.icon, this.icon,
...@@ -28,9 +28,7 @@ class Input extends StatefulComponent { ...@@ -28,9 +28,7 @@ class Input extends StatefulComponent {
this.autofocus: false, this.autofocus: false,
this.onChanged, this.onChanged,
this.onSubmitted this.onSubmitted
}) : super(key: key) { }) : super(key: key);
assert(key != null);
}
/// The text of the input field. /// The text of the input field.
final InputValue value; final InputValue value;
...@@ -77,10 +75,13 @@ const Curve _kTransitionCurve = Curves.ease; ...@@ -77,10 +75,13 @@ const Curve _kTransitionCurve = Curves.ease;
class _InputState extends State<Input> { class _InputState extends State<Input> {
GlobalKey<RawInputLineState> _rawInputLineKey = new GlobalKey<RawInputLineState>(); GlobalKey<RawInputLineState> _rawInputLineKey = new GlobalKey<RawInputLineState>();
GlobalKey get focusKey => config.key is GlobalKey ? config.key : _rawInputLineKey;
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context)); assert(debugCheckHasMaterial(context));
ThemeData themeData = Theme.of(context); ThemeData themeData = Theme.of(context);
bool focused = Focus.at(context, autofocus: config.autofocus); BuildContext focusContext = focusKey.currentContext;
bool focused = focusContext != null && Focus.at(focusContext, autofocus: config.autofocus);
TextStyle textStyle = config.style ?? themeData.text.subhead; TextStyle textStyle = config.style ?? themeData.text.subhead;
Color focusHighlightColor = themeData.accentColor; Color focusHighlightColor = themeData.accentColor;
...@@ -156,7 +157,7 @@ class _InputState extends State<Input> { ...@@ -156,7 +157,7 @@ class _InputState extends State<Input> {
child: new RawInputLine( child: new RawInputLine(
key: _rawInputLineKey, key: _rawInputLineKey,
value: config.value, value: config.value,
focusKey: config.key, focusKey: focusKey,
style: textStyle, style: textStyle,
hideText: config.hideText, hideText: config.hideText,
cursorColor: cursorColor, cursorColor: cursorColor,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment