Answers for "flutter text form field loses focus"

0

remove focus textfield flutter

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        FocusScopeNode currentFocus = FocusScope.of(context);

        if (!currentFocus.hasPrimaryFocus) {
          currentFocus.unfocus();
        }
      },
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(),
      ),
    );
  }
}
Posted by: Guest on June-27-2020
0

Keyboard disappearing when focussing on TextFormField flutter

This happens when you put GlobalKey<FormState> in your build function

Try with static or add inside initState ... _formKey ...

static GlobalKey<FormState> _formKey = new GlobalKey<FormState>();

Currently the key is recreated every time _LoginState is rebuilt, which defeats
it's purpose.
Posted by: Guest on July-11-2021

Code answers related to "flutter text form field loses focus"

Browse Popular Code Answers by Language