2

When I use TextInputAction and set it to next, the button does change on my simulator device however it doesn't do anything, User interaction is not moved into the next element. Have opened a ticket on the FLutter `gitHUb page as well as in the chat rooms but no help so far and would like to keep the ball rolling on my training :)

https://github.com/flutter/flutter/issues/47749

Joe Early
  • 108
  • 5
  • 20
  • Does this answer your question? [How to shift focus to next textfield in flutter?](https://stackoverflow.com/questions/52150677/how-to-shift-focus-to-next-textfield-in-flutter) – Ravinder Kumar Dec 25 '19 at 10:47
  • I believe I am already doing what is suggusted with `FocusScope.of(context).requestFocus(focus);` – Joe Early Dec 25 '19 at 22:20

1 Answers1

3

There is bug in your code , you put _passwordFocusNode in email field and cause error
when _emailEditingComplete() , focus stay in email

void _emailEditingComplete() {
    FocusScope.of(context).requestFocus(_passwordFocusNode);
}

return TextField(
  controller: _passwordController,
  focusNode: _emailFocusNode,

return TextField(
  controller: _emailController,
  focusNode: _passwordFocusNode,

onEditingComplete and onSubmitted both work correctly in this case

working demo for test

enter image description here

full test code

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  final TextEditingController _emailController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();
  final FocusNode _emailFocusNode = FocusNode();
  final FocusNode _passwordFocusNode = FocusNode();

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  void dispose() {
    // Clean up the focus node when the Form is disposed.
    _emailFocusNode.dispose();
    _passwordFocusNode.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextField(
              focusNode: _emailFocusNode,
              decoration: InputDecoration(
                labelText: 'Email',
                hintText: 'test@test.com',
              ),
              keyboardType: TextInputType.emailAddress,
              textInputAction: TextInputAction.next,
              onEditingComplete: () {
                FocusScope.of(context).requestFocus(_passwordFocusNode);
              },
              onSubmitted: (val) {
                //FocusScope.of(context).requestFocus(_passwordFocusNode);
              },
            ),
            TextField(
              focusNode: _passwordFocusNode,
              decoration: InputDecoration(
                labelText: 'password',
              ),
              keyboardType: TextInputType.emailAddress,
              textInputAction: TextInputAction.done,
              onSubmitted: (val) {},
            ),
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

bug

enter image description here

chunhunghan
  • 51,087
  • 5
  • 102
  • 120
  • 3
    You sir are a gentleman for taking the time and effort to debug that. I owe you a beer or lunch at the very least. Send me your paypal.me link to my uername without the same to Gmail – Joe Early Dec 27 '19 at 13:16