Update Saqel Platform: 2026-09-08 13:43:36
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/repositories/super_admin_repository.dart';
|
||||
|
||||
class SuperAdminAuthScreen extends StatefulWidget {
|
||||
final SuperAdminRepository repository;
|
||||
final VoidCallback onAuthenticated;
|
||||
|
||||
const SuperAdminAuthScreen({super.key, required this.repository, required this.onAuthenticated});
|
||||
|
||||
@override
|
||||
State<SuperAdminAuthScreen> createState() => _SuperAdminAuthScreenState();
|
||||
}
|
||||
|
||||
class _SuperAdminAuthScreenState extends State<SuperAdminAuthScreen> {
|
||||
final _phone = TextEditingController();
|
||||
final _otp = TextEditingController();
|
||||
bool _sent = false;
|
||||
bool _busy = false;
|
||||
String? _error;
|
||||
|
||||
Future<void> _submit() async {
|
||||
setState(() { _busy = true; _error = null; });
|
||||
try {
|
||||
if (_sent) {
|
||||
await widget.repository.verifyOtp(_phone.text.trim(), _otp.text.trim());
|
||||
widget.onAuthenticated();
|
||||
} else {
|
||||
await widget.repository.requestOtp(_phone.text.trim());
|
||||
if (mounted) setState(() => _sent = true);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) setState(() => _error = e.toString().replaceFirst('Bad state: ', ''));
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() { _phone.dispose(); _otp.dispose(); super.dispose(); }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 420),
|
||||
child: Card(
|
||||
margin: const EdgeInsets.all(24),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(28),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
||||
const Text('القيادة السيادية', style: TextStyle(fontSize: 28, fontWeight: FontWeight.w900)),
|
||||
const SizedBox(height: 8),
|
||||
const Text('حساب سوبر أدمن مخوّل مسبقاً فقط'),
|
||||
const SizedBox(height: 22),
|
||||
TextField(controller: _phone, enabled: !_sent, keyboardType: TextInputType.phone, decoration: const InputDecoration(labelText: 'رقم الهاتف')),
|
||||
if (_sent) ...[
|
||||
const SizedBox(height: 14),
|
||||
TextField(controller: _otp, keyboardType: TextInputType.number, decoration: const InputDecoration(labelText: 'رمز التحقق')),
|
||||
],
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: 14),
|
||||
Text(_error!, style: const TextStyle(color: Colors.redAccent)),
|
||||
],
|
||||
const SizedBox(height: 22),
|
||||
FilledButton(onPressed: _busy ? null : _submit, child: Text(_busy ? 'جارٍ التحقق…' : (_sent ? 'دخول' : 'إرسال الرمز'))),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user