Last active
February 8, 2016 22:32
-
-
Save collinjackson/33906003d2eef047b6fc to your computer and use it in GitHub Desktop.
New Input API example
This file contains 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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
new MaterialApp( | |
title: "Input Demo", | |
routes: <String, RouteBuilder>{ | |
'/': (RouteArguments args) => new FlutterDemo() | |
} | |
) | |
); | |
} | |
class FlutterDemo extends StatefulComponent { | |
@override | |
State createState() => new FlutterDemoState(); | |
} | |
class FlutterDemoState extends State { | |
GlobalKey _inputKey = new GlobalKey(); | |
InputValue _inputValue = InputValue.empty; | |
Widget build(BuildContext context) { | |
return new Scaffold( | |
toolBar: new ToolBar( | |
center: new Text("Input Demo") | |
), | |
body: new Material( | |
child: new Center( | |
child: new Column( | |
children: <Widget>[ | |
new Flexible( | |
child: new Container( | |
decoration: const BoxDecoration( | |
backgroundColor: const Color(0xFF00FF00) | |
) | |
) | |
), | |
new Input( | |
key: _inputKey, | |
value: _inputValue, | |
onChanged: (InputValue value) { | |
setState(() { | |
_inputValue = value; | |
}); | |
}, | |
onSubmitted: (InputValue value) { | |
print("Submitted ${value.text}"); | |
setState(() { | |
_inputValue = InputValue.empty; | |
}); | |
} | |
) | |
] | |
) | |
) | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment