Skip to content

Instantly share code, notes, and snippets.

@iapicca
Created October 9, 2019 15:00
Show Gist options
  • Save iapicca/bd70a608d1b8432a99a91f186b619199 to your computer and use it in GitHub Desktop.
Save iapicca/bd70a608d1b8432a99a91f186b619199 to your computer and use it in GitHub Desktop.
Focus Node Test
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