dot_auth 1.0.0 copy "dot_auth: ^1.0.0" to clipboard
dot_auth: ^1.0.0 copied to clipboard

A powerful Flutter authentication package with phone number OTP verification using Firebase. Features Riverpod state management, GoRouter integration, and customizable UI.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:dot_auth/dot_auth.dart';

// This file is generated by flutterfire configure
import 'firebase_options.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize ScreenUtil
  await ScreenUtil.ensureScreenSize();

  // Initialize Firebase
  try {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
    print('✅ Firebase initialized successfully');
  } catch (e) {
    print('''
    ═══════════════════════════════════════════════════════════
    ❌ Firebase not configured!
    
    Please run the following commands in the example directory:
    
    1. flutter pub add firebase_core firebase_auth
    2. flutter pub add -d flutterfire_cli  
    3. flutterfire configure
    
    Then select your Firebase project.
    ═══════════════════════════════════════════════════════════
    ''');
    rethrow;
  }

  runApp(const ProviderScope(child: MyApp()));
}

class MyApp extends ConsumerWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final router = AuthRouter.createRouter(
      ref: ref,
      homeRoute: '/home',
      homeBuilder: (context, state) => const HomePage(),
    );

    return ScreenUtilInit(
      designSize: const Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (_, child) {
        return MaterialApp.router(
          title: 'Dot Auth Example',
          theme: authTheme(),
          routerConfig: router,
          debugShowCheckedModeBanner: false,
        );
      },
    );
  }
}

class HomePage extends ConsumerWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final user = ref.watch(currentUserProvider);

    return Scaffold(
      appBar: AppBar(
        title: const Text('Home'),
        actions: [
          IconButton(
            icon: const Icon(Icons.logout),
            onPressed: () async {
              await ref
                  .read(authStateProvider.notifier)
                  .signOut();
              if (context.mounted) {
                // Use pushReplacement instead of go
                context.pushReplacement('/phone');
              }
            },
          ),
        ],
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text(
              'Welcome to Dot Auth!',
              style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 20),
            Text(
              'Phone: ${user?.phoneNumber ?? "N/A"}',
              style: const TextStyle(fontSize: 16),
            ),
            const SizedBox(height: 10),
            Text(
              'UID: ${user?.uid ?? "N/A"}',
              style: const TextStyle(
                  fontSize: 12, color: Colors.grey),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
0
points
400
downloads

Publisher

unverified uploader

Weekly Downloads

A powerful Flutter authentication package with phone number OTP verification using Firebase. Features Riverpod state management, GoRouter integration, and customizable UI.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

animations, firebase_auth, firebase_core, flutter, flutter_riverpod, flutter_screenutil, go_router, google_fonts, phone_form_field, pinput

More

Packages that depend on dot_auth