Created
October 9, 2019 15:00
-
-
Save iapicca/bd70a608d1b8432a99a91f186b619199 to your computer and use it in GitHub Desktop.
Focus Node Test
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(MaterialApp(home: MyHomePage(),),); | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
static final FocusNode _focusNode = FocusNode(); | |
static final TextEditingController _controller = TextEditingController(); | |
void _requestNode()=> FocusScope.of(context).requestFocus(_focusNode); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: TextField( | |
focusNode: _focusNode, | |
controller: _controller, | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: ()=>_requestNode(), | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment