Skip to main content

auth_logic 1.0.1 copy "auth_logic: ^1.0.1" to clipboard
auth_logic: ^1.0.1 copied to clipboard

Production-ready Flutter auth package with MVVM + Cubit. Login, register, OTP, token refresh, retry, and colored network logs.

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:auth_logic/auth_logic.dart';

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'auth_logic Example',
      home: const LoginScreen(),
    );
  }
}

class LoginScreen extends StatelessWidget {
  const LoginScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => LoginViewModel(
        authService: AuthDependencies.create().authService,
      ),
      child: BlocConsumer<LoginViewModel, LoginState>(
        listener: (context, state) {
          if (state.status == LoginStatus.success) {
            ScaffoldMessenger.of(context).showSnackBar(
              const SnackBar(content: Text('Login successful!')),
            );
          } else if (state.status == LoginStatus.failure) {
            ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(content: Text(state.errorMessage ?? 'Login failed')),
            );
          }
        },
        builder: (context, state) {
          return Scaffold(
            appBar: AppBar(title: const Text('Login')),
            body: Padding(
              padding: const EdgeInsets.all(16),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextField(
                    decoration: const InputDecoration(
                      labelText: 'Phone or Email',
                      border: OutlineInputBorder(),
                    ),
                    onSubmitted: (_) {},
                  ),
                  const SizedBox(height: 16),
                  TextField(
                    obscureText: true,
                    decoration: const InputDecoration(
                      labelText: 'Password',
                      border: OutlineInputBorder(),
                    ),
                    onSubmitted: (_) {},
                  ),
                  const SizedBox(height: 24),
                  SizedBox(
                    width: double.infinity,
                    child: ElevatedButton(
                      onPressed: state.status == LoginStatus.loading
                          ? null
                          : () {
                              context.read<LoginViewModel>().login(
                                    login: '+1234567890',
                                    password: 'password',
                                    locale: 'en', fcmToken: '', deviceId: '', deviceType: '',
                                  );
                            },
                      child: state.status == LoginStatus.loading
                          ? const CircularProgressIndicator()
                          : const Text('Login'),
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}
1
likes
145
points
232
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Production-ready Flutter auth package with MVVM + Cubit. Login, register, OTP, token refresh, retry, and colored network logs.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

device_info_plus, dio, equatable, firebase_core, firebase_messaging, flutter, flutter_bloc, google_sign_in, image_picker, phone_numbers_parser, shared_preferences, sign_in_with_apple

More

Packages that depend on auth_logic