Adds all fields to the edit profile bottom sheet: - First Name / Last Name (side by side), Email, Phone - Location section: Home District (locked with "Next change" date), Place, Pincode, State, Country - Saves all fields via update-profile API and persists to prefs - Loads existing values from prefs on open; refreshes from status API on every profile open so fields stay in sync with server Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2732 lines
101 KiB
Dart
2732 lines
101 KiB
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import '../core/utils/error_utils.dart';
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:share_plus/share_plus.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
import '../features/events/services/events_service.dart';
|
|
import '../features/events/models/event_models.dart';
|
|
import '../features/gamification/providers/gamification_provider.dart';
|
|
import '../features/gamification/models/gamification_models.dart';
|
|
import '../widgets/skeleton_loader.dart';
|
|
import '../widgets/tier_avatar_ring.dart';
|
|
import 'learn_more_screen.dart';
|
|
import 'settings_screen.dart';
|
|
import '../core/api/api_endpoints.dart';
|
|
import '../core/api/api_client.dart';
|
|
import '../core/app_decoration.dart';
|
|
import '../core/constants.dart';
|
|
import '../widgets/landscape_section_header.dart';
|
|
import '../features/share/share_card_generator.dart';
|
|
import '../core/analytics/posthog_service.dart';
|
|
|
|
class ProfileScreen extends StatefulWidget {
|
|
const ProfileScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<ProfileScreen> createState() => _ProfileScreenState();
|
|
}
|
|
|
|
class _ProfileScreenState extends State<ProfileScreen>
|
|
with SingleTickerProviderStateMixin {
|
|
final ApiClient _apiClient = ApiClient();
|
|
String _username = '';
|
|
String _email = 'not provided';
|
|
String _profileImage = '';
|
|
String? _eventifyId;
|
|
String? _userTier;
|
|
String? _district;
|
|
DateTime? _districtChangedAt;
|
|
String? _firstName;
|
|
String? _lastName;
|
|
String? _phone;
|
|
String? _place;
|
|
String? _pincode;
|
|
String? _state;
|
|
String? _country;
|
|
final ImagePicker _picker = ImagePicker();
|
|
|
|
// Share rank
|
|
bool _sharingRank = false;
|
|
|
|
// 14 Kerala districts
|
|
static const List<String> _districts = [
|
|
'Thiruvananthapuram', 'Kollam', 'Pathanamthitta', 'Alappuzha',
|
|
'Kottayam', 'Idukki', 'Ernakulam', 'Thrissur', 'Palakkad',
|
|
'Malappuram', 'Kozhikode', 'Wayanad', 'Kannur', 'Kasaragod',
|
|
];
|
|
|
|
final EventsService _eventsService = EventsService();
|
|
|
|
// AUTH-005: District change cooldown (183-day lock)
|
|
bool get _districtLocked {
|
|
if (_districtChangedAt == null) return false;
|
|
return DateTime.now().difference(_districtChangedAt!) < const Duration(days: 183);
|
|
}
|
|
|
|
String get _districtNextChange {
|
|
if (_districtChangedAt == null) return '';
|
|
final next = _districtChangedAt!.add(const Duration(days: 183));
|
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
return '${next.day} ${months[next.month - 1]} ${next.year}';
|
|
}
|
|
|
|
List<EventModel> _ongoingEvents = [];
|
|
|
|
bool _loadingEvents = true;
|
|
|
|
// Gradient used for EXP bar and rainbow bar (6-color rainbow)
|
|
static const LinearGradient _expGradient = LinearGradient(
|
|
colors: [
|
|
Color(0xFFA855F7), // purple-500
|
|
Color(0xFFEC4899), // pink-500
|
|
Color(0xFFF97316), // orange-500
|
|
Color(0xFFEAB308), // yellow-500
|
|
Color(0xFF22C55E), // green-500
|
|
Color(0xFF3B82F6), // blue-500
|
|
],
|
|
);
|
|
|
|
// Animation state
|
|
late AnimationController _animController;
|
|
double _expProgress = 0.0;
|
|
int _animatedLikes = 0;
|
|
int _animatedPosts = 0;
|
|
int _animatedViews = 0;
|
|
|
|
// Target stat values (matching web: 1.2K, 45, 3.4K)
|
|
static const int _targetLikes = 1200;
|
|
static const int _targetPosts = 45;
|
|
static const int _targetViews = 3400;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
PostHogService.instance.screen('Profile');
|
|
|
|
// Animation controller for EXP bar + stat counters
|
|
_animController = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 2000),
|
|
);
|
|
|
|
_loadProfile();
|
|
_startAnimations();
|
|
|
|
// Load gamification data for profile EP cards
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (mounted) context.read<GamificationProvider>().loadAll(force: true);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_animController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _startAnimations() {
|
|
// Delay to match React's setTimeout(500ms)
|
|
Future.delayed(const Duration(milliseconds: 500), () {
|
|
if (!mounted) return;
|
|
|
|
// Animate EXP bar: 0 → 0.65 with ease-out over 1.3s
|
|
final expTween = Tween<double>(begin: 0.0, end: 0.65);
|
|
final expAnim = CurvedAnimation(
|
|
parent: _animController,
|
|
curve: const Interval(0.0, 0.65, curve: Curves.easeOut),
|
|
);
|
|
// Update fields without setState — AnimatedBuilder handles the rebuilds
|
|
expAnim.addListener(() {
|
|
_expProgress = expTween.evaluate(expAnim);
|
|
});
|
|
|
|
_animController.addListener(() {
|
|
final t = _animController.value;
|
|
_animatedLikes = (t * _targetLikes).round();
|
|
_animatedPosts = (t * _targetPosts).round();
|
|
_animatedViews = (t * _targetViews).round();
|
|
});
|
|
|
|
_animController.forward();
|
|
});
|
|
}
|
|
|
|
/// Format large numbers: ≥1M → "X.XM", ≥1K → "X.XK", else raw
|
|
String _formatNumber(int n) {
|
|
if (n >= 1000000) {
|
|
final val = n / 1000000;
|
|
return '${val.toStringAsFixed(1)}M';
|
|
} else if (n >= 1000) {
|
|
final val = n / 1000;
|
|
return '${val.toStringAsFixed(1)}K';
|
|
}
|
|
return n.toString();
|
|
}
|
|
|
|
// ───────── Data Loading (unchanged) ─────────
|
|
|
|
Future<void> _loadProfile() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final currentEmail =
|
|
prefs.getString('current_email') ?? prefs.getString('email') ?? '';
|
|
|
|
_email = currentEmail.isNotEmpty ? currentEmail : 'not provided';
|
|
|
|
final displayKey =
|
|
currentEmail.isNotEmpty ? 'display_name_$currentEmail' : 'display_name';
|
|
final profileImageKey =
|
|
currentEmail.isNotEmpty ? 'profileImage_$currentEmail' : 'profileImage';
|
|
|
|
_username = prefs.getString(displayKey) ??
|
|
prefs.getString('display_name') ??
|
|
_email;
|
|
_profileImage =
|
|
prefs.getString(profileImageKey) ?? prefs.getString('profileImage') ?? '';
|
|
|
|
// Always fetch fresh data from server (fire-and-forget)
|
|
// Ensures profile photo, district, and cooldown are always up-to-date
|
|
_fetchAndCacheStatusData(prefs, profileImageKey);
|
|
|
|
// AUTH-003/PROF-001: Eventify ID
|
|
_eventifyId = prefs.getString('eventify_id');
|
|
|
|
// PROF-004 partial: tier for avatar ring
|
|
_userTier = prefs.getString('user_tier') ?? prefs.getString('level');
|
|
|
|
// PROF-002: District
|
|
_district = prefs.getString('district');
|
|
|
|
// AUTH-005: District change cooldown
|
|
final districtChangedStr = prefs.getString('district_changed_at');
|
|
if (districtChangedStr != null) {
|
|
_districtChangedAt = DateTime.tryParse(districtChangedStr);
|
|
}
|
|
|
|
// Personal info fields
|
|
_firstName = prefs.getString('first_name');
|
|
_lastName = prefs.getString('last_name');
|
|
_phone = prefs.getString('phone_number');
|
|
_place = prefs.getString('place');
|
|
_pincode = prefs.getString('pincode');
|
|
_state = prefs.getString('state');
|
|
_country = prefs.getString('country');
|
|
|
|
await _loadEventsForProfile(prefs);
|
|
if (mounted) setState(() {});
|
|
}
|
|
|
|
/// Fetches fresh data from /user/status/ on every profile open.
|
|
/// Updates profile photo, district, and district_changed_at.
|
|
Future<void> _fetchAndCacheStatusData(SharedPreferences prefs, String profileImageKey) async {
|
|
try {
|
|
final res = await _apiClient.post(ApiEndpoints.status);
|
|
|
|
// Profile photo
|
|
final raw = res['profile_photo']?.toString() ?? '';
|
|
if (raw.isNotEmpty && !raw.contains('default.png')) {
|
|
final url = raw.startsWith('http') ? raw : 'https://em.eventifyplus.com$raw';
|
|
await prefs.setString(profileImageKey, url);
|
|
await prefs.setString('profileImage', url);
|
|
if (mounted) setState(() => _profileImage = url);
|
|
}
|
|
|
|
// Eventify ID
|
|
final eventifyId = res['eventify_id']?.toString() ?? '';
|
|
if (eventifyId.isNotEmpty) {
|
|
await prefs.setString('eventify_id', eventifyId);
|
|
if (mounted) setState(() => _eventifyId = eventifyId);
|
|
}
|
|
|
|
// District + cooldown timestamp
|
|
final districtFromServer = res['district']?.toString() ?? '';
|
|
final changedAtStr = res['district_changed_at']?.toString() ?? '';
|
|
if (districtFromServer.isNotEmpty) {
|
|
await prefs.setString('district', districtFromServer);
|
|
}
|
|
if (changedAtStr.isNotEmpty) {
|
|
await prefs.setString('district_changed_at', changedAtStr);
|
|
}
|
|
// Personal info fields from status response
|
|
final fields = <String, String>{
|
|
'first_name': res['first_name']?.toString() ?? '',
|
|
'last_name': res['last_name']?.toString() ?? '',
|
|
'phone_number': res['phone_number']?.toString() ?? '',
|
|
'place': res['place']?.toString() ?? '',
|
|
'pincode': res['pincode']?.toString() ?? '',
|
|
'state': res['state']?.toString() ?? '',
|
|
'country': res['country']?.toString() ?? '',
|
|
};
|
|
for (final e in fields.entries) {
|
|
if (e.value.isNotEmpty) await prefs.setString(e.key, e.value);
|
|
}
|
|
|
|
if (mounted) {
|
|
setState(() {
|
|
if (districtFromServer.isNotEmpty) _district = districtFromServer;
|
|
if (changedAtStr.isNotEmpty) _districtChangedAt = DateTime.tryParse(changedAtStr);
|
|
if (fields['first_name']!.isNotEmpty) _firstName = fields['first_name'];
|
|
if (fields['last_name']!.isNotEmpty) _lastName = fields['last_name'];
|
|
if (fields['phone_number']!.isNotEmpty) _phone = fields['phone_number'];
|
|
if (fields['place']!.isNotEmpty) _place = fields['place'];
|
|
if (fields['pincode']!.isNotEmpty) _pincode = fields['pincode'];
|
|
if (fields['state']!.isNotEmpty) _state = fields['state'];
|
|
if (fields['country']!.isNotEmpty) _country = fields['country'];
|
|
});
|
|
}
|
|
} catch (_) {
|
|
// Non-critical — silently ignore if status call fails
|
|
}
|
|
}
|
|
|
|
Future<void> _loadEventsForProfile([SharedPreferences? prefs]) async {
|
|
_ongoingEvents = [];
|
|
|
|
prefs ??= await SharedPreferences.getInstance();
|
|
final pincode = prefs.getString('pincode') ?? 'all';
|
|
|
|
try {
|
|
final events = await _eventsService.getEventsByPincode(pincode);
|
|
|
|
final now = DateTime.now();
|
|
final today = DateTime(now.year, now.month, now.day);
|
|
final ongoing = <EventModel>[];
|
|
|
|
DateTime? tryParseDate(String? s) {
|
|
if (s == null) return null;
|
|
try {
|
|
return DateTime.tryParse(s);
|
|
} catch (_) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
for (final e in events) {
|
|
final parsedStart = tryParseDate(e.startDate);
|
|
final parsedEnd = tryParseDate(e.endDate);
|
|
|
|
if (parsedStart == null) {
|
|
// treat as ongoing or handle differently
|
|
} else if (parsedStart.isAtSameMomentAs(today) ||
|
|
(parsedStart.isBefore(today) &&
|
|
parsedEnd != null &&
|
|
!parsedEnd.isBefore(today))) {
|
|
ongoing.add(e);
|
|
} else if (parsedStart.isBefore(today)) {
|
|
// ignore past
|
|
}
|
|
}
|
|
|
|
|
|
if (mounted) {
|
|
setState(() {
|
|
_ongoingEvents = ongoing;
|
|
});
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(content: Text(userFriendlyError(e))));
|
|
}
|
|
} finally {
|
|
if (mounted) setState(() => _loadingEvents = false);
|
|
}
|
|
}
|
|
|
|
Future<void> _saveProfile(
|
|
String name, String email, String profileImage) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final currentEmail =
|
|
prefs.getString('current_email') ?? prefs.getString('email') ?? email;
|
|
|
|
final displayKey =
|
|
currentEmail.isNotEmpty ? 'display_name_$currentEmail' : 'display_name';
|
|
final profileImageKey =
|
|
currentEmail.isNotEmpty ? 'profileImage_$currentEmail' : 'profileImage';
|
|
|
|
await prefs.setString(displayKey, name);
|
|
await prefs.setString(profileImageKey, profileImage);
|
|
await prefs.setString('email', currentEmail);
|
|
await prefs.setString('current_email', currentEmail);
|
|
|
|
setState(() {
|
|
_username = name;
|
|
_email = currentEmail.isNotEmpty ? currentEmail : 'not provided';
|
|
_profileImage = profileImage;
|
|
});
|
|
}
|
|
|
|
// ───────── Image picking (unchanged) ─────────
|
|
|
|
Future<void> _pickFromGallery() async {
|
|
try {
|
|
final XFile? xfile =
|
|
await _picker.pickImage(source: ImageSource.gallery, imageQuality: 85);
|
|
if (xfile == null) return;
|
|
if (kIsWeb) {
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
content:
|
|
Text('Use "Enter Asset Path" on web/desktop or add server URL.')));
|
|
return;
|
|
}
|
|
final String path = xfile.path;
|
|
await _saveProfile(_username, _email, path);
|
|
// PROF-004: Upload to server on mobile
|
|
await _uploadProfilePhoto(path);
|
|
} catch (e) {
|
|
debugPrint('Image pick error: $e');
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(content: Text(userFriendlyError(e))));
|
|
}
|
|
}
|
|
|
|
// PROF-004: Upload profile photo to server
|
|
Future<void> _uploadProfilePhoto(String filePath) async {
|
|
try {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final token = prefs.getString('access_token') ?? '';
|
|
if (token.isEmpty) return;
|
|
final request = http.MultipartRequest(
|
|
'PATCH',
|
|
Uri.parse('${ApiEndpoints.baseUrl}/user/update-profile/'),
|
|
);
|
|
request.headers['Authorization'] = 'Bearer $token';
|
|
request.files.add(await http.MultipartFile.fromPath('profile_picture', filePath));
|
|
final response = await request.send();
|
|
if (response.statusCode == 200) {
|
|
final body = await response.stream.bytesToString();
|
|
final data = jsonDecode(body) as Map<String, dynamic>;
|
|
if (data['profile_picture'] != null) {
|
|
final newUrl = data['profile_picture'].toString();
|
|
final prefs2 = await SharedPreferences.getInstance();
|
|
final currentEmail = prefs2.getString('current_email') ?? prefs2.getString('email') ?? '';
|
|
final profileImageKey = currentEmail.isNotEmpty ? 'profileImage_$currentEmail' : 'profileImage';
|
|
await prefs2.setString(profileImageKey, newUrl);
|
|
if (mounted) setState(() => _profileImage = newUrl);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
debugPrint('Photo upload error: $e');
|
|
}
|
|
}
|
|
|
|
// PROF-002: Update district via API with cooldown check
|
|
Future<void> _updateDistrict(String district) async {
|
|
if (_districtLocked) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('District locked until $_districtNextChange')),
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
try {
|
|
final res = await _apiClient.post(
|
|
ApiEndpoints.updateProfile,
|
|
body: {'district': district},
|
|
);
|
|
final savedDistrict = res['district']?.toString() ?? district;
|
|
final changedAtStr = res['district_changed_at']?.toString() ?? '';
|
|
final now = DateTime.now();
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString('district', savedDistrict);
|
|
final changedAt = changedAtStr.isNotEmpty
|
|
? (DateTime.tryParse(changedAtStr) ?? now)
|
|
: now;
|
|
await prefs.setString('district_changed_at', changedAt.toIso8601String());
|
|
if (mounted) {
|
|
setState(() {
|
|
_district = savedDistrict;
|
|
_districtChangedAt = changedAt;
|
|
});
|
|
}
|
|
} catch (e) {
|
|
debugPrint('District update error: $e');
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context)
|
|
.showSnackBar(SnackBar(content: Text(userFriendlyError(e))));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Generates the share card via dart:ui Canvas and shares as PNG + caption.
|
|
Future<void> _shareRank(String tier, int lifetimeEp) async {
|
|
if (_sharingRank) return;
|
|
setState(() => _sharingRank = true);
|
|
try {
|
|
final imageUrl = _profileImage.isNotEmpty &&
|
|
!_profileImage.contains('default.png')
|
|
? (_profileImage.startsWith('http')
|
|
? _profileImage
|
|
: 'https://em.eventifyplus.com$_profileImage')
|
|
: null;
|
|
|
|
final gam = context.read<GamificationProvider>();
|
|
final p = gam.profile;
|
|
final stats = gam.currentUserStats;
|
|
|
|
final resolvedTier = stats?.level ?? _userTier ?? tier;
|
|
final resolvedEp = p?.lifetimeEp ?? lifetimeEp;
|
|
|
|
final bytes = await generateShareCardPng(
|
|
username: _username,
|
|
tier: resolvedTier,
|
|
lifetimeEp: resolvedEp,
|
|
currentEp: p?.currentEp ?? 0,
|
|
rewardPoints: p?.currentRp ?? 0,
|
|
eventifyId: _eventifyId,
|
|
district: _district,
|
|
imageUrl: imageUrl,
|
|
);
|
|
|
|
final shareText =
|
|
"I'm a ${resolvedTier.toUpperCase()} Explorer on Eventify Plus! "
|
|
"${formatEp(resolvedEp)} EP earned. "
|
|
"Let's connect on the platform for more.\nhttps://app.eventifyplus.com";
|
|
|
|
if (kIsWeb) {
|
|
try {
|
|
final xfile = XFile.fromData(
|
|
bytes,
|
|
name: 'eventify-rank.png',
|
|
mimeType: 'image/png',
|
|
);
|
|
await Share.shareXFiles(
|
|
[xfile],
|
|
subject: 'My Eventify Rank',
|
|
text: shareText,
|
|
);
|
|
} catch (_) {
|
|
await Clipboard.setData(ClipboardData(text: shareText));
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text(
|
|
'Caption copied! Save the image and paste caption when sharing.'),
|
|
duration: Duration(seconds: 5),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
} else {
|
|
final tempDir = await getTemporaryDirectory();
|
|
final file = File('${tempDir.path}/eventify_rank.png');
|
|
await file.writeAsBytes(bytes);
|
|
await Share.shareXFiles(
|
|
[XFile(file.path)],
|
|
subject: 'My Eventify Rank',
|
|
text: shareText,
|
|
);
|
|
}
|
|
} catch (e, st) {
|
|
debugPrint('_shareRank error: $e\n$st');
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('Share failed: $e')),
|
|
);
|
|
}
|
|
} finally {
|
|
if (mounted) setState(() => _sharingRank = false);
|
|
}
|
|
}
|
|
|
|
/// Shows a bottom sheet with the 14 Kerala district pills.
|
|
/// Used both from the header district row and from the Edit Profile sheet.
|
|
void _showDistrictPicker() {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (ctx) {
|
|
final theme = Theme.of(ctx);
|
|
return StatefulBuilder(
|
|
builder: (ctx2, setInner) {
|
|
return Container(
|
|
padding: const EdgeInsets.fromLTRB(18, 14, 18, 32),
|
|
decoration: BoxDecoration(
|
|
color: theme.cardColor,
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(
|
|
child: Container(
|
|
width: 48,
|
|
height: 6,
|
|
decoration: BoxDecoration(
|
|
color: theme.dividerColor,
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
'Select Your District',
|
|
style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'Used for leaderboard rankings. Can be changed once every 6 months.',
|
|
style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor),
|
|
),
|
|
const SizedBox(height: 12),
|
|
if (_districtLocked)
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 12),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.lock_outline, size: 14, color: Colors.amber),
|
|
const SizedBox(width: 6),
|
|
Text(
|
|
'Locked until $_districtNextChange',
|
|
style: const TextStyle(fontSize: 12, color: Colors.amber, fontWeight: FontWeight.w600),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Wrap(
|
|
spacing: 8,
|
|
runSpacing: 8,
|
|
children: _districts.map((d) {
|
|
final isSelected = _district == d;
|
|
return GestureDetector(
|
|
onTap: _districtLocked
|
|
? null
|
|
: () async {
|
|
setInner(() {});
|
|
Navigator.of(ctx2).pop();
|
|
await _updateDistrict(d);
|
|
},
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 180),
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: isSelected
|
|
? const Color(0xFF3B82F6)
|
|
: (_districtLocked
|
|
? theme.dividerColor.withOpacity(0.5)
|
|
: theme.cardColor),
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(
|
|
color: isSelected
|
|
? const Color(0xFF3B82F6)
|
|
: theme.dividerColor,
|
|
),
|
|
),
|
|
child: Text(
|
|
d,
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: isSelected
|
|
? Colors.white
|
|
: (_districtLocked
|
|
? theme.hintColor
|
|
: theme.textTheme.bodyMedium?.color),
|
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
const SizedBox(height: 8),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<void> _enterAssetPathDialog() async {
|
|
final ctl = TextEditingController(text: _profileImage);
|
|
final result = await showDialog<String?>(
|
|
context: context,
|
|
builder: (ctx) {
|
|
// Note: ctl is disposed after dialog closes below
|
|
final theme = Theme.of(ctx);
|
|
return AlertDialog(
|
|
title: const Text('Enter image path or URL'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextField(
|
|
controller: ctl,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Asset path (e.g. assets/images/profile.jpg) or URL',
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Use an asset path (for bundled images) or an https:// URL (web).',
|
|
style:
|
|
theme.textTheme.bodySmall?.copyWith(color: theme.hintColor),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(ctx).pop(null),
|
|
child: const Text('Cancel')),
|
|
ElevatedButton(
|
|
onPressed: () => Navigator.of(ctx).pop(ctl.text.trim()),
|
|
child: const Text('Use')),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
|
|
ctl.dispose();
|
|
if (result == null || result.isEmpty) return;
|
|
await _saveProfile(_username, _email, result);
|
|
}
|
|
|
|
Future<void> _openEditDialog() async {
|
|
final firstNameCtl = TextEditingController(text: _firstName ?? '');
|
|
final lastNameCtl = TextEditingController(text: _lastName ?? '');
|
|
final emailCtl = TextEditingController(text: _email == 'not provided' ? '' : _email);
|
|
final phoneCtl = TextEditingController(text: _phone ?? '');
|
|
final placeCtl = TextEditingController(text: _place ?? '');
|
|
final pincodeCtl = TextEditingController(text: _pincode ?? '');
|
|
final stateCtl = TextEditingController(text: _state ?? '');
|
|
final countryCtl = TextEditingController(text: _country ?? '');
|
|
final gamDistrict = context.read<GamificationProvider>().profile?.district;
|
|
|
|
showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (ctx) {
|
|
final theme = Theme.of(ctx);
|
|
final inputDecoration = InputDecoration(
|
|
filled: true,
|
|
fillColor: theme.cardColor,
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
|
);
|
|
|
|
return DraggableScrollableSheet(
|
|
expand: false,
|
|
initialChildSize: 0.85,
|
|
minChildSize: 0.5,
|
|
maxChildSize: 0.95,
|
|
builder: (context, scrollController) {
|
|
return Container(
|
|
padding: const EdgeInsets.fromLTRB(18, 14, 18, 32),
|
|
decoration: BoxDecoration(
|
|
color: theme.cardColor,
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
|
),
|
|
child: SingleChildScrollView(
|
|
controller: scrollController,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Handle bar
|
|
Center(
|
|
child: Container(
|
|
width: 48, height: 6,
|
|
decoration: BoxDecoration(
|
|
color: theme.dividerColor,
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
|
|
// Header row
|
|
Row(
|
|
children: [
|
|
Text('Personal Info',
|
|
style: theme.textTheme.titleMedium
|
|
?.copyWith(fontWeight: FontWeight.bold)),
|
|
const Spacer(),
|
|
IconButton(
|
|
icon: const Icon(Icons.photo_camera),
|
|
tooltip: 'Change photo',
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
await _pickFromGallery();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// ── Personal info ────────────────────────────────────
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextField(
|
|
controller: firstNameCtl,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: inputDecoration.copyWith(labelText: 'First Name *'),
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: TextField(
|
|
controller: lastNameCtl,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: inputDecoration.copyWith(labelText: 'Last Name'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 10),
|
|
|
|
TextField(
|
|
controller: emailCtl,
|
|
keyboardType: TextInputType.emailAddress,
|
|
decoration: inputDecoration.copyWith(labelText: 'Email *'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
|
|
TextField(
|
|
controller: phoneCtl,
|
|
keyboardType: TextInputType.phone,
|
|
decoration: inputDecoration.copyWith(labelText: 'Phone'),
|
|
),
|
|
const SizedBox(height: 20),
|
|
|
|
// ── Location ─────────────────────────────────────────
|
|
Text('Location',
|
|
style: theme.textTheme.labelLarge?.copyWith(
|
|
color: theme.hintColor,
|
|
fontWeight: FontWeight.w600,
|
|
letterSpacing: 0.8,
|
|
)),
|
|
const SizedBox(height: 10),
|
|
|
|
// District — tap to open picker (locked with cooldown)
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
_showDistrictPicker();
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
|
decoration: BoxDecoration(
|
|
color: theme.cardColor,
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: theme.dividerColor),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('Home District',
|
|
style: theme.textTheme.bodySmall
|
|
?.copyWith(color: theme.hintColor)),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
gamDistrict ?? _district ?? 'Tap to set district',
|
|
style: theme.textTheme.bodyMedium,
|
|
),
|
|
if (_districtLocked) ...[
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
'Next change: $_districtNextChange',
|
|
style: theme.textTheme.bodySmall
|
|
?.copyWith(color: Colors.amber[700]),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
Icon(
|
|
_districtLocked ? Icons.lock_outline : Icons.chevron_right,
|
|
size: 18,
|
|
color: _districtLocked ? Colors.amber : theme.hintColor,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 10),
|
|
|
|
TextField(
|
|
controller: placeCtl,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: inputDecoration.copyWith(labelText: 'Place'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
|
|
TextField(
|
|
controller: pincodeCtl,
|
|
keyboardType: TextInputType.number,
|
|
decoration: inputDecoration.copyWith(labelText: 'Pincode'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
|
|
TextField(
|
|
controller: stateCtl,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: inputDecoration.copyWith(labelText: 'State'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
|
|
TextField(
|
|
controller: countryCtl,
|
|
textCapitalization: TextCapitalization.words,
|
|
decoration: inputDecoration.copyWith(labelText: 'Country'),
|
|
),
|
|
const SizedBox(height: 20),
|
|
|
|
// ── Save / Cancel ─────────────────────────────────────
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
const SizedBox(width: 8),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
final firstName = firstNameCtl.text.trim();
|
|
final lastName = lastNameCtl.text.trim();
|
|
final email = emailCtl.text.trim();
|
|
final phone = phoneCtl.text.trim();
|
|
final place = placeCtl.text.trim();
|
|
final pincode = pincodeCtl.text.trim();
|
|
final stateVal = stateCtl.text.trim();
|
|
final country = countryCtl.text.trim();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
try {
|
|
// Build display name from first + last
|
|
final displayName = [firstName, lastName]
|
|
.where((s) => s.isNotEmpty)
|
|
.join(' ');
|
|
|
|
// API call
|
|
await _apiClient.post(
|
|
ApiEndpoints.updateProfile,
|
|
body: {
|
|
if (firstName.isNotEmpty) 'first_name': firstName,
|
|
if (lastName.isNotEmpty) 'last_name': lastName,
|
|
if (email.isNotEmpty) 'email': email,
|
|
if (phone.isNotEmpty) 'phone_number': phone,
|
|
if (place.isNotEmpty) 'place': place,
|
|
if (pincode.isNotEmpty) 'pincode': pincode,
|
|
if (stateVal.isNotEmpty) 'state': stateVal,
|
|
if (country.isNotEmpty) 'country': country,
|
|
},
|
|
);
|
|
|
|
// Persist to prefs
|
|
final prefs = await SharedPreferences.getInstance();
|
|
if (firstName.isNotEmpty) await prefs.setString('first_name', firstName);
|
|
if (lastName.isNotEmpty) await prefs.setString('last_name', lastName);
|
|
if (phone.isNotEmpty) await prefs.setString('phone_number', phone);
|
|
if (place.isNotEmpty) await prefs.setString('place', place);
|
|
if (pincode.isNotEmpty) await prefs.setString('pincode', pincode);
|
|
if (stateVal.isNotEmpty) await prefs.setString('state', stateVal);
|
|
if (country.isNotEmpty) await prefs.setString('country', country);
|
|
|
|
// Update display name if first name provided
|
|
if (displayName.isNotEmpty) {
|
|
await _saveProfile(displayName, email.isNotEmpty ? email : _email, _profileImage);
|
|
} else if (email.isNotEmpty) {
|
|
await _saveProfile(_username, email, _profileImage);
|
|
}
|
|
|
|
if (mounted) {
|
|
setState(() {
|
|
if (firstName.isNotEmpty) _firstName = firstName;
|
|
if (lastName.isNotEmpty) _lastName = lastName;
|
|
if (phone.isNotEmpty) _phone = phone;
|
|
if (place.isNotEmpty) _place = place;
|
|
if (pincode.isNotEmpty) _pincode = pincode;
|
|
if (stateVal.isNotEmpty) _state = stateVal;
|
|
if (country.isNotEmpty) _country = country;
|
|
});
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Profile updated')),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
if (mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text(userFriendlyError(e))),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
).then((_) {
|
|
firstNameCtl.dispose();
|
|
lastNameCtl.dispose();
|
|
emailCtl.dispose();
|
|
phoneCtl.dispose();
|
|
placeCtl.dispose();
|
|
pincodeCtl.dispose();
|
|
stateCtl.dispose();
|
|
countryCtl.dispose();
|
|
});
|
|
}
|
|
|
|
// ───────── Avatar builder (AUTH-006 / PROF-004: DiceBear via TierAvatarRing) ─────────
|
|
|
|
Widget _buildProfileAvatar({double size = 96}) {
|
|
final path = _profileImage.trim();
|
|
String? imageUrl;
|
|
if (path.isNotEmpty && !path.contains('default.png')) {
|
|
if (path.startsWith('http')) {
|
|
imageUrl = path;
|
|
} else if (path.startsWith('/media/')) {
|
|
imageUrl = 'https://em.eventifyplus.com$path';
|
|
}
|
|
}
|
|
return TierAvatarRing(
|
|
username: _username.isNotEmpty ? _username : _email,
|
|
tier: _userTier ?? '',
|
|
size: size,
|
|
imageUrl: imageUrl,
|
|
);
|
|
}
|
|
|
|
// ───────── Event list tile (updated styling) ─────────
|
|
|
|
Widget _eventListTileFromModel(EventModel ev, {bool faded = false}) {
|
|
final theme = Theme.of(context);
|
|
final title = ev.title ?? ev.name ?? '';
|
|
final dateLabel =
|
|
(ev.startDate != null && ev.endDate != null && ev.startDate == ev.endDate)
|
|
? ev.startDate!
|
|
: ((ev.startDate != null && ev.endDate != null)
|
|
? '${ev.startDate} - ${ev.endDate}'
|
|
: (ev.startDate ?? ''));
|
|
final location = ev.place ?? '';
|
|
final imageUrl = (ev.thumbImg != null && ev.thumbImg!.isNotEmpty)
|
|
? ev.thumbImg!
|
|
: (ev.images.isNotEmpty ? ev.images.first.image : null);
|
|
|
|
final titleStyle = theme.textTheme.bodyLarge?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
color: faded ? theme.hintColor : theme.textTheme.bodyLarge?.color);
|
|
final subtitleStyle = theme.textTheme.bodySmall?.copyWith(
|
|
fontSize: 13,
|
|
color: faded
|
|
? theme.hintColor.withValues(alpha: 0.7)
|
|
: theme.hintColor);
|
|
|
|
Widget leadingWidget() {
|
|
if (imageUrl != null && imageUrl.trim().isNotEmpty) {
|
|
if (imageUrl.startsWith('http')) {
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: CachedNetworkImage(
|
|
imageUrl: imageUrl,
|
|
memCacheWidth: 120,
|
|
memCacheHeight: 120,
|
|
width: 60,
|
|
height: 60,
|
|
fit: BoxFit.cover,
|
|
placeholder: (_, __) => Container(
|
|
width: 60,
|
|
height: 60,
|
|
color: const Color(0xFFE5E7EB)),
|
|
errorWidget: (_, __, ___) => Container(
|
|
width: 60,
|
|
height: 60,
|
|
color: theme.dividerColor,
|
|
child: Icon(Icons.image, color: theme.hintColor))));
|
|
} else if (!kIsWeb) {
|
|
final path = imageUrl;
|
|
if (path.startsWith('/') || path.contains(Platform.pathSeparator)) {
|
|
final file = File(path);
|
|
if (file.existsSync()) {
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Image.file(file,
|
|
width: 60,
|
|
height: 60,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => Container(
|
|
width: 60,
|
|
height: 60,
|
|
color: theme.dividerColor,
|
|
child: Icon(Icons.image, color: theme.hintColor))));
|
|
}
|
|
}
|
|
}
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: Image.asset(imageUrl,
|
|
width: 60,
|
|
height: 60,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => Container(
|
|
width: 60,
|
|
height: 60,
|
|
color: theme.dividerColor,
|
|
child: Icon(Icons.image, color: theme.hintColor))));
|
|
}
|
|
return Container(
|
|
width: 60,
|
|
height: 60,
|
|
decoration: BoxDecoration(
|
|
color: theme.dividerColor,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Icon(Icons.image, color: theme.hintColor));
|
|
}
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: theme.cardColor,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.03),
|
|
blurRadius: 15,
|
|
offset: const Offset(0, 4))
|
|
],
|
|
),
|
|
child: ListTile(
|
|
onTap: () {
|
|
if (ev.id != null) {
|
|
Navigator.of(context)
|
|
.push(MaterialPageRoute(builder: (_) => LearnMoreScreen(eventId: ev.id, initialEvent: ev)));
|
|
}
|
|
},
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
leading: leadingWidget(),
|
|
title: Text(title, style: titleStyle),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const SizedBox(height: 4),
|
|
Text(dateLabel, style: subtitleStyle),
|
|
const SizedBox(height: 2),
|
|
Text(location, style: subtitleStyle),
|
|
],
|
|
),
|
|
trailing: Container(
|
|
width: 40,
|
|
height: 40,
|
|
decoration: BoxDecoration(
|
|
color: theme.colorScheme.primary.withValues(alpha: 0.12),
|
|
borderRadius: BorderRadius.circular(10)),
|
|
child: Icon(Icons.qr_code_scanner, color: theme.colorScheme.primary),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════
|
|
// NEW UI WIDGETS — matching web profile layout
|
|
// ═══════════════════════════════════════════════
|
|
|
|
// ═══════════════════════════════════════════════
|
|
// MODERN UI WIDGETS
|
|
// ═══════════════════════════════════════════════
|
|
|
|
Widget _buildModernHeader(BuildContext context, ThemeData theme) {
|
|
return Consumer<GamificationProvider>(
|
|
builder: (context, gam, _) {
|
|
final stats = gam.currentUserStats;
|
|
final p = gam.profile;
|
|
final tier = stats?.level ?? _userTier ?? 'Bronze';
|
|
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.only(bottom: 30),
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [Color(0xFF2563EB), Color(0xFF3B82F6)],
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
),
|
|
borderRadius: BorderRadius.only(
|
|
bottomLeft: Radius.circular(40),
|
|
bottomRight: Radius.circular(40),
|
|
),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
// Top Bar
|
|
SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
|
child: Row(
|
|
children: [
|
|
const Spacer(),
|
|
GestureDetector(
|
|
onTap: () => Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (_) => const SettingsScreen()),
|
|
),
|
|
child: Container(
|
|
width: 40,
|
|
height: 40,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white24,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: const Icon(Icons.settings, color: Colors.white),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
|
|
// Profile Avatar
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: Colors.white.withOpacity(0.5), width: 2),
|
|
),
|
|
child: _buildProfileAvatar(size: 100),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Username
|
|
Text(
|
|
(p?.username.isNotEmpty == true) ? p!.username : _username,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.w800,
|
|
letterSpacing: -0.5,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
|
|
// Eventify ID Badge
|
|
if ((p?.eventifyId ?? _eventifyId) != null)
|
|
GestureDetector(
|
|
onTap: () {
|
|
final id = p?.eventifyId ?? _eventifyId!;
|
|
Clipboard.setData(ClipboardData(text: id));
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('ID copied to clipboard')),
|
|
);
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(color: Colors.white.withValues(alpha: 0.2)),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.copy, size: 14, color: Colors.white70),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
p?.eventifyId ?? _eventifyId!,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w500,
|
|
fontFamily: 'monospace',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// Location (District) — tappable to open picker
|
|
GestureDetector(
|
|
onTap: _showDistrictPicker,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
const Icon(Icons.location_on_outlined, color: Colors.white, size: 18),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
p?.district ?? _district ?? 'Tap to set district',
|
|
style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w400),
|
|
),
|
|
const SizedBox(width: 4),
|
|
Icon(
|
|
_districtLocked ? Icons.lock_outline : Icons.edit_outlined,
|
|
color: Colors.white70,
|
|
size: 14,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (_districtNextChange.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 4),
|
|
child: Text(
|
|
'Next change: $_districtNextChange',
|
|
style: TextStyle(color: Colors.white.withOpacity(0.7), fontSize: 12),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
|
|
// Tier Badge
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFFFD1A9), // Matching "Bronze" color from screenshot
|
|
borderRadius: BorderRadius.circular(30),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.shield_outlined, size: 18, color: Color(0xFF92400E)),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
tier.toUpperCase(),
|
|
style: const TextStyle(
|
|
color: Color(0xFF92400E),
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
|
|
// Buttons
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: Column(
|
|
children: [
|
|
_buildHeaderButton(
|
|
label: 'Edit Profile',
|
|
icon: Icons.person_outline,
|
|
onTap: _openEditDialog,
|
|
),
|
|
const SizedBox(height: 12),
|
|
_buildHeaderButton(
|
|
label: _sharingRank ? 'Generating...' : 'Share Rank',
|
|
icon: _sharingRank ? Icons.hourglass_top_outlined : Icons.share_outlined,
|
|
onTap: _sharingRank
|
|
? () {}
|
|
: () => _shareRank(tier, p?.lifetimeEp ?? 0),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildHeaderButton({required String label, required IconData icon, required VoidCallback onTap}) {
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
child: Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(vertical: 14),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: Colors.white.withOpacity(0.3)),
|
|
color: Colors.white.withValues(alpha: 0.05),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(icon, color: Colors.white, size: 20),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
label,
|
|
style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w600),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildModernStatCards(GamificationProvider gam, ThemeData theme) {
|
|
final p = gam.profile;
|
|
if (p == null) return const SizedBox.shrink();
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 20),
|
|
child: Column(
|
|
children: [
|
|
_buildStatRowCard('Lifetime EP', '${p.lifetimeEp}', Icons.bolt, const Color(0xFFEFF6FF), const Color(0xFF3B82F6)),
|
|
const SizedBox(height: 12),
|
|
_buildStatRowCard('Liquid EP', '${p.currentEp}', Icons.hexagon_outlined, const Color(0xFFF0FDF4), const Color(0xFF22C55E)),
|
|
const SizedBox(height: 12),
|
|
_buildStatRowCard('Reward Points', '${p.currentRp}', Icons.card_giftcard, const Color(0xFFFFFBEB), const Color(0xFFF59E0B)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatRowCard(String label, String value, IconData icon, Color bgColor, Color iconColor) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(color: Colors.grey.shade100),
|
|
boxShadow: [
|
|
BoxShadow(color: Colors.black.withOpacity(0.02), blurRadius: 10, offset: const Offset(0, 4)),
|
|
],
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(
|
|
color: bgColor,
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
child: Icon(icon, color: iconColor, size: 24),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
value,
|
|
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.w800, color: Color(0xFF1F2937)),
|
|
),
|
|
Text(
|
|
label,
|
|
style: TextStyle(fontSize: 14, color: Colors.grey.shade500, fontWeight: FontWeight.w500),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildTierProgressCard(GamificationProvider gam, ThemeData theme) {
|
|
final ep = gam.profile?.lifetimeEp ?? 0;
|
|
final currentTier = tierFromEp(ep);
|
|
final nextThreshold = nextTierThreshold(currentTier);
|
|
final startEp = tierStartEp(currentTier);
|
|
|
|
double progress = 0.0;
|
|
String nextInfo = '';
|
|
if (nextThreshold != null) {
|
|
final needed = nextThreshold - ep;
|
|
final range = nextThreshold - startEp;
|
|
progress = ((ep - startEp) / range).clamp(0.0, 1.0);
|
|
nextInfo = '$needed EP to ${tierLabel(ContributorTier.values[currentTier.index + 1]).toUpperCase()}';
|
|
} else {
|
|
progress = 1.0;
|
|
nextInfo = 'MAX TIER REACHED';
|
|
}
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 18),
|
|
padding: const EdgeInsets.all(24),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(24),
|
|
border: Border.all(color: Colors.grey.shade100),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
tierLabel(currentTier).toUpperCase(),
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w800, color: Color(0xFF1F2937)),
|
|
),
|
|
Text(
|
|
nextInfo,
|
|
style: TextStyle(fontSize: 13, color: Colors.grey.shade500, fontWeight: FontWeight.w600),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(10),
|
|
child: LinearProgressIndicator(
|
|
value: progress,
|
|
minHeight: 10,
|
|
backgroundColor: const Color(0xFFF3F4F6),
|
|
valueColor: const AlwaysStoppedAnimation<Color>(Color(0xFF2563EB)),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Text(
|
|
'$ep EP total',
|
|
style: TextStyle(fontSize: 13, color: Colors.grey.shade400, fontWeight: FontWeight.w500),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildContributedEventsSection(GamificationProvider gam, ThemeData theme) {
|
|
final submissions = gam.submissions;
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 32, 20, 16),
|
|
child: Row(
|
|
children: [
|
|
const Text(
|
|
'Contributed Events',
|
|
style: TextStyle(fontSize: 22, fontWeight: FontWeight.w800, color: Color(0xFF1F2937)),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF3F4F6),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Text(
|
|
'${submissions.length}',
|
|
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: Color(0xFF6B7280)),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (submissions.isEmpty)
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
|
child: Text('No contributions yet. Start contributing to earn EP!'),
|
|
)
|
|
else
|
|
ListView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
padding: const EdgeInsets.symmetric(horizontal: 18),
|
|
itemCount: submissions.length,
|
|
itemBuilder: (ctx, i) => _buildSubmissionCard(submissions[i], theme),
|
|
),
|
|
const SizedBox(height: 100),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildSubmissionCard(SubmissionModel sub, ThemeData theme) {
|
|
Color statusColor;
|
|
Color statusBgColor;
|
|
String statusLabel = sub.status.toUpperCase();
|
|
|
|
switch (sub.status.toUpperCase()) {
|
|
case 'APPROVED':
|
|
statusColor = const Color(0xFF059669);
|
|
statusBgColor = const Color(0xFFD1FAE5);
|
|
break;
|
|
case 'REJECTED':
|
|
statusColor = const Color(0xFFDC2626);
|
|
statusBgColor = const Color(0xFFFEE2E2);
|
|
break;
|
|
default: // PENDING
|
|
statusColor = const Color(0xFFD97706);
|
|
statusBgColor = const Color(0xFFFEF3C7);
|
|
statusLabel = 'PENDING';
|
|
}
|
|
|
|
final dateStr = '${sub.createdAt.day} ${_getMonth(sub.createdAt.month)} ${sub.createdAt.year}';
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 16),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(color: Colors.grey.shade100),
|
|
boxShadow: [
|
|
BoxShadow(color: Colors.black.withOpacity(0.01), blurRadius: 10, offset: const Offset(0, 4)),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
sub.eventName,
|
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w800, color: Color(0xFF1F2937)),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: statusBgColor,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.access_time_filled, size: 14, color: statusColor),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
statusLabel,
|
|
style: TextStyle(fontSize: 11, fontWeight: FontWeight.bold, color: statusColor),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
Icon(Icons.calendar_today_outlined, size: 14, color: Colors.grey.shade400),
|
|
const SizedBox(width: 6),
|
|
Text(dateStr, style: TextStyle(color: Colors.grey.shade500, fontSize: 13)),
|
|
const SizedBox(width: 16),
|
|
Icon(Icons.location_on_outlined, size: 14, color: Colors.grey.shade400),
|
|
const SizedBox(width: 6),
|
|
Expanded(
|
|
child: Text(
|
|
sub.district ?? 'Unknown',
|
|
style: TextStyle(color: Colors.grey.shade500, fontSize: 13),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
if (sub.status.toUpperCase() == 'APPROVED' && sub.epAwarded > 0)
|
|
Text(
|
|
'+${sub.epAwarded} EP',
|
|
style: const TextStyle(color: Color(0xFF059669), fontWeight: FontWeight.w800, fontSize: 14),
|
|
),
|
|
],
|
|
),
|
|
if (sub.category.isNotEmpty) ...[
|
|
const SizedBox(height: 12),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF3F4F6),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Text(
|
|
sub.category,
|
|
style: const TextStyle(fontSize: 12, color: Color(0xFF6B7280), fontWeight: FontWeight.w500),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
String _getMonth(int m) {
|
|
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
return months[m - 1];
|
|
}
|
|
|
|
// ───────── Gradient Header ─────────
|
|
|
|
|
|
Widget _buildGradientHeader(BuildContext context, double height) {
|
|
return Container(
|
|
width: double.infinity,
|
|
height: height,
|
|
decoration: AppDecoration.blueGradient.copyWith(
|
|
borderRadius: const BorderRadius.only(
|
|
bottomLeft: Radius.circular(40),
|
|
bottomRight: Radius.circular(40),
|
|
),
|
|
),
|
|
child: SafeArea(
|
|
bottom: false,
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 14, 20, 0),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Share rank card button
|
|
Consumer<GamificationProvider>(
|
|
builder: (context, gam, _) => GestureDetector(
|
|
onTap: _sharingRank
|
|
? null
|
|
: () => _shareRank(
|
|
gam.currentUserStats?.level ?? _userTier ?? 'Bronze',
|
|
gam.profile?.lifetimeEp ?? 0,
|
|
),
|
|
child: Container(
|
|
width: 40,
|
|
height: 40,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white24,
|
|
borderRadius: BorderRadius.circular(10)),
|
|
child: Icon(
|
|
_sharingRank ? Icons.hourglass_top_outlined : Icons.share_outlined,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const Spacer(),
|
|
Text(
|
|
'Profile',
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
color: Colors.white, fontWeight: FontWeight.w600),
|
|
),
|
|
const Spacer(),
|
|
GestureDetector(
|
|
onTap: () => Navigator.of(context)
|
|
.push(MaterialPageRoute(builder: (_) => const SettingsScreen())),
|
|
child: Container(
|
|
width: 40,
|
|
height: 40,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white24,
|
|
borderRadius: BorderRadius.circular(10)),
|
|
child: const Icon(Icons.settings, color: Colors.white),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// ───────── Cover Banner ─────────
|
|
|
|
Widget _buildCoverBanner() {
|
|
return Stack(
|
|
children: [
|
|
Container(
|
|
height: 160,
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(16),
|
|
gradient: const LinearGradient(
|
|
colors: [
|
|
Color(0xFFE879A8), // rose/pink tint (page bg bleed)
|
|
Color(0xFF7DD3FC), // sky-300
|
|
Color(0xFF67E8F9), // cyan-300
|
|
Color(0xFF0284C7), // sky-600
|
|
],
|
|
stops: [0.0, 0.35, 0.6, 1.0],
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
),
|
|
),
|
|
),
|
|
// Edit pencil button (top-right, matching web)
|
|
Positioned(
|
|
top: 16,
|
|
right: 16,
|
|
child: GestureDetector(
|
|
onTap: () => _openEditDialog(),
|
|
child: Container(
|
|
width: 36,
|
|
height: 36,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withValues(alpha: 0.2),
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(Icons.edit, color: Colors.white, size: 18),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// ───────── Avatar overlapping banner + EXP bar ─────────
|
|
|
|
Widget _buildAvatarSection() {
|
|
// Use a Stack so the avatar overlaps the bottom of the banner
|
|
return Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
// Banner
|
|
_buildCoverBanner(),
|
|
// Avatar positioned at bottom-left, half overlapping
|
|
Positioned(
|
|
bottom: -36,
|
|
left: 16,
|
|
child: GestureDetector(
|
|
onTap: () => _openEditDialog(),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: Colors.white, width: 3),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.1),
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: _buildProfileAvatar(size: 80),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// ───────── Animated EXP Progress Bar ─────────
|
|
|
|
Widget _buildExpBar() {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'exp.',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w300,
|
|
color: Colors.grey.shade500,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: AnimatedBuilder(
|
|
animation: _animController,
|
|
builder: (context, _) => LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final fullWidth = constraints.maxWidth;
|
|
final filledWidth = fullWidth * _expProgress;
|
|
return Container(
|
|
height: 8,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(4),
|
|
color: Colors.grey.shade200,
|
|
),
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Container(
|
|
width: filledWidth,
|
|
height: 8,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(4),
|
|
gradient: _expGradient,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// ───────── Stats Row (animated counters + top/bottom borders) ─────────
|
|
|
|
Widget _buildStatsRow() {
|
|
Widget statColumn(String value, String label) {
|
|
return Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
value,
|
|
style: const TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppConstants.textPrimary,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
label,
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w300,
|
|
color: AppConstants.textSecondary,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 8),
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
decoration: BoxDecoration(
|
|
border: Border(
|
|
top: BorderSide(color: Colors.grey.shade200, width: 1),
|
|
bottom: BorderSide(color: Colors.grey.shade200, width: 1),
|
|
),
|
|
),
|
|
child: AnimatedBuilder(
|
|
animation: _animController,
|
|
builder: (context, _) => IntrinsicHeight(
|
|
child: Row(
|
|
children: [
|
|
statColumn(_formatNumber(_animatedLikes), 'Likes'),
|
|
VerticalDivider(color: Colors.grey.shade200, thickness: 1, width: 1),
|
|
statColumn(_formatNumber(_animatedPosts), 'Posts'),
|
|
VerticalDivider(color: Colors.grey.shade200, thickness: 1, width: 1),
|
|
statColumn(_formatNumber(_animatedViews), 'Views'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// ───────── Social Icons Row ─────────
|
|
|
|
Widget _buildSocialIcons() {
|
|
final icons = [
|
|
Icons.emoji_events_outlined, // trophy (matching web)
|
|
Icons.camera_alt_outlined, // instagram camera
|
|
Icons.flutter_dash, // twitter-like bird
|
|
Icons.layers_outlined, // layers/stack
|
|
];
|
|
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: icons.map((icon) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Icon(icon, size: 24, color: Colors.grey.shade500),
|
|
);
|
|
}).toList(),
|
|
);
|
|
}
|
|
|
|
// ───────── Rainbow Bar ─────────
|
|
|
|
Widget _buildRainbowBar() {
|
|
return Container(
|
|
height: 4,
|
|
margin: const EdgeInsets.symmetric(horizontal: 24),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(2),
|
|
gradient: _expGradient,
|
|
),
|
|
);
|
|
}
|
|
|
|
// ───────── Profile Card (white, overlapping header) ─────────
|
|
|
|
Widget _buildProfileCard(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: theme.cardColor,
|
|
borderRadius: BorderRadius.circular(32),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.03),
|
|
blurRadius: 15,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Cover Banner + Avatar
|
|
_buildAvatarSection(),
|
|
|
|
// Spacer for avatar overflow (avatar extends 36px below banner)
|
|
const SizedBox(height: 44),
|
|
|
|
// EXP bar
|
|
_buildExpBar(),
|
|
const SizedBox(height: 16),
|
|
|
|
// Name
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Text(
|
|
_username,
|
|
style: const TextStyle(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppConstants.textPrimary,
|
|
letterSpacing: -0.3,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
|
|
// AUTH-003 / PROF-001: Eventify ID badge
|
|
if (_eventifyId != null && _eventifyId!.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Clipboard.setData(ClipboardData(text: _eventifyId!));
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Eventify ID copied'),
|
|
duration: Duration(seconds: 2),
|
|
),
|
|
);
|
|
},
|
|
child: Container(
|
|
margin: const EdgeInsets.only(top: 2),
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF1E3A8A).withOpacity(0.3),
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(
|
|
color: const Color(0xFF3B82F6).withOpacity(0.5)),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.badge_outlined,
|
|
size: 12, color: Color(0xFF93C5FD)),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
_eventifyId!,
|
|
style: const TextStyle(
|
|
fontSize: 11,
|
|
color: Color(0xFF93C5FD),
|
|
fontFamily: 'monospace',
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
|
|
// Email
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Text(
|
|
_email,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w300,
|
|
color: AppConstants.textSecondary,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
|
|
// Stats Row
|
|
_buildStatsRow(),
|
|
const SizedBox(height: 24),
|
|
|
|
// Social Icons
|
|
_buildSocialIcons(),
|
|
const SizedBox(height: 16),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// ───────── Event Sections ─────────
|
|
|
|
Widget _buildEventSections(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
Widget sectionHeading(String text) {
|
|
return Text(
|
|
text,
|
|
style: theme.textTheme.titleMedium
|
|
?.copyWith(fontWeight: FontWeight.w600, fontSize: 18),
|
|
);
|
|
}
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(18, 16, 18, 0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Ongoing Events
|
|
if (_ongoingEvents.isNotEmpty) ...[
|
|
sectionHeading('Ongoing Events'),
|
|
const SizedBox(height: 12),
|
|
Column(
|
|
children:
|
|
_ongoingEvents.map((e) => _eventListTileFromModel(e)).toList()),
|
|
const SizedBox(height: 24),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════
|
|
// LANDSCAPE LAYOUT
|
|
// ═══════════════════════════════════════════════
|
|
|
|
Widget _buildLandscapeLeftPanel(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return SafeArea(
|
|
child: SingleChildScrollView(
|
|
physics: const BouncingScrollPhysics(),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
// Top bar row — title + settings
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
|
|
child: Row(
|
|
children: [
|
|
const Text(
|
|
'Profile',
|
|
style: TextStyle(color: Colors.white, fontSize: 22, fontWeight: FontWeight.w700),
|
|
),
|
|
const Spacer(),
|
|
GestureDetector(
|
|
onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => const SettingsScreen())),
|
|
child: Container(
|
|
width: 40,
|
|
height: 40,
|
|
decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(10)),
|
|
child: const Icon(Icons.settings, color: Colors.white),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
// Avatar + name section
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: Colors.white, width: 3),
|
|
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.15), blurRadius: 8, offset: const Offset(0, 2))],
|
|
),
|
|
child: _buildProfileAvatar(size: 64),
|
|
),
|
|
const SizedBox(width: 14),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
_username.isNotEmpty ? _username : 'Guest User',
|
|
style: const TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.w700),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
_email,
|
|
style: const TextStyle(color: Colors.white70, fontSize: 13),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
// EXP Bar
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: _buildExpBar(),
|
|
),
|
|
const SizedBox(height: 20),
|
|
// Stats row
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(14),
|
|
),
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
child: _buildLandscapeStats(context, textColor: Colors.white),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
// Edit profile button
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: OutlinedButton.icon(
|
|
onPressed: _openEditDialog,
|
|
icon: const Icon(Icons.edit, size: 16, color: Colors.white),
|
|
label: const Text('Edit Profile', style: TextStyle(color: Colors.white)),
|
|
style: OutlinedButton.styleFrom(
|
|
side: const BorderSide(color: Colors.white38),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildLandscapeStats(BuildContext context, {Color? textColor}) {
|
|
final color = textColor ?? Theme.of(context).textTheme.bodyLarge?.color;
|
|
final hintColor = textColor?.withOpacity(0.6) ?? Theme.of(context).hintColor;
|
|
|
|
String fmt(int v) => v >= 1000 ? '${(v / 1000).toStringAsFixed(1)}K' : '$v';
|
|
|
|
return AnimatedBuilder(
|
|
animation: _animController,
|
|
builder: (_, __) => Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
_landscapeStatItem(fmt(_animatedLikes), 'Likes', color, hintColor),
|
|
_landscapeStatDivider(),
|
|
_landscapeStatItem(fmt(_animatedPosts), 'Posts', color, hintColor),
|
|
_landscapeStatDivider(),
|
|
_landscapeStatItem(fmt(_animatedViews), 'Views', color, hintColor),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _landscapeStatItem(String value, String label, Color? valueColor, Color? labelColor) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(value, style: TextStyle(fontSize: 20, fontWeight: FontWeight.w700, color: valueColor)),
|
|
const SizedBox(height: 2),
|
|
Text(label, style: TextStyle(fontSize: 12, color: labelColor, fontWeight: FontWeight.w400)),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _landscapeStatDivider() => Container(width: 1, height: 36, color: Colors.white24);
|
|
|
|
Widget _buildLandscapeRightPanel(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
|
|
Widget _eventList(List<EventModel> events, {bool faded = false}) {
|
|
if (_loadingEvents) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
if (events.isEmpty) {
|
|
return Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(32),
|
|
child: Text('No events', style: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor)),
|
|
),
|
|
);
|
|
}
|
|
return ListView.builder(
|
|
physics: const BouncingScrollPhysics(),
|
|
padding: const EdgeInsets.fromLTRB(18, 8, 18, 32),
|
|
itemCount: events.length,
|
|
itemBuilder: (ctx, i) => _eventListTileFromModel(events[i], faded: faded),
|
|
);
|
|
}
|
|
|
|
return SafeArea(
|
|
child: DefaultTabController(
|
|
length: 1,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const LandscapeSectionHeader(title: 'My Events'),
|
|
// Tab bar
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 8),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: theme.dividerColor.withOpacity(0.5),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: TabBar(
|
|
labelColor: Colors.white,
|
|
unselectedLabelColor: theme.hintColor,
|
|
indicator: BoxDecoration(
|
|
color: theme.colorScheme.primary,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
labelStyle: const TextStyle(fontWeight: FontWeight.w600, fontSize: 13),
|
|
tabs: const [
|
|
Tab(text: 'Ongoing'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: TabBarView(
|
|
children: [
|
|
_eventList(_ongoingEvents),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════
|
|
// DESKTOP LAYOUT (Figma: full-width banner + 3-col grids)
|
|
// ═══════════════════════════════════════════════
|
|
|
|
Widget _buildDesktopLayout(BuildContext context, ThemeData theme) {
|
|
return Scaffold(
|
|
backgroundColor: theme.scaffoldBackgroundColor,
|
|
body: Consumer<GamificationProvider>(
|
|
builder: (context, gam, _) {
|
|
return SingleChildScrollView(
|
|
physics: const BouncingScrollPhysics(),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Full-width profile header + card (reuse existing widgets)
|
|
Stack(
|
|
children: [
|
|
_buildGradientHeader(context, 200),
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 130),
|
|
child: _buildProfileCard(context),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 24),
|
|
// Ongoing Events (only if non-empty)
|
|
if (_ongoingEvents.isNotEmpty)
|
|
_buildDesktopEventSection(
|
|
context,
|
|
title: 'Ongoing Events',
|
|
events: _ongoingEvents,
|
|
faded: false,
|
|
),
|
|
const SizedBox(height: 32),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Section heading row ("Title" + "View All >") followed by a 3-column grid.
|
|
Widget _buildDesktopEventSection(
|
|
BuildContext context, {
|
|
required String title,
|
|
required List<EventModel> events,
|
|
bool faded = false,
|
|
String? emptyMessage,
|
|
}) {
|
|
final theme = Theme.of(context);
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Heading row
|
|
Row(
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: theme.textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.w700,
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
if (events.isNotEmpty)
|
|
TextButton(
|
|
onPressed: () {
|
|
// View all — no-op for now; could navigate to a full list
|
|
},
|
|
child: Text(
|
|
'View All >',
|
|
style: TextStyle(
|
|
color: theme.colorScheme.primary,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
|
|
// Content
|
|
if (_loadingEvents)
|
|
const Center(child: CircularProgressIndicator())
|
|
else if (events.isEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
child: Text(
|
|
emptyMessage ?? 'No events',
|
|
style: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor),
|
|
),
|
|
)
|
|
else
|
|
GridView.builder(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 3,
|
|
crossAxisSpacing: 16,
|
|
mainAxisSpacing: 16,
|
|
childAspectRatio: 0.82,
|
|
),
|
|
itemCount: events.length,
|
|
itemBuilder: (ctx, i) =>
|
|
_buildDesktopEventGridCard(events[i], faded: faded),
|
|
),
|
|
|
|
const SizedBox(height: 24),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// A single event card for the desktop grid: image on top, title, date (blue dot), venue (green dot).
|
|
Widget _buildDesktopEventGridCard(EventModel ev, {bool faded = false}) {
|
|
final theme = Theme.of(context);
|
|
final title = ev.title ?? ev.name ?? '';
|
|
final dateLabel =
|
|
(ev.startDate != null && ev.endDate != null && ev.startDate == ev.endDate)
|
|
? ev.startDate!
|
|
: ((ev.startDate != null && ev.endDate != null)
|
|
? '${ev.startDate} - ${ev.endDate}'
|
|
: (ev.startDate ?? ''));
|
|
final location = ev.place ?? '';
|
|
final imageUrl = (ev.thumbImg != null && ev.thumbImg!.isNotEmpty)
|
|
? ev.thumbImg!
|
|
: (ev.images.isNotEmpty ? ev.images.first.image : null);
|
|
|
|
final titleColor = faded ? theme.hintColor : (theme.textTheme.bodyLarge?.color);
|
|
final subtitleColor = faded
|
|
? theme.hintColor.withValues(alpha: 0.7)
|
|
: theme.hintColor;
|
|
|
|
return GestureDetector(
|
|
onTap: () {
|
|
if (ev.id != null) {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute(builder: (_) => LearnMoreScreen(eventId: ev.id, initialEvent: ev)),
|
|
);
|
|
}
|
|
},
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: theme.cardColor,
|
|
borderRadius: BorderRadius.circular(14),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.06),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 3),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Image
|
|
Expanded(
|
|
flex: 3,
|
|
child: ClipRRect(
|
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(14)),
|
|
child: _buildCardImage(imageUrl, theme),
|
|
),
|
|
),
|
|
// Text content
|
|
Expanded(
|
|
flex: 2,
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 10, 12, 10),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// Title
|
|
Text(
|
|
title,
|
|
style: theme.textTheme.titleSmall?.copyWith(
|
|
fontWeight: FontWeight.w700,
|
|
color: titleColor,
|
|
),
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const Spacer(),
|
|
// Date row with blue dot
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 8,
|
|
height: 8,
|
|
decoration: const BoxDecoration(
|
|
color: Color(0xFF3B82F6),
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
dateLabel,
|
|
style: theme.textTheme.bodySmall?.copyWith(color: subtitleColor),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 4),
|
|
// Venue row with green dot
|
|
Row(
|
|
children: [
|
|
Container(
|
|
width: 8,
|
|
height: 8,
|
|
decoration: const BoxDecoration(
|
|
color: Color(0xFF22C55E),
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
location,
|
|
style: theme.textTheme.bodySmall?.copyWith(color: subtitleColor),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Helper to build the image widget for a desktop grid card.
|
|
Widget _buildCardImage(String? imageUrl, ThemeData theme) {
|
|
if (imageUrl != null && imageUrl.trim().isNotEmpty) {
|
|
if (imageUrl.startsWith('http')) {
|
|
return CachedNetworkImage(
|
|
imageUrl: imageUrl,
|
|
memCacheWidth: 400,
|
|
memCacheHeight: 400,
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
fit: BoxFit.cover,
|
|
placeholder: (_, __) => Container(color: theme.dividerColor),
|
|
errorWidget: (_, __, ___) => Container(
|
|
color: theme.dividerColor,
|
|
child: Icon(Icons.event, size: 32, color: theme.hintColor),
|
|
),
|
|
);
|
|
}
|
|
if (!kIsWeb) {
|
|
final path = imageUrl;
|
|
if (path.startsWith('/') || path.contains(Platform.pathSeparator)) {
|
|
final file = File(path);
|
|
if (file.existsSync()) {
|
|
return Image.file(
|
|
file,
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => Container(
|
|
color: theme.dividerColor,
|
|
child: Icon(Icons.event, size: 32, color: theme.hintColor),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
return Image.asset(
|
|
imageUrl,
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
fit: BoxFit.cover,
|
|
errorBuilder: (_, __, ___) => Container(
|
|
color: theme.dividerColor,
|
|
child: Icon(Icons.event, size: 32, color: theme.hintColor),
|
|
),
|
|
);
|
|
}
|
|
return Container(
|
|
color: theme.dividerColor,
|
|
child: Icon(Icons.event, size: 32, color: theme.hintColor),
|
|
);
|
|
}
|
|
|
|
// ═══════════════════════════════════════════════
|
|
// BUILD
|
|
// ═══════════════════════════════════════════════
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final width = MediaQuery.of(context).size.width;
|
|
|
|
// ── DESKTOP / LANDSCAPE layout ─────────────────────────────────────────
|
|
if (width >= AppConstants.desktopBreakpoint) {
|
|
return _buildDesktopLayout(context, theme);
|
|
}
|
|
|
|
// ── MOBILE layout ─────────────────────────────────────────────────────
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFF9FAFB),
|
|
body: Consumer<GamificationProvider>(
|
|
builder: (context, gam, _) {
|
|
return CustomScrollView(
|
|
physics: const BouncingScrollPhysics(),
|
|
slivers: [
|
|
SliverToBoxAdapter(child: _buildModernHeader(context, theme)),
|
|
SliverToBoxAdapter(child: _buildModernStatCards(gam, theme)),
|
|
SliverToBoxAdapter(child: _buildTierProgressCard(gam, theme)),
|
|
SliverToBoxAdapter(child: _buildContributedEventsSection(gam, theme)),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
// PROF-003: Gamification 3-card row (Lifetime EP / Liquid EP / RP)
|
|
// ─────────────────────────────────────────────────────────────────────────
|
|
Widget _buildGamificationCards(ThemeData theme) {
|
|
return Consumer<GamificationProvider>(
|
|
builder: (context, gp, _) {
|
|
if (gp.isLoading && gp.profile == null) {
|
|
return const ProfileStatsSkeleton();
|
|
}
|
|
if (gp.profile == null) return const SizedBox.shrink();
|
|
|
|
final p = gp.profile!;
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(18, 8, 18, 8),
|
|
child: Row(
|
|
children: [
|
|
_gamStatCard('Lifetime EP', '${p.lifetimeEp}', Icons.star, const Color(0xFFF59E0B), theme),
|
|
const SizedBox(width: 10),
|
|
// GAM-003 + GAM-004: Liquid EP with cycle countdown and progress bar
|
|
Expanded(
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF3B82F6).withOpacity(0.08),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: const Color(0xFF3B82F6).withOpacity(0.2)),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
const Icon(Icons.bolt, color: Color(0xFF3B82F6), size: 22),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'${p.currentEp}',
|
|
style: TextStyle(fontWeight: FontWeight.w800, fontSize: 16, color: theme.textTheme.bodyLarge?.color),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text('Liquid EP', style: TextStyle(color: theme.hintColor, fontSize: 10), textAlign: TextAlign.center),
|
|
if (gp.currentUserStats?.rewardCycleDays != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'Converts in ${gp.currentUserStats!.rewardCycleDays}d',
|
|
style: const TextStyle(fontSize: 11, color: Color(0xFF94A3B8)),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 6),
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(4),
|
|
child: Builder(
|
|
builder: (_) {
|
|
final days = gp.currentUserStats?.rewardCycleDays ?? 30;
|
|
final elapsed = (30 - days).clamp(0, 30);
|
|
final ratio = elapsed / 30;
|
|
return LinearProgressIndicator(
|
|
value: ratio,
|
|
minHeight: 4,
|
|
backgroundColor: Colors.white12,
|
|
valueColor: AlwaysStoppedAnimation<Color>(
|
|
ratio > 0.7 ? const Color(0xFFFBBF24) : const Color(0xFF3B82F6),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
_gamStatCard('Reward Pts', '${p.currentRp}', Icons.redeem, const Color(0xFF10B981), theme),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _gamStatCard(String label, String value, IconData icon, Color color, ThemeData theme) {
|
|
return Expanded(
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
|
decoration: BoxDecoration(
|
|
color: color.withOpacity(0.08),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: color.withOpacity(0.2)),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Icon(icon, color: color, size: 22),
|
|
const SizedBox(height: 4),
|
|
Text(value, style: TextStyle(fontWeight: FontWeight.w800, fontSize: 16, color: theme.textTheme.bodyLarge?.color)),
|
|
const SizedBox(height: 2),
|
|
Text(label, style: TextStyle(color: theme.hintColor, fontSize: 10), textAlign: TextAlign.center),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|