Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter app freezes when a TextField or TextFormField is selected

I have a Flutter app that is functioning properly in all respects except when I select a TextField (or TextFormField). When I select the TextField, the cursor blinks in the TextField, but I can't type anything AND all other buttons like the floatingActionButton and the back button in the AppBar quit working. Essentially, the app appears to be frozen, but I don't get any error messages.

After numerous attempts to fix the problem in two different pages that contain FocusNodes and TextEditingControllers, I went back to square one by incorporating a new page with code straight from Flutter's website, but the TextField in this barebones code still locks up the app.

import 'package:flutter/material.dart';

class EventDetailForm extends StatefulWidget {
  static const String routeName = "/events/event-detail-form";
  @override
  _EventDetailFormState createState() => _EventDetailFormState();
}

class _EventDetailFormState extends State<EventDetailForm> {
  final myController = TextEditingController();
  @override
  void dispose() {
    myController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Event Detail')),
      body: Padding(
          padding: const EdgeInsets.all(16),
          child: TextField(
            controller: myController,
          )),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          return showDialog(
              context: context,
              builder: (context) {
                return AlertDialog(
                  content: Text(myController.text),
                );
              });
        },
        child: Icon(Icons.text_fields),
      ),
    );
  }
}

Unfortunately, I am not getting any error messages. The cursor just blinks in the TextField and everything else loses function and I have to quit and restart. I am not sure what else I should be considering. Does anyone have any ideas on what might be causing this?

like image 286
xdevco Avatar asked Oct 04 '19 13:10

xdevco


People also ask

What is difference between TextField and TextFormField in Flutter?

The main difference between TextFormField and TextField is that the TextFormField widget uses the Form widget, which can contain multiple TextField widgets.

How do you add a dynamic TextField in Flutter?

Add a form with a text field to enter our name in this class. 3. Create a list that will tell how many dynamic text fields to display and will also store each text field data. static List<String> friendsList = [null];


2 Answers

Simulator -> Device -> Erase All Content And Settings works for me.

like image 114
Sait Banazili Avatar answered Sep 20 '22 07:09

Sait Banazili


Had same problem when I upgraded Xcode to ios 13.1. I switched to a different simulator, and the problem went away.

like image 30
Kevin Avatar answered Sep 19 '22 07:09

Kevin