Commit d4533622 authored by Collin Jackson's avatar Collin Jackson

Don’t require global keys for Input, fixes #1828

parent 62fb32d4
......@@ -241,9 +241,6 @@ class StockHomeState extends State<StockHome> {
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?
Widget buildSearchBar() {
return new ToolBar(
......@@ -255,7 +252,6 @@ class StockHomeState extends State<StockHome> {
),
center: new Input(
value: _searchQuery,
key: searchFieldKey,
autofocus: true,
hintText: 'Search stocks',
onChanged: _handleSearchQueryChanged
......@@ -272,7 +268,6 @@ class StockHomeState extends State<StockHome> {
return new Column(
children: <Widget>[
new Input(
key: companyNameKey,
autofocus: true,
hintText: 'Company Name'
),
......
......@@ -15,7 +15,7 @@ export 'package:sky_services/editing/editing.mojom.dart' show KeyboardType;
/// A material design text input field.
class Input extends StatefulComponent {
Input({
GlobalKey key,
Key key,
this.value: InputValue.empty,
this.keyboardType: KeyboardType.text,
this.icon,
......@@ -28,9 +28,7 @@ class Input extends StatefulComponent {
this.autofocus: false,
this.onChanged,
this.onSubmitted
}) : super(key: key) {
assert(key != null);
}
}) : super(key: key);
/// The text of the input field.
final InputValue value;
......@@ -77,10 +75,13 @@ const Curve _kTransitionCurve = Curves.ease;
class _InputState extends State<Input> {
GlobalKey<RawInputLineState> _rawInputLineKey = new GlobalKey<RawInputLineState>();
GlobalKey get focusKey => config.key is GlobalKey ? config.key : _rawInputLineKey;
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(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;
Color focusHighlightColor = themeData.accentColor;
......@@ -156,7 +157,7 @@ class _InputState extends State<Input> {
child: new RawInputLine(
key: _rawInputLineKey,
value: config.value,
focusKey: config.key,
focusKey: focusKey,
style: textStyle,
hideText: config.hideText,
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