Initial commit: Flutter app + PHP/MySQL backend on Hostinger
Replaces Firebase with a self-hosted PHP/MySQL API served from winded.prymsolutions.com. Includes full backend (schema, auth, events, teams, brackets, suggestions, stats, media, file upload) and updated Flutter repositories and domain models. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../../core/api/api_client.dart';
|
||||
import '../domain/app_user.dart';
|
||||
import '../infrastructure/auth_repository.dart';
|
||||
|
||||
part 'auth_notifier.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class AuthNotifier extends _$AuthNotifier {
|
||||
@override
|
||||
Future<AppUser?> build() async {
|
||||
final repo = ref.watch(authRepositoryProvider);
|
||||
|
||||
final completer = Completer<AppUser?>();
|
||||
final sub = repo.authStateChanges().listen(
|
||||
(user) {
|
||||
if (!completer.isCompleted) {
|
||||
completer.complete(user);
|
||||
} else {
|
||||
state = AsyncData(user);
|
||||
}
|
||||
},
|
||||
onError: (Object error, StackTrace stack) {
|
||||
if (!completer.isCompleted) {
|
||||
completer.completeError(error, stack);
|
||||
} else {
|
||||
state = AsyncError(error, stack);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
ref.onDispose(sub.cancel);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
Future<void> signIn({
|
||||
required String email,
|
||||
required String password,
|
||||
}) async {
|
||||
final repo = ref.read(authRepositoryProvider);
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
() => repo.signInWithEmail(email: email, password: password),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> register({
|
||||
required String email,
|
||||
required String password,
|
||||
required String displayName,
|
||||
}) async {
|
||||
final repo = ref.read(authRepositoryProvider);
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(
|
||||
() => repo.registerWithEmail(
|
||||
email: email,
|
||||
password: password,
|
||||
displayName: displayName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> signOut() async {
|
||||
final repo = ref.read(authRepositoryProvider);
|
||||
state = const AsyncLoading();
|
||||
state = await AsyncValue.guard(() async {
|
||||
await repo.signOut();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Maps an [ApiException] or generic error to a friendly message.
|
||||
String authErrorMessage(Object error) {
|
||||
if (error is ApiException) {
|
||||
final msg = error.message.toLowerCase();
|
||||
if (msg.contains('email already')) return 'An account already exists for that email.';
|
||||
if (msg.contains('invalid email')) return 'That email address looks invalid.';
|
||||
if (msg.contains('password')) return 'Password must be at least 6 characters.';
|
||||
if (msg.contains('invalid email or password')) return 'Incorrect email or password.';
|
||||
return error.message;
|
||||
}
|
||||
return 'Something went wrong. Please try again.';
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||
|
||||
part of 'auth_notifier.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$authNotifierHash() => r'c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4';
|
||||
|
||||
/// See also [AuthNotifier].
|
||||
@ProviderFor(AuthNotifier)
|
||||
final authNotifierProvider =
|
||||
AsyncNotifierProvider<AuthNotifier, AppUser?>.internal(
|
||||
AuthNotifier.new,
|
||||
name: r'authNotifierProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$authNotifierHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$AuthNotifier = AsyncNotifier<AppUser?>;
|
||||
@@ -0,0 +1,48 @@
|
||||
/// Immutable domain model representing an authenticated Winded user.
|
||||
///
|
||||
/// This is a pure-Dart model intentionally decoupled from Firebase types so
|
||||
/// the rest of the app can depend on it without pulling in firebase_auth.
|
||||
class AppUser {
|
||||
const AppUser({
|
||||
required this.uid,
|
||||
required this.email,
|
||||
this.displayName,
|
||||
this.photoUrl,
|
||||
});
|
||||
|
||||
final String uid;
|
||||
final String email;
|
||||
final String? displayName;
|
||||
final String? photoUrl;
|
||||
|
||||
AppUser copyWith({
|
||||
String? uid,
|
||||
String? email,
|
||||
String? displayName,
|
||||
String? photoUrl,
|
||||
}) {
|
||||
return AppUser(
|
||||
uid: uid ?? this.uid,
|
||||
email: email ?? this.email,
|
||||
displayName: displayName ?? this.displayName,
|
||||
photoUrl: photoUrl ?? this.photoUrl,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other is AppUser &&
|
||||
other.uid == uid &&
|
||||
other.email == email &&
|
||||
other.displayName == displayName &&
|
||||
other.photoUrl == photoUrl;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(uid, email, displayName, photoUrl);
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'AppUser(uid: $uid, email: $email, displayName: $displayName)';
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../../core/api/api_client.dart';
|
||||
import '../domain/app_user.dart';
|
||||
|
||||
part 'auth_repository.g.dart';
|
||||
|
||||
/// Manages auth state backed by the PHP/MySQL API.
|
||||
///
|
||||
/// Because the backend has no push mechanism, auth state is held in memory and
|
||||
/// exposed via a [StreamController]. Sign-in and registration update the stream
|
||||
/// immediately; the token is persisted in [FlutterSecureStorage] via [ApiClient].
|
||||
class AuthRepository {
|
||||
AuthRepository(this._api) {
|
||||
_init();
|
||||
}
|
||||
|
||||
final ApiClient _api;
|
||||
final _controller = StreamController<AppUser?>.broadcast();
|
||||
|
||||
Stream<AppUser?> authStateChanges() => _controller.stream;
|
||||
AppUser? get currentUser => _currentUser;
|
||||
AppUser? _currentUser;
|
||||
|
||||
Future<void> _init() async {
|
||||
final token = await _api.token;
|
||||
if (token == null) {
|
||||
_emit(null);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final data = await _api.get('/auth/me.php');
|
||||
final user = _mapUser(data);
|
||||
_emit(user);
|
||||
} catch (_) {
|
||||
await _api.clearToken();
|
||||
_emit(null);
|
||||
}
|
||||
}
|
||||
|
||||
Future<AppUser?> signInWithEmail({
|
||||
required String email,
|
||||
required String password,
|
||||
}) async {
|
||||
final data = await _api.post(
|
||||
'/auth/login.php',
|
||||
{'email': email.trim(), 'password': password},
|
||||
auth: false,
|
||||
);
|
||||
await _api.saveToken(data['token'] as String);
|
||||
final user = _mapUser(data['user'] as Map<String, dynamic>);
|
||||
_emit(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
Future<AppUser?> registerWithEmail({
|
||||
required String email,
|
||||
required String password,
|
||||
String? displayName,
|
||||
}) async {
|
||||
final data = await _api.post(
|
||||
'/auth/register.php',
|
||||
{
|
||||
'email': email.trim(),
|
||||
'password': password,
|
||||
'display_name': displayName?.trim() ?? '',
|
||||
},
|
||||
auth: false,
|
||||
);
|
||||
await _api.saveToken(data['token'] as String);
|
||||
final user = _mapUser(data['user'] as Map<String, dynamic>);
|
||||
_emit(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
Future<void> signOut() async {
|
||||
await _api.clearToken();
|
||||
_emit(null);
|
||||
}
|
||||
|
||||
void _emit(AppUser? user) {
|
||||
_currentUser = user;
|
||||
_controller.add(user);
|
||||
}
|
||||
|
||||
AppUser? _mapUser(Map<String, dynamic> data) {
|
||||
final id = data['id'] as String?;
|
||||
if (id == null || id.isEmpty) return null;
|
||||
return AppUser(
|
||||
uid: id,
|
||||
email: (data['email'] as String?) ?? '',
|
||||
displayName: data['display_name'] as String?,
|
||||
photoUrl: data['photo_url'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
void dispose() => _controller.close();
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
AuthRepository authRepository(AuthRepositoryRef ref) {
|
||||
final repo = AuthRepository(ref.watch(apiClientProvider));
|
||||
ref.onDispose(repo.dispose);
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Stream<AppUser?> authStateChanges(AuthStateChangesRef ref) {
|
||||
return ref.watch(authRepositoryProvider).authStateChanges();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package, deprecated_member_use
|
||||
|
||||
part of 'auth_repository.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$authRepositoryHash() => r'a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2';
|
||||
|
||||
/// See also [authRepository].
|
||||
@ProviderFor(authRepository)
|
||||
final authRepositoryProvider = Provider<AuthRepository>.internal(
|
||||
authRepository,
|
||||
name: r'authRepositoryProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$authRepositoryHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef AuthRepositoryRef = ProviderRef<AuthRepository>;
|
||||
|
||||
String _$authStateChangesHash() => r'b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3';
|
||||
|
||||
/// See also [authStateChanges].
|
||||
@ProviderFor(authStateChanges)
|
||||
final authStateChangesProvider = StreamProvider<AppUser?>.internal(
|
||||
authStateChanges,
|
||||
name: r'authStateChangesProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$authStateChangesHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef AuthStateChangesRef = StreamProviderRef<AppUser?>;
|
||||
@@ -0,0 +1,237 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../application/auth_notifier.dart';
|
||||
import 'widgets/winded_brand_header.dart';
|
||||
|
||||
class LoginScreen extends ConsumerStatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
static const _purple = Color(0xFF8B30C8);
|
||||
static const _purpleLight = Color(0xFFBF77F6);
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _emailCtrl = TextEditingController();
|
||||
final _passwordCtrl = TextEditingController();
|
||||
bool _obscurePassword = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailCtrl.dispose();
|
||||
_passwordCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
final form = _formKey.currentState;
|
||||
if (form == null || !form.validate()) return;
|
||||
FocusScope.of(context).unfocus();
|
||||
|
||||
await ref.read(authNotifierProvider.notifier).signIn(
|
||||
email: _emailCtrl.text,
|
||||
password: _passwordCtrl.text,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
final state = ref.read(authNotifierProvider);
|
||||
if (state.hasError) {
|
||||
final message = authErrorMessage(state.error!);
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
// Successful sign-in triggers router redirect via auth stream — no
|
||||
// manual navigation needed here.
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final authState = ref.watch(authNotifierProvider);
|
||||
final isLoading = authState.isLoading;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surface,
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 440),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const WindedBrandHeader(),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'SIGN IN TO YOUR PITCH',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
letterSpacing: 2.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A1A),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: const Color(0xFF3A3A3A)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 3,
|
||||
decoration: const BoxDecoration(
|
||||
color: _purple,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(4)),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _emailCtrl,
|
||||
enabled: !isLoading,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autofillHints: const [AutofillHints.email],
|
||||
textInputAction: TextInputAction.next,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'EMAIL',
|
||||
prefixIcon: Icon(Icons.email_outlined),
|
||||
),
|
||||
validator: _validateEmail,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _passwordCtrl,
|
||||
enabled: !isLoading,
|
||||
obscureText: _obscurePassword,
|
||||
autofillHints: const [AutofillHints.password],
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _submit(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'PASSWORD',
|
||||
prefixIcon: const Icon(Icons.lock_outline),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscurePassword
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
),
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () => setState(() {
|
||||
_obscurePassword =
|
||||
!_obscurePassword;
|
||||
}),
|
||||
),
|
||||
),
|
||||
validator: (v) {
|
||||
if (v == null || v.isEmpty) {
|
||||
return 'Enter your password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton(
|
||||
onPressed: isLoading ? null : _submit,
|
||||
style: FilledButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(52),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(4)),
|
||||
),
|
||||
),
|
||||
child: isLoading
|
||||
? SizedBox(
|
||||
width: 22,
|
||||
height: 22,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.5,
|
||||
color: colors.onPrimary,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'SIGN IN',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 2.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'NEW HERE? ',
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
letterSpacing: 1.5,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () => context.go('/register'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: _purpleLight,
|
||||
textStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 1.5,
|
||||
),
|
||||
),
|
||||
child: const Text('CREATE AN ACCOUNT'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String? _validateEmail(String? value) {
|
||||
final trimmed = value?.trim() ?? '';
|
||||
if (trimmed.isEmpty) return 'Enter your email';
|
||||
final emailRegex = RegExp(r'^[^\s@]+@[^\s@]+\.[^\s@]+$');
|
||||
if (!emailRegex.hasMatch(trimmed)) return 'Enter a valid email address';
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,392 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../profile/domain/user_profile.dart';
|
||||
import '../../profile/infrastructure/profile_repository.dart';
|
||||
import '../application/auth_notifier.dart';
|
||||
import 'widgets/winded_brand_header.dart';
|
||||
|
||||
class RegisterScreen extends ConsumerStatefulWidget {
|
||||
const RegisterScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<RegisterScreen> createState() => _RegisterScreenState();
|
||||
}
|
||||
|
||||
class _RegisterScreenState extends ConsumerState<RegisterScreen> {
|
||||
static const _purple = Color(0xFF8B30C8);
|
||||
static const _purpleLight = Color(0xFFBF77F6);
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _nameCtrl = TextEditingController();
|
||||
final _emailCtrl = TextEditingController();
|
||||
final _passwordCtrl = TextEditingController();
|
||||
final _confirmCtrl = TextEditingController();
|
||||
bool _obscurePassword = true;
|
||||
bool _obscureConfirm = true;
|
||||
UserRole _selectedRole = UserRole.player;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameCtrl.dispose();
|
||||
_emailCtrl.dispose();
|
||||
_passwordCtrl.dispose();
|
||||
_confirmCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
final form = _formKey.currentState;
|
||||
if (form == null || !form.validate()) return;
|
||||
FocusScope.of(context).unfocus();
|
||||
|
||||
final displayName = _nameCtrl.text.trim();
|
||||
final email = _emailCtrl.text.trim();
|
||||
|
||||
await ref.read(authNotifierProvider.notifier).register(
|
||||
email: email,
|
||||
password: _passwordCtrl.text,
|
||||
displayName: displayName,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
final state = ref.read(authNotifierProvider);
|
||||
if (state.hasError) {
|
||||
final message = authErrorMessage(state.error!);
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(content: Text(message)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Auth succeeded — write the matching Firestore profile so role-based
|
||||
// gates work immediately. Failures here are surfaced but don't block the
|
||||
// sign-in flow because the user is already authenticated.
|
||||
final user = state.valueOrNull;
|
||||
if (user != null) {
|
||||
try {
|
||||
await ref.read(profileRepositoryProvider).createProfile(
|
||||
UserProfile(
|
||||
uid: user.uid,
|
||||
email: user.email,
|
||||
displayName: displayName.isEmpty
|
||||
? (user.displayName ?? '')
|
||||
: displayName,
|
||||
role: _selectedRole,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(
|
||||
SnackBar(content: Text('Could not create profile: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// On success, Firebase auth stream emits the new user, AuthNotifier
|
||||
// updates, and the router redirect sends us to /events.
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final authState = ref.watch(authNotifierProvider);
|
||||
final isLoading = authState.isLoading;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: colors.surface,
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 32),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 440),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const WindedBrandHeader(),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'JOIN THE LEAGUE',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
letterSpacing: 2.0,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A1A),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: const Color(0xFF3A3A3A)),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 3,
|
||||
decoration: const BoxDecoration(
|
||||
color: _purple,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(4)),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _nameCtrl,
|
||||
enabled: !isLoading,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
autofillHints: const [AutofillHints.name],
|
||||
textInputAction: TextInputAction.next,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'DISPLAY NAME',
|
||||
prefixIcon: Icon(Icons.person_outline),
|
||||
),
|
||||
validator: (v) {
|
||||
final trimmed = v?.trim() ?? '';
|
||||
if (trimmed.isEmpty) {
|
||||
return 'Enter your name';
|
||||
}
|
||||
if (trimmed.length < 2) {
|
||||
return 'Name must be at least 2 characters';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _emailCtrl,
|
||||
enabled: !isLoading,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autofillHints: const [AutofillHints.email],
|
||||
textInputAction: TextInputAction.next,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'EMAIL',
|
||||
prefixIcon: Icon(Icons.email_outlined),
|
||||
),
|
||||
validator: (v) {
|
||||
final trimmed = v?.trim() ?? '';
|
||||
if (trimmed.isEmpty) {
|
||||
return 'Enter your email';
|
||||
}
|
||||
final emailRegex = RegExp(
|
||||
r'^[^\s@]+@[^\s@]+\.[^\s@]+$',
|
||||
);
|
||||
if (!emailRegex.hasMatch(trimmed)) {
|
||||
return 'Enter a valid email address';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _passwordCtrl,
|
||||
enabled: !isLoading,
|
||||
obscureText: _obscurePassword,
|
||||
autofillHints: const [AutofillHints.newPassword],
|
||||
textInputAction: TextInputAction.next,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'PASSWORD',
|
||||
prefixIcon: const Icon(Icons.lock_outline),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscurePassword
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
),
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () => setState(() {
|
||||
_obscurePassword =
|
||||
!_obscurePassword;
|
||||
}),
|
||||
),
|
||||
helperText: 'At least 6 characters',
|
||||
),
|
||||
validator: (v) {
|
||||
if (v == null || v.isEmpty) {
|
||||
return 'Enter a password';
|
||||
}
|
||||
if (v.length < 6) {
|
||||
return 'Password must be at least 6 characters';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _confirmCtrl,
|
||||
enabled: !isLoading,
|
||||
obscureText: _obscureConfirm,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _submit(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'CONFIRM PASSWORD',
|
||||
prefixIcon: const Icon(Icons.lock_outline),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureConfirm
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
),
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () => setState(() {
|
||||
_obscureConfirm = !_obscureConfirm;
|
||||
}),
|
||||
),
|
||||
),
|
||||
validator: (v) {
|
||||
if (v == null || v.isEmpty) {
|
||||
return 'Confirm your password';
|
||||
}
|
||||
if (v != _passwordCtrl.text) {
|
||||
return 'Passwords do not match';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'I AM A',
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
letterSpacing: 1.8,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SegmentedButton<UserRole>(
|
||||
segments: const <ButtonSegment<UserRole>>[
|
||||
ButtonSegment<UserRole>(
|
||||
value: UserRole.player,
|
||||
label: Text('PLAYER'),
|
||||
icon: Icon(Icons.sports_soccer),
|
||||
),
|
||||
ButtonSegment<UserRole>(
|
||||
value: UserRole.manager,
|
||||
label: Text('MANAGER'),
|
||||
icon: Icon(Icons.shield_outlined),
|
||||
),
|
||||
],
|
||||
selected: <UserRole>{_selectedRole},
|
||||
onSelectionChanged: isLoading
|
||||
? null
|
||||
: (set) => setState(
|
||||
() => _selectedRole = set.first,
|
||||
),
|
||||
showSelectedIcon: false,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_selectedRole == UserRole.manager
|
||||
? 'Managers create and run a team. New teams '
|
||||
'require admin approval.'
|
||||
: 'Players have a personal profile and can '
|
||||
'request to join a team.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
FilledButton(
|
||||
onPressed: isLoading ? null : _submit,
|
||||
style: FilledButton.styleFrom(
|
||||
minimumSize: const Size.fromHeight(52),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(4)),
|
||||
),
|
||||
),
|
||||
child: isLoading
|
||||
? SizedBox(
|
||||
width: 22,
|
||||
height: 22,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.5,
|
||||
color: colors.onPrimary,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'CREATE ACCOUNT',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 2.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'ALREADY HAVE AN ACCOUNT? ',
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
letterSpacing: 1.5,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: isLoading
|
||||
? null
|
||||
: () => context.go('/login'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: _purpleLight,
|
||||
textStyle: const TextStyle(
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 1.5,
|
||||
),
|
||||
),
|
||||
child: const Text('SIGN IN'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Brand header for the auth screens. Renders the Shadow Oak Pick Up
|
||||
/// circular badge logo, followed by the league wordmark in heavy
|
||||
/// uppercase type with wide letter spacing.
|
||||
class WindedBrandHeader extends StatelessWidget {
|
||||
const WindedBrandHeader({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/images/shadow_oak_logo.jpg',
|
||||
width: 140,
|
||||
height: 140,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'SHADOW OAK',
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 4.0,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'PICK UP',
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
color: const Color(0xFFBF77F6),
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 6.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user