Scalar Presence: brand-panel login (light/dark), Poppins, splash and launcher icons, fixed API base via dart-define, keep-signed-in, Android project

- Login reworked to the Brand panel layout with a dark-theme switch; 'Scalar Presence' two-line wordmark
- Android project now tracked (was gitignored); pins shared_preferences_android 2.4.27 (2.5.0 crashed with a black screen)
- API base URL fixed per build (--dart-define=API_BASE_URL), no in-app server setting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
athul rd
2026-10-19 15:51:09 +05:30
co-authored by Claude Opus 5.5
parent 19a79d6126
commit 2dbd1a2ea9
66 changed files with 1463 additions and 140 deletions
+84 -77
View File
@@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import '../api_service.dart';
import '../settings.dart';
import '../theme.dart';
import 'auth_shell.dart';
import 'home_screen.dart';
import 'settings_screen.dart';
class LoginScreen extends StatefulWidget {
final ApiService api;
@@ -19,15 +18,32 @@ class _LoginScreenState extends State<LoginScreen> {
final _pin = TextEditingController();
bool _busy = false;
String? _error;
/// Zoho-style: the email first, then the PIN on its own step.
bool _askPin = false;
bool _keep = true;
static final _emailPattern = RegExp(r'^[^@\s]+@[^@\s]+\.[^@\s]+$');
void _next() {
final email = _email.text.trim();
if (!_emailPattern.hasMatch(email)) {
setState(() => _error = 'Enter a valid work email address');
return;
}
setState(() { _askPin = true; _error = null; });
}
void _change() => setState(() { _askPin = false; _pin.clear(); _error = null; });
Future<void> _login() async {
if (_email.text.trim().isEmpty || _pin.text.isEmpty) {
setState(() => _error = 'Enter your work email and PIN');
if (_pin.text.isEmpty) {
setState(() => _error = 'Enter your PIN');
return;
}
setState(() { _busy = true; _error = null; });
try {
await widget.api.login(_email.text, _pin.text);
await widget.api.login(_email.text.trim(), _pin.text);
await KeepSignedIn.save(_keep);
if (!mounted) return;
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (_) => HomeScreen(api: widget.api, settings: widget.settings)));
@@ -38,82 +54,73 @@ class _LoginScreenState extends State<LoginScreen> {
}
}
void _forgotEmail() {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Use the work email HR added you with. Not sure which one? Ask your HR or manager.'),
behavior: SnackBarBehavior.floating,
));
}
void _forgotPin() {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Your PIN is set by HR. Ask your HR or manager to reset it.'),
behavior: SnackBarBehavior.floating,
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Row(children: [
Container(
width: 40, height: 40,
decoration: BoxDecoration(color: AppColors.emerald, borderRadius: BorderRadius.circular(12)),
child: const Icon(Icons.badge_outlined, color: Colors.white),
),
const SizedBox(width: 10),
const Text('Scalar360', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: AppColors.navy)),
]),
IconButton(
icon: const Icon(Icons.settings_outlined, color: AppColors.muted),
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (_) => SettingsScreen(settings: widget.settings))),
),
]),
const SizedBox(height: 28),
const Text('Employee sign in',
style: TextStyle(fontSize: 26, fontWeight: FontWeight.bold, color: AppColors.navy)),
const SizedBox(height: 4),
const Text('Use your work email and the PIN from HR', style: TextStyle(color: AppColors.muted)),
const SizedBox(height: 24),
TextField(
controller: _email,
keyboardType: TextInputType.emailAddress,
autocorrect: false,
decoration: const InputDecoration(labelText: 'Work email', prefixIcon: Icon(Icons.mail_outline)),
),
const SizedBox(height: 14),
TextField(
controller: _pin,
obscureText: true,
keyboardType: TextInputType.number,
onSubmitted: (_) => _login(),
decoration: const InputDecoration(labelText: 'PIN', prefixIcon: Icon(Icons.pin_outlined)),
),
if (_error != null) ...[
const SizedBox(height: 14),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(color: AppColors.danger.withValues(alpha: 0.08), borderRadius: BorderRadius.circular(12)),
child: Row(children: [
const Icon(Icons.error_outline, color: AppColors.danger, size: 18),
const SizedBox(width: 8),
Expanded(child: Text(_error!, style: const TextStyle(color: AppColors.danger))),
]),
),
],
const SizedBox(height: 22),
FilledButton(
onPressed: _busy ? null : _login,
child: _busy
? const SizedBox(height: 22, width: 22, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
: const Text('Sign in'),
),
const SizedBox(height: 16),
Text('Server: ${widget.settings.baseUrl}',
textAlign: TextAlign.center, style: const TextStyle(color: AppColors.muted, fontSize: 12)),
],
),
),
if (_askPin) {
return AuthShell(
appName: 'Scalar Presence',
product: 'Presence',
tagline: 'Check in, apply for leave and see your payslips.',
title: 'Enter PIN',
children: [
AuthIdentity(value: _email.text.trim(), onBack: _busy ? () {} : _change),
const SizedBox(height: 16),
if (_error != null) AuthError(_error!),
AuthField(
key: const ValueKey('pin'),
controller: _pin,
hint: 'PIN',
icon: Icons.lock_outline,
secret: true,
autofocus: true,
error: _error != null,
keyboardType: TextInputType.number,
action: TextInputAction.done,
onSubmitted: (_) => _login(),
),
const SizedBox(height: 12),
AuthLink('Forgot PIN?', onPressed: _forgotPin),
AuthKeepSignedIn(value: _keep, onChanged: (v) => setState(() => _keep = v)),
const SizedBox(height: 20),
AuthButton(label: 'Sign in', busy: _busy, onPressed: _login),
],
);
}
return AuthShell(
appName: 'Scalar Presence',
product: 'Presence',
tagline: 'Check in, apply for leave and see your payslips.',
children: [
if (_error != null) AuthError(_error!),
AuthField(
key: const ValueKey('email'),
controller: _email,
hint: 'Work email',
icon: Icons.mail_outline,
error: _error != null,
keyboardType: TextInputType.emailAddress,
action: TextInputAction.next,
onSubmitted: (_) => _next(),
),
),
const SizedBox(height: 12),
AuthLink('Forgot email?', onPressed: _forgotEmail),
const SizedBox(height: 28),
AuthButton(label: 'Next', busy: false, onPressed: _next),
],
);
}
}