Video link: https://www.bilibili.com/video/av44936399/?p=2

In more than oneTextFieldGet the focus, and jump to the next focus through the keyboarddemoGetting the focus, the first file,main.dart
Copy the code

Effect:



import 'package:flutter/material.dart';
import 'textfields_focus_demo.dart'; / / package

void main(a) => runApp(MyApp());

class MyApp extends StatelessWidget {
  final Widget child;

  MyApp({Key key, this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: MaterialApp(
        title: 'Flutter demo', theme: ThemeData( primarySwatch: Colors.blue, primaryColor: Colors.blue, ), home: TextFieldDemo(), ), ); }}Copy the code

After the package, define the controller and focus for username and password,

I’m going to initialize it, and then I’m going to call it,

/ * *

  • Implementation principle:
  • Get the current textField focus with the FocusNode
  • Select keyboard Action (Next/Down) in the textInputAction property of TextNode
  • For the last preceding TextField: Remove the current Focus state in the onSubmitted property
  • Focus on the nextFocusNode: focusscope.of (context).requestfocus (nextFocusNode);
  • For the last TextField, just unfocus and submit the form */
    textfields_focus_demo.dart 
import 'package:flutter/material.dart';

class TextFieldDemo extends StatefulWidget {
  _TextFieldDemoState createState(a) => _TextFieldDemoState();
}

class _TextFieldDemoState extends State<TextFieldDemo> {
  FocusNode _namefocusNode, _pwfocusNode;
  TextEditingController _nameController, _pwController;

  @override
  void initState(a) {
    super.initState();
    _nameController = TextEditingController();
    _pwController = TextEditingController();
    _namefocusNode = FocusNode();
    _pwfocusNode = FocusNode();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(// Safe zone, mainly compatible with screens
        child: ListView(
          children: <Widget>[
            SizedBox(height: 80.0),// Set the height to 80
            Center(/ / in the middle
              child: Text(
                'Login',
                style: TextStyle(fontSize: 30.0),
              ),
            ),
            SizedBox(height: 80.0),
            Padding(
              padding: EdgeInsets.all(16.0),
              child: Material(
                borderRadius: BorderRadius.circular(10.0),
                child: TextField(
                  focusNode: _namefocusNode,
                  controller: _nameController,
                  obscureText: false,
                  textInputAction: TextInputAction.next,
                  onSubmitted: (input) {
                    _namefocusNode.unfocus();
                    FocusScope.of(context).requestFocus(_pwfocusNode);
                  },
                  decoration: InputDecoration(
                    labelText: 'name',
                  ),
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.all(16.0),
              child: Material(
                borderRadius: BorderRadius.circular(10.0),
                child: TextField(
                  focusNode: _pwfocusNode,
                  controller: _pwController,
                  obscureText: true,
                  textInputAction: TextInputAction.done,
                  onSubmitted: (input) {
                    _pwfocusNode.unfocus();
                  },
                  decoration: InputDecoration(
                    labelText: 'password'
                  ),
                ),
              ),
            ),
            ButtonBar(
              children: <Widget>[
                RaisedButton(
                  onPressed: (){},
                  child: Text('login'() [() [() [() [() [() [() }}Copy the code

Directory: www.flutterj.com/?post=124#t…