Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

Flutter code to make a sign in page with email and password

  1. User

    Flutter code to make a sign in page with email and password

  2. Assistant

    Here is a simple Flutter code to create a sign-in page with email and password:

    import 'package:flutter/material.dart';
    
    class SignInPage extends StatefulWidget {
      const SignInPage({Key? key}) : super(key: key);
    
      @override
      _SignInPageState createState() => _SignInPageState();
    }
    
    class _SignInPageState extends State<SignInPage> {
      final TextEditingController _emailController = TextEditingController();
      final TextEditingController _passwordController = TextEditingController();
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Sign In'),
          ),
          body: Padding(
            padding: const EdgeInsets.all(20.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextFormField(
                  controller: _emailController,
                  decoration: InputDecoration(
                    labelText: 'Email',
                  ),
                  keyboardType: TextInputType.emailAddress,
                  validator: (value) {
                    if (value!.isEmpty) {
                      return 'Email is required';
                    }
                    return null;
                  },
                ),
                SizedBox(height: 20.0),
                TextFormField(
                  controller: _passwordController,
                  decoration: InputDecoration(
                    labelText: 'Password',
                  ),
                  obscureText: true,
                  validator: (value) {
                    if (value!.isEmpty) {
                      return 'Password is required';
                    }
                    return null;
                  },
                ),
                SizedBox(height: 20.0),
                ElevatedButton(
                  onPressed: () {},
                  child: Text('Sign In'),
                ),
              ],
            ),
          ),
        );
      }
    }
    

    In this code, we have used TextFormField to get the email and password input from the user. We have also used ElevatedButton to create the sign-in button and added necessary validations to the form fields using the validator property.

    You can further customize the UI and add authentication logic to this page based on your requirements.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.