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,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