Getting Started with Flutter + Firebase Authentication

Short guide: sign in with email & password.

Introduction

Authentication is one of the most common features in mobile apps. With Firebase, Flutter developers can quickly implement secure login systems. In this guide, we’ll walk through setting up email and password authentication using Firebase in Flutter.


Step 1: Add Firebase to Your Flutter Project

  1. Create a Firebase project at Firebase Console.
  2. Register your iOS/Android app and download the google-services.json (Android) or GoogleService-Info.plist (iOS).
  3. Add the Firebase SDK dependencies in your pubspec.yaml:
dependencies:
  firebase_core: ^3.0.0
  firebase_auth: ^5.0.0
  1. Initialize Firebase in main.dart:
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const MyApp());
}

Step 2: Implement Authentication Methods

import 'package:firebase_auth/firebase_auth.dart';

class AuthService {
  final FirebaseAuth _auth = FirebaseAuth.instance;

  // Sign up with email & password
  Future<User?> signUp(String email, String password) async {
    final userCredential = await _auth.createUserWithEmailAndPassword(
      email: email,
      password: password,
    );
    return userCredential.user;
  }

  // Sign in with email & password
  Future<User?> signIn(String email, String password) async {
    final userCredential = await _auth.signInWithEmailAndPassword(
      email: email,
      password: password,
    );
    return userCredential.user;
  }

  // Sign out
  Future<void> signOut() async {
    await _auth.signOut();
  }
}

Step 3: Simple UI for Login

class LoginScreen extends StatefulWidget {
  @override
  _LoginScreenState createState() => _LoginScreenState();
}

class _LoginScreenState extends State<LoginScreen> {
  final emailController = TextEditingController();
  final passwordController = TextEditingController();
  final authService = AuthService();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Login")),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          children: [
            TextField(controller: emailController, decoration: const InputDecoration(labelText: "Email")),
            TextField(controller: passwordController, decoration: const InputDecoration(labelText: "Password"), obscureText: true),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () async {
                await authService.signIn(emailController.text, passwordController.text);
              },
              child: const Text("Sign In"),
            )
          ],
        ),
      ),
    );
  }
}

Conclusion

With just a few lines of code, you’ve set up Firebase Authentication in Flutter. From here, you can extend authentication with Google, Facebook, or phone number logins.


Posted

in

,

by

Tags:

Comments

13 responses to “Getting Started with Flutter + Firebase Authentication”

  1. jili pg Avatar

    Interesting analysis! The shift towards mobile gaming is huge, and platforms like JILI PG are capitalizing on that. Easy access via the jili pg app download is key for players in the Philippines – convenience wins! Great insights on game algorithms too.

  2. 188bet apk Avatar

    The 188bet apk is the only way to go mobile. 188betzokb offers apk link, easy to download! Download it here: 188bet apk.

  3. jljl55 Avatar

    That’s a solid point about in-game strategy impacting betting! Seeing platforms like JLJL55 cater specifically to Filipino players with easy GCash deposits is great. Check out the jljl55 download for a smooth gaming experience – might help refine those predictions! 😉

  4. taigameb66clubapk Avatar

    Right then, time to give this taigameb66clubapk a look-see. Heard it’s got some decent games. Let’s hope my luck’s in!

  5. 1winlogin Avatar

    Tried logging into 1winlogin last night. Seemed pretty smooth. Hoping my win is just as smooth today!

  6. betap Avatar

    Anyone tried betap yet? I’m always hunting for new betting platforms. Let me know if it’s worth my time and money, fam!

  7. chillbetnet Avatar

    Chillbetnet, eh? Been hearing whispers around town. Gotta check it out, see if it lives up to the hype. Hopefully not just another flash-in-the-pan. Fingers crossed for some real fun and good payouts! Check it out yourself at chillbetnet!

  8. lebullcasino Avatar

    Heard some buzz about lebullcasino. Decided to see what all the fuss was about. It’s alright, good selection of games. Could be a good time waster with a chance to snag some serious cash. Check it out: lebullcasino

  9. casinovenus Avatar

    Casinovenus, eh? Had a little wander around their site, pretty decent setup. Nothing that blew my socks off, but definitely worth a look if you’re looking for another place to try your luck. Get started: casinovenus

  10. jilimk Avatar

    Interesting points about strategic play! Thinking about account security & provably fair systems-like those at jilimk slot-is key for long-term success. Solid KYC protocols are a must, too!

  11. playkaro Avatar

    Been using Playkaro for a bit now and it’s got its perks. Loads fast, which is a big win for me. Give it a go! playkaro

  12. playtime ph download Avatar

    Looking for Playtime PH download, hopefully this is the one. Trying to keep my phone safe! Check it out if you’re brave: playtime ph download

  13. adda52 apk Avatar

    Anyone have the Adda52 APK? Wanna play on my phone while I’m waiting for my laundry. You can download from here: adda52 apk

Leave a Reply

Your email address will not be published. Required fields are marked *