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,28 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../domain/event.dart';
|
||||
import '../infrastructure/events_repository.dart';
|
||||
|
||||
part 'events_notifier.g.dart';
|
||||
|
||||
/// Holds the currently-selected event id used when navigating to the detail
|
||||
/// screen. Null when no event is selected.
|
||||
@riverpod
|
||||
class SelectedEventId extends _$SelectedEventId {
|
||||
@override
|
||||
String? build() => null;
|
||||
|
||||
void select(String? id) => state = id;
|
||||
}
|
||||
|
||||
/// Resolves a single [Event] by id out of the events stream. Returns null
|
||||
/// while loading or if no event matches.
|
||||
@riverpod
|
||||
Event? eventById(EventByIdRef ref, String id) {
|
||||
final events = ref.watch(eventsStreamProvider).valueOrNull;
|
||||
if (events == null) return null;
|
||||
for (final event in events) {
|
||||
if (event.id == id) return event;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'events_notifier.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$eventByIdHash() => r'8717d386b9cf44631b1bc606aedab99c63636b33';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves a single [Event] by id out of the events stream. Returns null
|
||||
/// while loading or if no event matches.
|
||||
///
|
||||
/// Copied from [eventById].
|
||||
@ProviderFor(eventById)
|
||||
const eventByIdProvider = EventByIdFamily();
|
||||
|
||||
/// Resolves a single [Event] by id out of the events stream. Returns null
|
||||
/// while loading or if no event matches.
|
||||
///
|
||||
/// Copied from [eventById].
|
||||
class EventByIdFamily extends Family<Event?> {
|
||||
/// Resolves a single [Event] by id out of the events stream. Returns null
|
||||
/// while loading or if no event matches.
|
||||
///
|
||||
/// Copied from [eventById].
|
||||
const EventByIdFamily();
|
||||
|
||||
/// Resolves a single [Event] by id out of the events stream. Returns null
|
||||
/// while loading or if no event matches.
|
||||
///
|
||||
/// Copied from [eventById].
|
||||
EventByIdProvider call(String id) {
|
||||
return EventByIdProvider(id);
|
||||
}
|
||||
|
||||
@override
|
||||
EventByIdProvider getProviderOverride(covariant EventByIdProvider provider) {
|
||||
return call(provider.id);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'eventByIdProvider';
|
||||
}
|
||||
|
||||
/// Resolves a single [Event] by id out of the events stream. Returns null
|
||||
/// while loading or if no event matches.
|
||||
///
|
||||
/// Copied from [eventById].
|
||||
class EventByIdProvider extends AutoDisposeProvider<Event?> {
|
||||
/// Resolves a single [Event] by id out of the events stream. Returns null
|
||||
/// while loading or if no event matches.
|
||||
///
|
||||
/// Copied from [eventById].
|
||||
EventByIdProvider(String id)
|
||||
: this._internal(
|
||||
(ref) => eventById(ref as EventByIdRef, id),
|
||||
from: eventByIdProvider,
|
||||
name: r'eventByIdProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$eventByIdHash,
|
||||
dependencies: EventByIdFamily._dependencies,
|
||||
allTransitiveDependencies: EventByIdFamily._allTransitiveDependencies,
|
||||
id: id,
|
||||
);
|
||||
|
||||
EventByIdProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.id,
|
||||
}) : super.internal();
|
||||
|
||||
final String id;
|
||||
|
||||
@override
|
||||
Override overrideWith(Event? Function(EventByIdRef provider) create) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: EventByIdProvider._internal(
|
||||
(ref) => create(ref as EventByIdRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
id: id,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeProviderElement<Event?> createElement() {
|
||||
return _EventByIdProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is EventByIdProvider && other.id == id;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, id.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
mixin EventByIdRef on AutoDisposeProviderRef<Event?> {
|
||||
/// The parameter `id` of this provider.
|
||||
String get id;
|
||||
}
|
||||
|
||||
class _EventByIdProviderElement extends AutoDisposeProviderElement<Event?>
|
||||
with EventByIdRef {
|
||||
_EventByIdProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get id => (origin as EventByIdProvider).id;
|
||||
}
|
||||
|
||||
String _$selectedEventIdHash() => r'6d48c24938e4ca7c60317e72cfee3bd87823b2cb';
|
||||
|
||||
/// Holds the currently-selected event id used when navigating to the detail
|
||||
/// screen. Null when no event is selected.
|
||||
///
|
||||
/// Copied from [SelectedEventId].
|
||||
@ProviderFor(SelectedEventId)
|
||||
final selectedEventIdProvider =
|
||||
AutoDisposeNotifierProvider<SelectedEventId, String?>.internal(
|
||||
SelectedEventId.new,
|
||||
name: r'selectedEventIdProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$selectedEventIdHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$SelectedEventId = AutoDisposeNotifier<String?>;
|
||||
// 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
|
||||
@@ -0,0 +1,129 @@
|
||||
enum EventCategory { tournament, pickup }
|
||||
|
||||
class Event {
|
||||
const Event({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.date,
|
||||
required this.location,
|
||||
required this.registrationDeadline,
|
||||
required this.teamsRegistered,
|
||||
required this.maxTeams,
|
||||
this.category = EventCategory.pickup,
|
||||
this.imageUrl,
|
||||
this.isCancelled = false,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
final DateTime date;
|
||||
final String location;
|
||||
final DateTime registrationDeadline;
|
||||
final int teamsRegistered;
|
||||
final int maxTeams;
|
||||
final EventCategory category;
|
||||
final String? imageUrl;
|
||||
final bool isCancelled;
|
||||
|
||||
Event copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? description,
|
||||
DateTime? date,
|
||||
String? location,
|
||||
DateTime? registrationDeadline,
|
||||
int? teamsRegistered,
|
||||
int? maxTeams,
|
||||
EventCategory? category,
|
||||
String? imageUrl,
|
||||
bool? isCancelled,
|
||||
}) {
|
||||
return Event(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
date: date ?? this.date,
|
||||
location: location ?? this.location,
|
||||
registrationDeadline: registrationDeadline ?? this.registrationDeadline,
|
||||
teamsRegistered: teamsRegistered ?? this.teamsRegistered,
|
||||
maxTeams: maxTeams ?? this.maxTeams,
|
||||
category: category ?? this.category,
|
||||
imageUrl: imageUrl ?? this.imageUrl,
|
||||
isCancelled: isCancelled ?? this.isCancelled,
|
||||
);
|
||||
}
|
||||
|
||||
factory Event.fromJson(Map<String, dynamic> data) {
|
||||
return Event(
|
||||
id: (data['id'] as String?) ?? '',
|
||||
title: (data['title'] as String?) ?? '',
|
||||
description: (data['description'] as String?) ?? '',
|
||||
date: _parseDate(data['event_date']) ?? DateTime.now(),
|
||||
location: (data['location'] as String?) ?? '',
|
||||
registrationDeadline:
|
||||
_parseDate(data['registration_deadline']) ?? DateTime.now(),
|
||||
teamsRegistered: (data['teams_registered'] as num?)?.toInt() ?? 0,
|
||||
maxTeams: (data['max_teams'] as num?)?.toInt() ?? 0,
|
||||
category: (data['category'] as String?) == 'tournament'
|
||||
? EventCategory.tournament
|
||||
: EventCategory.pickup,
|
||||
imageUrl: data['image_url'] as String?,
|
||||
isCancelled: _parseBool(data['is_cancelled']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, Object?> toJson() {
|
||||
return <String, Object?>{
|
||||
'title': title,
|
||||
'description': description,
|
||||
'event_date': date.toIso8601String(),
|
||||
'location': location,
|
||||
'registration_deadline': registrationDeadline.toIso8601String(),
|
||||
'max_teams': maxTeams,
|
||||
'category': category.name,
|
||||
'image_url': imageUrl,
|
||||
'is_cancelled': isCancelled ? 1 : 0,
|
||||
};
|
||||
}
|
||||
|
||||
static DateTime? _parseDate(Object? v) {
|
||||
if (v is String && v.isNotEmpty) return DateTime.tryParse(v);
|
||||
return null;
|
||||
}
|
||||
|
||||
static bool _parseBool(Object? v) {
|
||||
if (v is bool) return v;
|
||||
if (v is int) return v != 0;
|
||||
if (v is String) return v == '1' || v.toLowerCase() == 'true';
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other is Event &&
|
||||
other.id == id &&
|
||||
other.title == title &&
|
||||
other.description == description &&
|
||||
other.date == date &&
|
||||
other.location == location &&
|
||||
other.registrationDeadline == registrationDeadline &&
|
||||
other.teamsRegistered == teamsRegistered &&
|
||||
other.maxTeams == maxTeams &&
|
||||
other.category == category &&
|
||||
other.imageUrl == imageUrl &&
|
||||
other.isCancelled == isCancelled;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
id, title, description, date, location,
|
||||
registrationDeadline, teamsRegistered, maxTeams,
|
||||
category, imageUrl, isCancelled,
|
||||
);
|
||||
|
||||
@override
|
||||
String toString() => 'Event(id: $id, title: $title, date: $date)';
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../../core/api/api_client.dart';
|
||||
import '../domain/event.dart';
|
||||
|
||||
part 'events_repository.g.dart';
|
||||
|
||||
class EventsRepository {
|
||||
EventsRepository(this._api);
|
||||
|
||||
final ApiClient _api;
|
||||
|
||||
Future<List<Event>> fetchEvents() async {
|
||||
final data = await _api.get('/events/index.php');
|
||||
final list = (data['events'] as List?) ?? [];
|
||||
return list.whereType<Map<String, dynamic>>().map(Event.fromJson).toList();
|
||||
}
|
||||
|
||||
Future<Event?> getEvent(String id) async {
|
||||
try {
|
||||
final data = await _api.get('/events/detail.php', params: {'id': id});
|
||||
return Event.fromJson(data);
|
||||
} on ApiException catch (e) {
|
||||
if (e.statusCode == 404) return null;
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> createEvent(Event event) async {
|
||||
final data = await _api.post('/events/index.php', event.toJson());
|
||||
return data['id'] as String;
|
||||
}
|
||||
|
||||
Future<void> updateEvent(Event event) async {
|
||||
await _api.put('/events/detail.php', event.toJson(), params: {'id': event.id});
|
||||
}
|
||||
|
||||
Future<void> deleteEvent(String id) async {
|
||||
await _api.delete('/events/detail.php', params: {'id': id});
|
||||
}
|
||||
|
||||
Future<bool> isRegistered(String eventId) async {
|
||||
final data = await _api.get(
|
||||
'/events/register.php',
|
||||
params: {'event_id': eventId},
|
||||
);
|
||||
return (data['registered'] as bool?) ?? false;
|
||||
}
|
||||
|
||||
Future<void> register(String eventId) async {
|
||||
await _api.post('/events/register.php', {'event_id': eventId});
|
||||
}
|
||||
|
||||
Future<void> unregister(String eventId) async {
|
||||
await _api.delete('/events/register.php', params: {'event_id': eventId});
|
||||
}
|
||||
|
||||
Stream<List<Event>> watchEvents() async* {
|
||||
yield await fetchEvents();
|
||||
await for (final _ in Stream<void>.periodic(const Duration(seconds: 30))) {
|
||||
yield await fetchEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
EventsRepository eventsRepository(EventsRepositoryRef ref) {
|
||||
return EventsRepository(ref.watch(apiClientProvider));
|
||||
}
|
||||
|
||||
@riverpod
|
||||
Stream<List<Event>> eventsStream(EventsStreamRef ref) {
|
||||
return ref.watch(eventsRepositoryProvider).watchEvents();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'events_repository.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$eventsRepositoryHash() => r'753d76dd8556bce50755088a8ea0a611bab61d34';
|
||||
|
||||
/// See also [eventsRepository].
|
||||
@ProviderFor(eventsRepository)
|
||||
final eventsRepositoryProvider = Provider<EventsRepository>.internal(
|
||||
eventsRepository,
|
||||
name: r'eventsRepositoryProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$eventsRepositoryHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef EventsRepositoryRef = ProviderRef<EventsRepository>;
|
||||
String _$eventsStreamHash() => r'50b8c367793996c2c0fa894fd2694eefbdf4135b';
|
||||
|
||||
/// Stream of events surfaced to the UI.
|
||||
///
|
||||
/// Currently emits [EventsRepository.mockEvents] as a single tick so the
|
||||
/// screens render real-looking content without needing Firestore to be
|
||||
/// seeded. Swap this to `ref.watch(eventsRepositoryProvider).watchEvents()`
|
||||
/// once the collection has data.
|
||||
///
|
||||
/// Copied from [eventsStream].
|
||||
@ProviderFor(eventsStream)
|
||||
final eventsStreamProvider = AutoDisposeStreamProvider<List<Event>>.internal(
|
||||
eventsStream,
|
||||
name: r'eventsStreamProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$eventsStreamHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
typedef EventsStreamRef = AutoDisposeStreamProviderRef<List<Event>>;
|
||||
// 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
|
||||
@@ -0,0 +1,351 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../application/events_notifier.dart';
|
||||
import '../domain/event.dart';
|
||||
import '../infrastructure/events_repository.dart';
|
||||
import 'widgets/countdown_timer.dart';
|
||||
import 'widgets/registration_button.dart';
|
||||
|
||||
class EventDetailScreen extends ConsumerWidget {
|
||||
const EventDetailScreen({super.key, required this.eventId});
|
||||
|
||||
final String eventId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final eventsAsync = ref.watch(eventsStreamProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go('/events');
|
||||
}
|
||||
},
|
||||
),
|
||||
title: const Text('Event details'),
|
||||
),
|
||||
body: eventsAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, _) => _NotFound(
|
||||
message: 'Could not load event: $error',
|
||||
),
|
||||
data: (_) {
|
||||
final event = ref.watch(eventByIdProvider(eventId));
|
||||
if (event == null) {
|
||||
return const _NotFound(message: 'Event not found.');
|
||||
}
|
||||
return _EventDetailBody(event: event);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EventDetailBody extends StatelessWidget {
|
||||
const _EventDetailBody({required this.event});
|
||||
|
||||
final Event event;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
|
||||
final dateLabel =
|
||||
DateFormat('EEEE, MMMM d, y · h:mm a').format(event.date);
|
||||
final deadlineLabel =
|
||||
DateFormat('EEE, MMM d · h:mm a').format(event.registrationDeadline);
|
||||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final isWide = constraints.maxWidth > 720;
|
||||
final horizontalPadding = isWide ? 32.0 : 16.0;
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: horizontalPadding,
|
||||
vertical: 16,
|
||||
),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 760),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_Header(
|
||||
event: event,
|
||||
dateLabel: dateLabel,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: CountdownTimer(
|
||||
target: event.date,
|
||||
compact: false,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'About this event',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
event.description,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
height: 1.45,
|
||||
color: scheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_RegistrationSection(
|
||||
event: event,
|
||||
deadlineLabel: deadlineLabel,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Header extends StatelessWidget {
|
||||
const _Header({required this.event, required this.dateLabel});
|
||||
|
||||
final Event event;
|
||||
final String dateLabel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (event.isCancelled)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.error,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
'Cancelled',
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: scheme.onError,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
event.title,
|
||||
style: theme.textTheme.headlineSmall?.copyWith(
|
||||
color: scheme.onPrimaryContainer,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.calendar_today_outlined,
|
||||
size: 18,
|
||||
color: scheme.onPrimaryContainer,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
dateLabel,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: scheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.place_outlined,
|
||||
size: 18,
|
||||
color: scheme.onPrimaryContainer,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
event.location,
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
color: scheme.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RegistrationSection extends StatelessWidget {
|
||||
const _RegistrationSection({
|
||||
required this.event,
|
||||
required this.deadlineLabel,
|
||||
});
|
||||
|
||||
final Event event;
|
||||
final String deadlineLabel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final ratio = event.maxTeams == 0
|
||||
? 0.0
|
||||
: (event.teamsRegistered / event.maxTeams).clamp(0.0, 1.0).toDouble();
|
||||
final deadlinePassed =
|
||||
DateTime.now().isAfter(event.registrationDeadline);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Registration',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.groups_outlined, color: scheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${event.teamsRegistered} / ${event.maxTeams} teams',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
color: scheme.primary,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
child: LinearProgressIndicator(
|
||||
value: ratio,
|
||||
minHeight: 8,
|
||||
backgroundColor: scheme.surfaceContainer,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(scheme.primary),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.timer_off_outlined,
|
||||
size: 16,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
deadlinePassed
|
||||
? 'Registration closed $deadlineLabel'
|
||||
: 'Registration closes $deadlineLabel',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
RegistrationButton(
|
||||
fullWidth: true,
|
||||
enabled: !deadlinePassed && !event.isCancelled,
|
||||
),
|
||||
if (event.maxTeams > 0 &&
|
||||
event.teamsRegistered >= event.maxTeams) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Preferred headcount reached — extras are still welcome to drop in.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NotFound extends StatelessWidget {
|
||||
const _NotFound({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.search_off,
|
||||
size: 64,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(message, style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: () => context.go('/events'),
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const Text('Back to events'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../domain/event.dart';
|
||||
import '../infrastructure/events_repository.dart';
|
||||
import 'widgets/event_card.dart';
|
||||
|
||||
class EventsScreen extends ConsumerWidget {
|
||||
const EventsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final eventsAsync = ref.watch(eventsStreamProvider);
|
||||
|
||||
return DefaultTabController(
|
||||
length: 3,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Events'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
tooltip: 'Search & filter',
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
bottom: const TabBar(
|
||||
tabs: <Tab>[
|
||||
Tab(text: 'ALL'),
|
||||
Tab(text: 'TOURNAMENTS'),
|
||||
Tab(text: 'PICK-UP'),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: eventsAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, _) => _ErrorState(
|
||||
message: error.toString(),
|
||||
onRetry: () => ref.invalidate(eventsStreamProvider),
|
||||
),
|
||||
data: (events) {
|
||||
return TabBarView(
|
||||
children: <Widget>[
|
||||
_EventsList(
|
||||
events: events,
|
||||
onRefresh: () => ref.invalidate(eventsStreamProvider),
|
||||
),
|
||||
_EventsList(
|
||||
events: events
|
||||
.where((e) => e.category == EventCategory.tournament)
|
||||
.toList(growable: false),
|
||||
onRefresh: () => ref.invalidate(eventsStreamProvider),
|
||||
),
|
||||
_EventsList(
|
||||
events: events
|
||||
.where((e) => e.category == EventCategory.pickup)
|
||||
.toList(growable: false),
|
||||
onRefresh: () => ref.invalidate(eventsStreamProvider),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EventsList extends StatelessWidget {
|
||||
const _EventsList({required this.events, required this.onRefresh});
|
||||
|
||||
final List<Event> events;
|
||||
final VoidCallback onRefresh;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (events.isEmpty) return const _EmptyState();
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => onRefresh(),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: events.length,
|
||||
itemBuilder: (context, index) => EventCard(event: events[index]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EmptyState extends StatelessWidget {
|
||||
const _EmptyState();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.sports_soccer,
|
||||
size: 64,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No events scheduled', style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Check back soon — new pick-up games and tournaments are posted regularly.',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ErrorState extends StatelessWidget {
|
||||
const _ErrorState({required this.message, required this.onRetry});
|
||||
|
||||
final String message;
|
||||
final VoidCallback onRetry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 64, color: theme.colorScheme.error),
|
||||
const SizedBox(height: 16),
|
||||
Text('Could not load events', style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
message,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.tonalIcon(
|
||||
onPressed: onRetry,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('Try again'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Live-updating countdown to a target [DateTime].
|
||||
///
|
||||
/// Rebuilds once per second and renders one of:
|
||||
/// * "in 3d 4h" — when more than a day out
|
||||
/// * "in 4h 12m" — when same-day
|
||||
/// * "in 12m 30s" — within the hour
|
||||
/// * "Starting now!" — within the final minute window
|
||||
/// * "Ended" — once the target has passed by more than the [grace] window
|
||||
///
|
||||
/// Pass [compact] true to render only the duration text (used in cards);
|
||||
/// false renders a labelled card-friendly block (used on the detail screen).
|
||||
class CountdownTimer extends StatefulWidget {
|
||||
const CountdownTimer({
|
||||
super.key,
|
||||
required this.target,
|
||||
this.compact = true,
|
||||
this.grace = const Duration(minutes: 60),
|
||||
});
|
||||
|
||||
final DateTime target;
|
||||
final bool compact;
|
||||
|
||||
/// How long after [target] we still show "Starting now!" before flipping
|
||||
/// to "Ended". Defaults to an hour so an in-progress match stays visible.
|
||||
final Duration grace;
|
||||
|
||||
@override
|
||||
State<CountdownTimer> createState() => _CountdownTimerState();
|
||||
}
|
||||
|
||||
class _CountdownTimerState extends State<CountdownTimer> {
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final now = DateTime.now();
|
||||
final diff = widget.target.difference(now);
|
||||
|
||||
final label = _formatLabel(diff);
|
||||
final isLive = diff.isNegative && diff.abs() < widget.grace;
|
||||
final isEnded = diff.isNegative && diff.abs() >= widget.grace;
|
||||
|
||||
final Color bg;
|
||||
final Color fg;
|
||||
if (isEnded) {
|
||||
bg = scheme.surfaceContainerHighest;
|
||||
fg = scheme.onSurfaceVariant;
|
||||
} else if (isLive) {
|
||||
bg = scheme.tertiaryContainer;
|
||||
fg = scheme.onTertiaryContainer;
|
||||
} else {
|
||||
bg = scheme.primaryContainer;
|
||||
fg = scheme.onPrimaryContainer;
|
||||
}
|
||||
|
||||
if (widget.compact) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: fg,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
isEnded
|
||||
? Icons.event_busy
|
||||
: isLive
|
||||
? Icons.sports_soccer
|
||||
: Icons.timer_outlined,
|
||||
color: fg,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
label,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
color: fg,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatLabel(Duration diff) {
|
||||
if (diff.isNegative) {
|
||||
if (diff.abs() < widget.grace) return 'Starting now!';
|
||||
return 'Ended';
|
||||
}
|
||||
if (diff.inSeconds <= 60) return 'Starting now!';
|
||||
|
||||
if (diff.inDays >= 1) {
|
||||
final days = diff.inDays;
|
||||
final hours = diff.inHours - days * 24;
|
||||
if (hours == 0) {
|
||||
return 'in ${days}d';
|
||||
}
|
||||
return 'in ${days}d ${hours}h';
|
||||
}
|
||||
if (diff.inHours >= 1) {
|
||||
final hours = diff.inHours;
|
||||
final minutes = diff.inMinutes - hours * 60;
|
||||
return 'in ${hours}h ${minutes}m';
|
||||
}
|
||||
final minutes = diff.inMinutes;
|
||||
final seconds = diff.inSeconds - minutes * 60;
|
||||
return 'in ${minutes}m ${seconds}s';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../domain/event.dart';
|
||||
import 'countdown_timer.dart';
|
||||
|
||||
/// Material 3 card representing a single [Event] in the events list.
|
||||
///
|
||||
/// Tap navigates to `/events/:id`. Visual emphasis is given to the title,
|
||||
/// the countdown chip, and the registration headcount.
|
||||
class EventCard extends StatelessWidget {
|
||||
const EventCard({super.key, required this.event});
|
||||
|
||||
final Event event;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
|
||||
final dateLabel = DateFormat('EEE, MMM d · h:mm a').format(event.date);
|
||||
final isFull =
|
||||
event.teamsRegistered >= event.maxTeams && event.maxTeams > 0;
|
||||
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: InkWell(
|
||||
onTap: () => context.go('/events/${event.id}'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
event.title,
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
CountdownTimer(target: event.date),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
_CategoryChip(category: event.category),
|
||||
if (event.isCancelled) ...<Widget>[
|
||||
const SizedBox(width: 8),
|
||||
_CancelledChip(scheme: scheme),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_IconRow(
|
||||
icon: Icons.calendar_today_outlined,
|
||||
color: scheme.onSurfaceVariant,
|
||||
child: Text(
|
||||
dateLabel,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
_IconRow(
|
||||
icon: Icons.place_outlined,
|
||||
color: scheme.onSurfaceVariant,
|
||||
child: Text(
|
||||
event.location,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.groups_outlined, size: 18, color: scheme.primary),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${event.teamsRegistered} / ${event.maxTeams} teams',
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: scheme.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (isFull)
|
||||
Text(
|
||||
'Preferred count reached',
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: scheme.tertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _IconRow extends StatelessWidget {
|
||||
const _IconRow({
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 16, color: color),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CancelledChip extends StatelessWidget {
|
||||
const _CancelledChip({required this.scheme});
|
||||
|
||||
final ColorScheme scheme;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.errorContainer,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
),
|
||||
child: Text(
|
||||
'Cancelled',
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: scheme.onErrorContainer,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategoryChip extends StatelessWidget {
|
||||
const _CategoryChip({required this.category});
|
||||
|
||||
final EventCategory category;
|
||||
|
||||
static const Color _tournamentColor = Color(0xFF8B30C8);
|
||||
static const Color _pickupColor = Color(0xFF26A69A);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isTournament = category == EventCategory.tournament;
|
||||
final color = isTournament ? _tournamentColor : _pickupColor;
|
||||
final label = isTournament ? 'TOURNAMENT' : 'PICK-UP';
|
||||
final icon = isTournament
|
||||
? Icons.emoji_events_outlined
|
||||
: Icons.sports_soccer;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.18),
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
border: Border.all(color: color.withValues(alpha: 0.55)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Icon(icon, size: 13, color: color),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: color,
|
||||
fontWeight: FontWeight.w800,
|
||||
letterSpacing: 0.8,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Toggle button representing the current user's registration state for an
|
||||
/// event. Local-state only for now — a future revision will wire this to
|
||||
/// Firestore via the events repository.
|
||||
class RegistrationButton extends StatefulWidget {
|
||||
const RegistrationButton({
|
||||
super.key,
|
||||
this.initiallyRegistered = false,
|
||||
this.enabled = true,
|
||||
this.fullWidth = false,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
final bool initiallyRegistered;
|
||||
final bool enabled;
|
||||
final bool fullWidth;
|
||||
final ValueChanged<bool>? onChanged;
|
||||
|
||||
@override
|
||||
State<RegistrationButton> createState() => _RegistrationButtonState();
|
||||
}
|
||||
|
||||
class _RegistrationButtonState extends State<RegistrationButton> {
|
||||
late bool _registered;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_registered = widget.initiallyRegistered;
|
||||
}
|
||||
|
||||
void _toggle() {
|
||||
setState(() => _registered = !_registered);
|
||||
widget.onChanged?.call(_registered);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
|
||||
final child = _registered
|
||||
? OutlinedButton.icon(
|
||||
onPressed: widget.enabled ? _toggle : null,
|
||||
icon: Icon(Icons.check_circle, color: scheme.primary),
|
||||
label: const Text('Registered'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: scheme.primary,
|
||||
side: BorderSide(color: scheme.primary),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
)
|
||||
: FilledButton.icon(
|
||||
onPressed: widget.enabled ? _toggle : null,
|
||||
icon: const Icon(Icons.how_to_reg),
|
||||
label: const Text('Register'),
|
||||
style: FilledButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 14,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (widget.fullWidth) {
|
||||
return SizedBox(width: double.infinity, child: child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user