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,192 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../auth/application/auth_notifier.dart';
|
||||
import '../application/suggestions_notifier.dart';
|
||||
import 'widgets/suggestion_form.dart';
|
||||
import 'widgets/suggestion_list_tile.dart';
|
||||
|
||||
/// Top-level Suggestions screen.
|
||||
///
|
||||
/// Top half is the always-visible [SuggestionForm]. Bottom half lists the
|
||||
/// signed-in user's past suggestions via [userSuggestionsProvider], or a
|
||||
/// gentle sign-in prompt when there's no current user.
|
||||
class SuggestionsScreen extends ConsumerWidget {
|
||||
const SuggestionsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final authUser = ref.watch(authNotifierProvider).valueOrNull;
|
||||
final suggestionsAsync = ref.watch(userSuggestionsProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Suggestions')),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 32),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
const SuggestionForm(),
|
||||
const SizedBox(height: 24),
|
||||
const Divider(),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Your Suggestions',
|
||||
style: theme.textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
if (authUser == null)
|
||||
_SignInPrompt(colors: colors, textTheme: theme.textTheme)
|
||||
else
|
||||
suggestionsAsync.when(
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
error: (err, _) => _ErrorState(
|
||||
message: 'Could not load your suggestions.',
|
||||
detail: '$err',
|
||||
colors: colors,
|
||||
textTheme: theme.textTheme,
|
||||
),
|
||||
data: (suggestions) {
|
||||
if (suggestions.isEmpty) {
|
||||
return _EmptyState(
|
||||
colors: colors,
|
||||
textTheme: theme.textTheme,
|
||||
);
|
||||
}
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
for (final s in suggestions)
|
||||
SuggestionListTile(suggestion: s),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SignInPrompt extends StatelessWidget {
|
||||
const _SignInPrompt({required this.colors, required this.textTheme});
|
||||
|
||||
final ColorScheme colors;
|
||||
final TextTheme textTheme;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.lock_outline, color: colors.onSurfaceVariant),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Sign in to view your past suggestions.',
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _EmptyState extends StatelessWidget {
|
||||
const _EmptyState({required this.colors, required this.textTheme});
|
||||
|
||||
final ColorScheme colors;
|
||||
final TextTheme textTheme;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Icons.lightbulb_outline,
|
||||
size: 36,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'No suggestions yet — share your first idea above.',
|
||||
textAlign: TextAlign.center,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ErrorState extends StatelessWidget {
|
||||
const _ErrorState({
|
||||
required this.message,
|
||||
required this.detail,
|
||||
required this.colors,
|
||||
required this.textTheme,
|
||||
});
|
||||
|
||||
final String message;
|
||||
final String detail;
|
||||
final ColorScheme colors;
|
||||
final TextTheme textTheme;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: colors.errorContainer,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.error_outline, color: colors.onErrorContainer),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
message,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: colors.onErrorContainer,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
detail,
|
||||
style: textTheme.bodySmall?.copyWith(
|
||||
color: colors.onErrorContainer,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../auth/application/auth_notifier.dart';
|
||||
import '../../application/suggestions_notifier.dart';
|
||||
|
||||
/// Form for submitting a new community suggestion.
|
||||
///
|
||||
/// Owns its own [TextEditingController] and the "anonymous" toggle. Wires
|
||||
/// into [suggestionsNotifierProvider] for submission state — the FilledButton
|
||||
/// switches to a spinner while loading, and shows snackbars on success/error.
|
||||
class SuggestionForm extends ConsumerStatefulWidget {
|
||||
const SuggestionForm({super.key});
|
||||
|
||||
static const int _maxChars = 500;
|
||||
static const int _minChars = 10;
|
||||
|
||||
@override
|
||||
ConsumerState<SuggestionForm> createState() => _SuggestionFormState();
|
||||
}
|
||||
|
||||
class _SuggestionFormState extends ConsumerState<SuggestionForm> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _controller = TextEditingController();
|
||||
bool _isAnonymous = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String? _validate(String? value) {
|
||||
final text = value?.trim() ?? '';
|
||||
if (text.length < SuggestionForm._minChars) {
|
||||
return 'Please write at least ${SuggestionForm._minChars} characters.';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _onSubmit() async {
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
FocusScope.of(context).unfocus();
|
||||
|
||||
final user = ref.read(authNotifierProvider).valueOrNull;
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
|
||||
await ref.read(suggestionsNotifierProvider.notifier).submit(
|
||||
text: _controller.text,
|
||||
isAnonymous: _isAnonymous,
|
||||
userId: user?.uid,
|
||||
displayName: user?.displayName,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
final state = ref.read(suggestionsNotifierProvider);
|
||||
state.when(
|
||||
data: (_) {
|
||||
_controller.clear();
|
||||
_formKey.currentState?.reset();
|
||||
setState(() {});
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(content: Text('Thanks for your suggestion!')),
|
||||
);
|
||||
},
|
||||
loading: () {},
|
||||
error: (err, _) {
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Could not submit suggestion: $err'),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final submissionState = ref.watch(suggestionsNotifierProvider);
|
||||
final isSubmitting = submissionState.isLoading;
|
||||
final authUser = ref.watch(authNotifierProvider).valueOrNull;
|
||||
|
||||
final submittingAs = (!_isAnonymous && authUser != null)
|
||||
? (authUser.displayName?.trim().isNotEmpty ?? false
|
||||
? authUser.displayName!.trim()
|
||||
: authUser.email)
|
||||
: null;
|
||||
|
||||
return Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'Share an idea',
|
||||
style: theme.textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Tell us what would make Winded better — new features, '
|
||||
'tournament formats, anything.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _controller,
|
||||
enabled: !isSubmitting,
|
||||
minLines: 3,
|
||||
maxLines: 8,
|
||||
maxLength: SuggestionForm._maxChars,
|
||||
textInputAction: TextInputAction.newline,
|
||||
keyboardType: TextInputType.multiline,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
LengthLimitingTextInputFormatter(SuggestionForm._maxChars),
|
||||
],
|
||||
validator: _validate,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
onChanged: (_) => setState(() {}),
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Type your suggestion here…',
|
||||
border: OutlineInputBorder(),
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile.adaptive(
|
||||
value: _isAnonymous,
|
||||
onChanged: isSubmitting
|
||||
? null
|
||||
: (value) => setState(() => _isAnonymous = value),
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text('Submit anonymously'),
|
||||
subtitle: Text(
|
||||
_isAnonymous
|
||||
? 'Your name will not be attached to this suggestion.'
|
||||
: 'Admins will see who submitted this.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (submittingAs != null) ...<Widget>[
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Icons.person_outline,
|
||||
size: 16,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Submitting as: $submittingAs',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
FilledButton.icon(
|
||||
onPressed: isSubmitting ? null : _onSubmit,
|
||||
icon: isSubmitting
|
||||
? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: colors.onPrimary,
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.send_outlined),
|
||||
label: Text(isSubmitting ? 'Submitting…' : 'Submit Suggestion'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../domain/suggestion.dart';
|
||||
|
||||
/// Card-style row showing one of the current user's past suggestions.
|
||||
///
|
||||
/// Truncates the body to three lines, prints a friendly relative-ish date,
|
||||
/// and renders a status chip whose color matches the suggestion lifecycle.
|
||||
class SuggestionListTile extends StatelessWidget {
|
||||
const SuggestionListTile({super.key, required this.suggestion});
|
||||
|
||||
final Suggestion suggestion;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final dateLabel =
|
||||
DateFormat.yMMMd().add_jm().format(suggestion.submittedAt);
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
suggestion.text,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodyLarge,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_StatusChip(status: suggestion.status),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Icons.schedule,
|
||||
size: 14,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
dateLabel,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
if (suggestion.isAnonymous) ...<Widget>[
|
||||
const SizedBox(width: 12),
|
||||
Icon(
|
||||
Icons.visibility_off_outlined,
|
||||
size: 14,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Anonymous',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatusChip extends StatelessWidget {
|
||||
const _StatusChip({required this.status});
|
||||
|
||||
final SuggestionStatus status;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
|
||||
final (Color background, Color foreground, String label) = switch (status) {
|
||||
SuggestionStatus.pending => (
|
||||
colors.surfaceContainerHighest,
|
||||
colors.onSurfaceVariant,
|
||||
'Pending',
|
||||
),
|
||||
SuggestionStatus.reviewed => (
|
||||
Colors.amber.withValues(alpha: 0.18),
|
||||
Colors.amber.shade300,
|
||||
'Reviewed',
|
||||
),
|
||||
SuggestionStatus.implemented => (
|
||||
Colors.green.withValues(alpha: 0.18),
|
||||
Colors.green.shade300,
|
||||
'Implemented',
|
||||
),
|
||||
};
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: background,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: foreground,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user