- Migrate AuthBloc → MitraAuthNotifier (fixes stuck-loading bug: now returns MitraAuthInitialData when currentUser is null) - Migrate StatusBloc → OnlineStatusNotifier (heartbeat timer + lifecycle) - Migrate ExtensionBloc → MitraExtensionNotifier (accept/reject + goodbye) - Migrate ChatRequestBloc → ChatRequestNotifier (WebSocket incoming requests) - Migrate MitraChatBloc → MitraChatNotifier (WebSocket chat + messages) - Update router to use Riverpod auth state for redirects - Remove all flutter_bloc usage from mitra_app screens and main.dart - MultiBlocProvider fully removed from mitra_app Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
78 lines
2.4 KiB
Dart
78 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../core/auth/auth_notifier.dart';
|
|
|
|
class LoginScreen extends ConsumerStatefulWidget {
|
|
const LoginScreen({super.key});
|
|
|
|
@override
|
|
ConsumerState<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends ConsumerState<LoginScreen> {
|
|
final _phoneController = TextEditingController();
|
|
|
|
@override
|
|
void dispose() {
|
|
_phoneController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final authState = ref.watch(mitraAuthProvider);
|
|
final isLoading = authState is AsyncLoading;
|
|
|
|
ref.listen(mitraAuthProvider, (prev, next) {
|
|
final data = next.valueOrNull;
|
|
if (data is MitraAuthOtpSentData) {
|
|
context.push('/otp', extra: _phoneController.text.trim());
|
|
}
|
|
if (next is AsyncError) {
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(next.error.toString())));
|
|
}
|
|
});
|
|
|
|
return Scaffold(
|
|
body: SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const Text(
|
|
'Halo Bestie Mitra',
|
|
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 48),
|
|
TextField(
|
|
controller: _phoneController,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Nomor HP',
|
|
hintText: '+628xxxxxxxxxx',
|
|
border: OutlineInputBorder(),
|
|
),
|
|
keyboardType: TextInputType.phone,
|
|
),
|
|
const SizedBox(height: 16),
|
|
ElevatedButton(
|
|
onPressed: isLoading ? null : () {
|
|
final phone = _phoneController.text.trim();
|
|
if (phone.isEmpty) return;
|
|
ref.read(mitraAuthProvider.notifier).requestOtp(phone);
|
|
},
|
|
child: isLoading
|
|
? const CircularProgressIndicator()
|
|
: const Text('Kirim OTP'),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|