auth_logic 1.0.1
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.
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'),
),
),
],
),
),
);
},
),
);
}
}