0

I created a simple page for a user to update their display name if they don't have one, but for some reason when I click to enter the input data, the keyboard appears and disappears and the page freaks out a bit. I included a gif.

Error with text input

I've used this same code before for email and password inputs. Not sure why it's strange now. Here is my code for the page:

`class AddName extends StatefulWidget {
  const AddName({super.key});

  @override
  State<AddName> createState() => _AddNameState();
}

class _AddNameState extends State<AddName> {
  final TextEditingController _firstNameController = TextEditingController();
  final TextEditingController _lastNameController = TextEditingController();
  final user = FirebaseAuth.instance.currentUser;
  final userDoc = FirebaseFirestore.instance.collection('users').doc();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizedBox(
          height: MediaQuery.of(context).size.height,
          child: SingleChildScrollView(
              child: Column(
            children: [
              const SizedBox(height: 100),
              const Text(
                'Please enter your name',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 30,
                  fontWeight: FontWeight.bold,
                ),
              ),
              const SizedBox(
                height: 20,
              ),
              const Text('You must enter your name to use the app'),
              const SizedBox(height: 80),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: TextField(
                  controller: _firstNameController,
                  style: const TextStyle(color: Colors.white),
                  decoration: const InputDecoration(
                    hintText: 'Enter your first name',
                    hintStyle: TextStyle(color: Colors.white),
                    enabledBorder: UnderlineInputBorder(
                      borderSide: BorderSide(color: Colors.white),
                    ),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: TextField(
                  controller: _lastNameController,
                  style: const TextStyle(color: Colors.white),
                  decoration: const InputDecoration(
                    hintText: 'Enter your last name',
                    hintStyle: TextStyle(color: Colors.white),
                    enabledBorder: UnderlineInputBorder(
                      borderSide: BorderSide(color: Colors.white),
                    ),
                  ),
                ),
              ),
              const SizedBox(height: 100),
              ElevatedButton(
                onPressed: () async {
                  userDoc.set({
                    'displayName':
                        _firstNameController.text + _lastNameController.text,
                  });

                  // Navigator.of(context).pop();
                },
                child: const Text('Submit'),
              ),
            ],
          ))),
    );
  }
}
`

My emulator has been strange lately, too. Not sure if that's part of the problem.

Hunter Books
  • 372
  • 2
  • 11
  • 1
    The above code doesn't reproduce your issue. Tested both on iOS simulator & real device with Flutter 3.3.7. Works as expected. Try different device or `flutter clean` to see if it fixes the issue. – esentis Nov 10 '22 at 11:17
  • 1
    try your app on real device. On simulator, the keyboard doesn't work well – Fugipe Nov 10 '22 at 11:21
  • @esentis, I just ran it on my android. It's doing the same thing. Very strange that it works on yours and not my device. – Hunter Books Nov 10 '22 at 12:59
  • 1
    I have commented out the `Firebase` calls obviously, on my test. Try commenting them out to see if it makes any difference. – esentis Nov 10 '22 at 13:02
  • Still the same thing. This is hilarious. I'm going to restart everything and see if that works. I appreciate your help in this. – Hunter Books Nov 10 '22 at 13:04
  • Well this is weird indeed, I don't see any obvious problem from the snippet though. – esentis Nov 10 '22 at 13:09

1 Answers1

0

Add Await

await userDoc.set({
                'displayName':
                    _firstNameController.text + _lastNameController.text,
              });
MrShakila
  • 874
  • 1
  • 4
  • 19