Initial commit: Eventify frontend
This commit is contained in:
382
lib/screens/booking_screen.dart
Normal file
382
lib/screens/booking_screen.dart
Normal file
@@ -0,0 +1,382 @@
|
||||
// lib/screens/booking_screen.dart
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BookingScreen extends StatefulWidget {
|
||||
// Keep onBook in the constructor if you want to use it later, but we won't call it here.
|
||||
final VoidCallback? onBook;
|
||||
final String image;
|
||||
|
||||
const BookingScreen({
|
||||
Key? key,
|
||||
this.onBook,
|
||||
this.image = 'assets/images/event1.jpg',
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<BookingScreen> createState() => _BookingScreenState();
|
||||
}
|
||||
|
||||
class _BookingScreenState extends State<BookingScreen> {
|
||||
// small gallery placeholder
|
||||
final List<String> gallery = [
|
||||
'assets/images/event1.jpg',
|
||||
'assets/images/event2.jpg',
|
||||
'assets/images/event3.jpeg',
|
||||
'assets/images/event1.jpg',
|
||||
];
|
||||
|
||||
// long about text
|
||||
final String aboutText = '''
|
||||
Some voices don't just sing, they awaken something deep within. Sid Sriram is one of those rare artists who doesn't just perform music... he becomes it.
|
||||
|
||||
This concert isn't just about a setlist or a stage, it's a journey. A moment suspended in time. A powerful collective experience where every note pulls at memory, every silence says what words never could, and every crescendo feels like it was meant just for you.
|
||||
|
||||
From the moment the lights go down, you're no longer in the real world — you're in his world: a place shaped by melody and intimacy, where familiar songs are reborn and new ones carve out space in your memory. Expect an award-calibre voice that melts into orchestration, fragile acoustic passages that make the room hold its breath, and thunderous climaxes that lift everyone to their feet.
|
||||
|
||||
Whether you're a longtime fan or hearing him live for the first time, this evening promises to linger long after the last chord fades — a night of shared emotion, artistry, and music that stays with you.
|
||||
''';
|
||||
|
||||
bool _booked = false;
|
||||
|
||||
void _performLocalBooking() {
|
||||
// mark locally booked (do NOT call widget.onBook())
|
||||
if (!_booked) {
|
||||
setState(() => _booked = true);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Tickets booked (demo)')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _openLearnMoreSheet() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (ctx) {
|
||||
return DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.78,
|
||||
minChildSize: 0.35,
|
||||
maxChildSize: 0.95,
|
||||
builder: (context, scrollController) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24.0)),
|
||||
boxShadow: [BoxShadow(color: Colors.black26, blurRadius: 8)],
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
controller: scrollController,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 18, 20, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// drag handle
|
||||
Center(
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 6,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
|
||||
Text(
|
||||
"The Homecoming Tour | Sid Sriram Live in Concert",
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.calendar_today, size: 16, color: Colors.blue),
|
||||
SizedBox(width: 8),
|
||||
Text("22 Jan - 24 Jan, 2025", style: TextStyle(color: Colors.black54)),
|
||||
SizedBox(width: 14),
|
||||
Icon(Icons.access_time, size: 16, color: Colors.blue),
|
||||
SizedBox(width: 8),
|
||||
Text("04:00 PM - 11:00 PM", style: TextStyle(color: Colors.black54)),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 14),
|
||||
|
||||
Container(
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[200],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(child: Text('Map placeholder — Cultural Hall', style: TextStyle(color: Colors.black45))),
|
||||
),
|
||||
SizedBox(height: 18),
|
||||
|
||||
Text('About the Event', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 8),
|
||||
Text(aboutText, style: TextStyle(color: Colors.black54, height: 1.45)),
|
||||
SizedBox(height: 18),
|
||||
|
||||
Text('Gallery', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 12),
|
||||
SizedBox(
|
||||
height: 78,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: gallery.length,
|
||||
separatorBuilder: (_, __) => SizedBox(width: 12),
|
||||
itemBuilder: (context, idx) {
|
||||
final path = gallery[idx];
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: 78,
|
||||
height: 78,
|
||||
color: Colors.grey[200],
|
||||
child: Image.asset(
|
||||
path,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (ctx, err, st) => Center(child: Icon(Icons.image, color: Colors.grey)),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 22),
|
||||
|
||||
// If already booked, show booked UI inside the sheet too (optional)
|
||||
if (_booked) ...[
|
||||
_bookedRow(),
|
||||
SizedBox(height: 12),
|
||||
] else ...[
|
||||
// Book button inside sheet — now does in-place booking (no navigation)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
backgroundColor: Color(0xFF0B63D6),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
onPressed: () {
|
||||
// mark booked and close the sheet (no removal from home)
|
||||
_performLocalBooking();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text('Book Your Spot', style: TextStyle(fontSize: 16, color: Colors.white)),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
SizedBox(height: 12),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// row shown after booking: left green pill + three action icons on right
|
||||
Widget _bookedRow() {
|
||||
final Color primary = Color(0xFF0B63D6);
|
||||
return Row(
|
||||
children: [
|
||||
// Tickets Booked pill (left)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFDFF5DF), // light green background
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text('Tickets Booked', style: TextStyle(color: Color(0xFF2E7D32), fontWeight: FontWeight.bold)),
|
||||
),
|
||||
|
||||
Spacer(),
|
||||
|
||||
// action icons (scanner / chat / call)
|
||||
_iconSquare(primary, Icons.qr_code_scanner, onTap: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Scanner tapped (demo)')));
|
||||
}),
|
||||
SizedBox(width: 12),
|
||||
_iconSquare(primary, Icons.chat, onTap: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Chat tapped (demo)')));
|
||||
}),
|
||||
SizedBox(width: 12),
|
||||
_iconSquare(primary, Icons.call, onTap: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Call tapped (demo)')));
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _iconSquare(Color bg, IconData icon, {required VoidCallback onTap}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 4))],
|
||||
),
|
||||
child: Icon(icon, color: Colors.white, size: 24),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _confirmBookingFromMain() {
|
||||
// book in-place (no navigation and no removal from home)
|
||||
_performLocalBooking();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// full-bleed image behind status bar
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
children: [
|
||||
// full background image
|
||||
Positioned.fill(
|
||||
child: Image.asset(
|
||||
widget.image,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (ctx, err, st) => Container(color: Colors.grey[900]),
|
||||
),
|
||||
),
|
||||
|
||||
// subtle gradient to make bottom white text readable
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.transparent, Colors.black87],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
stops: [0.45, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// top safe area controls
|
||||
SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_smallRoundedButton(icon: Icons.arrow_back, onTap: () => Navigator.pop(context)),
|
||||
_smallRoundedButton(icon: Icons.favorite_border, onTap: () {}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// bottom anchored overlay: title, details, either book button or booked row, learn more
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: SafeArea(
|
||||
bottom: true,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 16),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Title & details
|
||||
Container(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'The Homecoming Tour | Sid Sriram Live in Concert',
|
||||
style: TextStyle(color: Colors.white, fontSize: 22, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.calendar_today, size: 16, color: Colors.white70),
|
||||
SizedBox(width: 8),
|
||||
Text('22 Jan - 24 Jan', style: TextStyle(color: Colors.white70)),
|
||||
SizedBox(width: 12),
|
||||
Icon(Icons.location_on, size: 16, color: Colors.white70),
|
||||
SizedBox(width: 8),
|
||||
Expanded(child: Text('Cultural Hall, Brookefield', style: TextStyle(color: Colors.white70))),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 16),
|
||||
|
||||
// If booked: show green pill + icons in-place.
|
||||
// Otherwise show the large Book button.
|
||||
if (_booked) ...[
|
||||
_bookedRow(),
|
||||
SizedBox(height: 12),
|
||||
] else ...[
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _confirmBookingFromMain,
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
backgroundColor: Color(0xFF0B63D6),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
child: Text('Book Your Spot', style: TextStyle(fontSize: 16, color: Colors.white)),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
],
|
||||
|
||||
// Learn more handle (tappable)
|
||||
GestureDetector(
|
||||
onTap: _openLearnMoreSheet,
|
||||
child: Column(
|
||||
children: [
|
||||
Text('Learn More', style: TextStyle(color: Colors.white70)),
|
||||
SizedBox(height: 6),
|
||||
Icon(Icons.keyboard_double_arrow_up, color: Colors.white70),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _smallRoundedButton({required IconData icon, required VoidCallback onTap}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(12)),
|
||||
child: Icon(icon, color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
732
lib/screens/calendar_screen.dart
Normal file
732
lib/screens/calendar_screen.dart
Normal file
@@ -0,0 +1,732 @@
|
||||
// lib/screens/calendar_screen.dart
|
||||
import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../features/events/services/events_service.dart';
|
||||
import '../features/events/models/event_models.dart';
|
||||
import 'learn_more_screen.dart';
|
||||
import '../core/app_decoration.dart';
|
||||
|
||||
class CalendarScreen extends StatefulWidget {
|
||||
const CalendarScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<CalendarScreen> createState() => _CalendarScreenState();
|
||||
}
|
||||
|
||||
class _CalendarScreenState extends State<CalendarScreen> {
|
||||
DateTime visibleMonth = DateTime.now();
|
||||
DateTime selectedDate = DateTime.now();
|
||||
|
||||
final EventsService _service = EventsService();
|
||||
|
||||
bool _loadingMonth = true;
|
||||
bool _loadingDay = false;
|
||||
|
||||
final Set<String> _markedDates = {};
|
||||
final Map<String, int> _dateCounts = {};
|
||||
final Map<String, List<String>> _dateThumbnails = {};
|
||||
|
||||
List<EventModel> _eventsOfDay = [];
|
||||
|
||||
// Scroll controller for the calendar grid
|
||||
final ScrollController _calendarGridController = ScrollController();
|
||||
|
||||
static const List<String> monthNames = [
|
||||
'',
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December'
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadMonth(visibleMonth);
|
||||
selectedDate = DateTime.now();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _onSelectDate(_ymKey(selectedDate)));
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_calendarGridController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadMonth(DateTime dt) async {
|
||||
setState(() {
|
||||
_loadingMonth = true;
|
||||
_markedDates.clear();
|
||||
_dateCounts.clear();
|
||||
_dateThumbnails.clear();
|
||||
_eventsOfDay = [];
|
||||
});
|
||||
|
||||
final monthName = DateFormat.MMMM().format(dt);
|
||||
final year = dt.year;
|
||||
|
||||
try {
|
||||
final res = await _service.getEventsByMonthYear(monthName, year);
|
||||
final datesRaw = res['dates'];
|
||||
if (datesRaw is List) {
|
||||
for (final d in datesRaw) {
|
||||
if (d is String) _markedDates.add(d);
|
||||
}
|
||||
}
|
||||
final dateEvents = res['date_events'];
|
||||
if (dateEvents is List) {
|
||||
for (final item in dateEvents) {
|
||||
if (item is Map) {
|
||||
final k = item['date_of_event']?.toString();
|
||||
final cnt = item['events_of_date'];
|
||||
if (k != null) {
|
||||
_dateCounts[k] = (cnt is int) ? cnt : int.tryParse(cnt?.toString() ?? '0') ?? 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_markedDates.isNotEmpty) {
|
||||
await _fetchThumbnailsForDates(_markedDates.toList());
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
} finally {
|
||||
if (mounted) setState(() => _loadingMonth = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchThumbnailsForDates(List<String> dates) async {
|
||||
for (final date in dates) {
|
||||
try {
|
||||
final events = await _service.getEventsForDate(date);
|
||||
final thumbs = <String>[];
|
||||
for (final e in events) {
|
||||
String? url;
|
||||
if (e.thumbImg != null && e.thumbImg!.trim().isNotEmpty) {
|
||||
url = e.thumbImg!.trim();
|
||||
} else if (e.images.isNotEmpty && e.images.first.image.trim().isNotEmpty) {
|
||||
url = e.images.first.image.trim();
|
||||
}
|
||||
if (url != null && url.isNotEmpty) thumbs.add(url);
|
||||
if (thumbs.length >= 3) break;
|
||||
}
|
||||
if (thumbs.isNotEmpty) {
|
||||
if (mounted) {
|
||||
setState(() => _dateThumbnails[date] = thumbs);
|
||||
} else {
|
||||
_dateThumbnails[date] = thumbs;
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore per-date errors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onSelectDate(String yyyyMMdd) async {
|
||||
setState(() {
|
||||
_loadingDay = true;
|
||||
_eventsOfDay = [];
|
||||
final parts = yyyyMMdd.split('-');
|
||||
if (parts.length == 3) {
|
||||
final y = int.tryParse(parts[0]) ?? DateTime.now().year;
|
||||
final m = int.tryParse(parts[1]) ?? DateTime.now().month;
|
||||
final d = int.tryParse(parts[2]) ?? DateTime.now().day;
|
||||
selectedDate = DateTime(y, m, d);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
final events = await _service.getEventsForDate(yyyyMMdd);
|
||||
if (mounted) setState(() => _eventsOfDay = events);
|
||||
} catch (e) {
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
} finally {
|
||||
if (mounted) setState(() => _loadingDay = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _prevMonth() {
|
||||
setState(() => visibleMonth = DateTime(visibleMonth.year, visibleMonth.month - 1, 1));
|
||||
_loadMonth(visibleMonth);
|
||||
}
|
||||
|
||||
void _nextMonth() {
|
||||
setState(() => visibleMonth = DateTime(visibleMonth.year, visibleMonth.month + 1, 1));
|
||||
_loadMonth(visibleMonth);
|
||||
}
|
||||
|
||||
int _daysInMonth(DateTime d) {
|
||||
final next = (d.month == 12) ? DateTime(d.year + 1, 1, 1) : DateTime(d.year, d.month + 1, 1);
|
||||
return next.subtract(const Duration(days: 1)).day;
|
||||
}
|
||||
|
||||
int _firstWeekdayOfMonth(DateTime d) {
|
||||
final first = DateTime(d.year, d.month, 1);
|
||||
return first.weekday; // 1=Mon ... 7=Sun
|
||||
}
|
||||
|
||||
String _ymKey(DateTime d) =>
|
||||
'${d.year.toString().padLeft(4, "0")}-${d.month.toString().padLeft(2, "0")}-${d.day.toString().padLeft(2, "0")}';
|
||||
|
||||
// show a premium modal sheet with years 2020..2050 in a 3-column grid, scrollable & draggable
|
||||
Future<void> _showYearPicker(BuildContext context) async {
|
||||
final startYear = 2020;
|
||||
final endYear = 2050;
|
||||
final years = List<int>.generate(endYear - startYear + 1, (i) => startYear + i);
|
||||
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (ctx) {
|
||||
final theme = Theme.of(ctx);
|
||||
return DraggableScrollableSheet(
|
||||
initialChildSize: 0.55,
|
||||
minChildSize: 0.32,
|
||||
maxChildSize: 0.95,
|
||||
expand: false,
|
||||
builder: (context, scrollController) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 18),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.cardColor,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: Colors.black26, blurRadius: 20, offset: Offset(0, 8))],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// header
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6.0, vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 4),
|
||||
Expanded(child: Text('Select Year', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w700))),
|
||||
IconButton(
|
||||
icon: Icon(Icons.close, color: theme.hintColor),
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// grid (scrollable using the passed scrollController)
|
||||
Expanded(
|
||||
child: GridView.builder(
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 3, // 3 columns -> premium style
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
childAspectRatio: 2.4,
|
||||
),
|
||||
itemCount: years.length,
|
||||
itemBuilder: (context, index) {
|
||||
final y = years[index];
|
||||
final isSelected = visibleMonth.year == y;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
visibleMonth = DateTime(y, visibleMonth.month, 1);
|
||||
});
|
||||
_loadMonth(visibleMonth);
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? theme.colorScheme.primary.withOpacity(0.12) : null,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: isSelected ? Border.all(color: theme.colorScheme.primary, width: 1.6) : Border.all(color: Colors.transparent),
|
||||
boxShadow: isSelected ? [BoxShadow(color: theme.colorScheme.primary.withOpacity(0.06), blurRadius: 10, offset: Offset(0, 4))] : null,
|
||||
),
|
||||
child: Text(
|
||||
'$y',
|
||||
style: theme.textTheme.bodyLarge?.copyWith(
|
||||
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w600,
|
||||
color: isSelected ? theme.colorScheme.primary : theme.textTheme.bodyLarge?.color,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMonthYearHeader(BuildContext context, Color primaryColor) {
|
||||
final theme = Theme.of(context);
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(icon: Icon(Icons.chevron_left, color: primaryColor), onPressed: _prevMonth, splashRadius: 20),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// plain month label (no dropdown)
|
||||
Text(
|
||||
monthNames[visibleMonth.month],
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
// year "dropdown" replaced with premium modal trigger
|
||||
InkWell(
|
||||
onTap: () => _showYearPicker(context),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'${visibleMonth.year}',
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Icon(Icons.arrow_drop_down, size: 22, color: theme.textTheme.bodyLarge?.color),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(icon: Icon(Icons.chevron_right, color: primaryColor), onPressed: _nextMonth, splashRadius: 20),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Calendar card that shows full rows (including overflow prev/next month dates).
|
||||
Widget _calendarCard(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final primaryColor = theme.colorScheme.primary;
|
||||
final weekdayShorts = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
|
||||
|
||||
// compute rows to guarantee rows * 7 cells
|
||||
final daysInMonth = _daysInMonth(visibleMonth);
|
||||
final firstWeekday = _firstWeekdayOfMonth(visibleMonth);
|
||||
final leadingEmpty = firstWeekday - 1;
|
||||
final totalCells = leadingEmpty + daysInMonth;
|
||||
final rows = (totalCells / 7).ceil();
|
||||
final totalItems = rows * 7;
|
||||
|
||||
// first date shown (may be prev month's date)
|
||||
final firstCellDate = DateTime(visibleMonth.year, visibleMonth.month, 1).subtract(Duration(days: leadingEmpty));
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: Card(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
elevation: 8,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14.0, vertical: 12.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min, // tightly wrap grid
|
||||
children: [
|
||||
// month/year header
|
||||
SizedBox(height: 48, child: _buildMonthYearHeader(context, primaryColor)),
|
||||
const SizedBox(height: 6),
|
||||
// weekday labels row
|
||||
SizedBox(
|
||||
height: 22,
|
||||
child: Row(
|
||||
children: List.generate(7, (i) {
|
||||
final isWeekend = (i == 5 || i == 6);
|
||||
return Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
weekdayShorts[i],
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: isWeekend ? Colors.redAccent.withOpacity(0.9) : (Theme.of(context).brightness == Brightness.dark ? Colors.white70 : Colors.black54),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// GRID: shrinkWrap true ensures all rows are rendered
|
||||
GridView.builder(
|
||||
shrinkWrap: true,
|
||||
controller: _calendarGridController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: totalItems,
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 7,
|
||||
mainAxisSpacing: 8,
|
||||
crossAxisSpacing: 8,
|
||||
childAspectRatio: 1,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final cellDate = firstCellDate.add(Duration(days: index));
|
||||
final inCurrentMonth = cellDate.month == visibleMonth.month && cellDate.year == visibleMonth.year;
|
||||
final dayIndex = cellDate.day;
|
||||
final key = _ymKey(cellDate);
|
||||
final hasEvents = _markedDates.contains(key);
|
||||
final thumbnails = _dateThumbnails[key] ?? [];
|
||||
final isSelected = selectedDate.year == cellDate.year && selectedDate.month == cellDate.month && selectedDate.day == cellDate.day;
|
||||
|
||||
final dayTextColor = inCurrentMonth
|
||||
? (Theme.of(context).brightness == Brightness.dark ? Colors.white : Colors.black87)
|
||||
: (Theme.of(context).brightness == Brightness.dark ? Colors.white38 : Colors.grey.shade400);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (!inCurrentMonth) {
|
||||
setState(() => visibleMonth = DateTime(cellDate.year, cellDate.month, 1));
|
||||
_loadMonth(visibleMonth);
|
||||
}
|
||||
_onSelectDate(key);
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// rounded date cell
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? primaryColor.withOpacity(0.14) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'$dayIndex',
|
||||
style: TextStyle(
|
||||
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w600,
|
||||
color: isSelected ? primaryColor : dayTextColor,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
// small event indicators (thumbnail overlap or dot)
|
||||
if (hasEvents && thumbnails.isNotEmpty)
|
||||
SizedBox(
|
||||
height: 14,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: thumbnails.take(2).toList().asMap().entries.map((entry) {
|
||||
final i = entry.key;
|
||||
final url = entry.value;
|
||||
return Transform.translate(
|
||||
offset: Offset(i * -6.0, 0),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(left: 4),
|
||||
width: 14,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(shape: BoxShape.circle, border: Border.all(color: Theme.of(context).cardColor, width: 1.0)),
|
||||
child: ClipOval(child: Image.network(url, fit: BoxFit.cover, errorBuilder: (_, __, ___) => Container(color: Theme.of(context).dividerColor))),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
)
|
||||
else if (hasEvents)
|
||||
Container(width: 18, height: 6, decoration: BoxDecoration(color: primaryColor, borderRadius: BorderRadius.circular(6)))
|
||||
else
|
||||
const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Selected-date summary (now guaranteed outside and below the calendar card)
|
||||
Widget _selectedDateSummary(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final shortWeekday = DateFormat('EEEE').format(selectedDate);
|
||||
final shortDate = DateFormat('d MMMM, yyyy').format(selectedDate);
|
||||
final dayNumber = selectedDate.day;
|
||||
final monthLabel = DateFormat('MMM').format(selectedDate).toUpperCase();
|
||||
final eventsCount = _eventsOfDay.length;
|
||||
final primaryColor = theme.colorScheme.primary;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 8),
|
||||
child: Card(
|
||||
elevation: 6,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(color: primaryColor.withOpacity(0.12), borderRadius: BorderRadius.circular(10)),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('$dayNumber', style: theme.textTheme.headlineSmall?.copyWith(color: primaryColor, fontWeight: FontWeight.bold, fontSize: 18)),
|
||||
const SizedBox(height: 2),
|
||||
Text(monthLabel, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor, fontSize: 11, fontWeight: FontWeight.w700)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(shortWeekday, style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600, fontSize: 14)),
|
||||
const SizedBox(height: 2),
|
||||
Text(shortDate, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor, fontSize: 12)),
|
||||
]),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text('$eventsCount', style: theme.textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.bold, color: primaryColor, fontSize: 16)),
|
||||
const SizedBox(height: 2),
|
||||
Text(eventsCount == 1 ? 'Event' : 'Events', style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Mobile event card (kept unchanged)
|
||||
Widget _eventCardMobile(EventModel e) {
|
||||
final theme = Theme.of(context);
|
||||
final imgUrl = (e.thumbImg != null && e.thumbImg!.isNotEmpty) ? e.thumbImg! : (e.images.isNotEmpty ? e.images.first.image : null);
|
||||
final dateLabel = (e.startDate != null && e.endDate != null && e.startDate == e.endDate)
|
||||
? '${e.startDate}'
|
||||
: (e.startDate != null && e.endDate != null ? '${e.startDate} - ${e.endDate}' : (e.startDate ?? ''));
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (_) => LearnMoreScreen(eventId: e.id))),
|
||||
child: Card(
|
||||
elevation: 6,
|
||||
margin: const EdgeInsets.fromLTRB(20, 10, 20, 10),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(14)),
|
||||
child: imgUrl != null ? Image.network(imgUrl, height: 150, width: double.infinity, fit: BoxFit.cover, errorBuilder: (_, __, ___) => Container(height: 150, color: theme.dividerColor)) : Container(height: 150, color: theme.dividerColor, child: Icon(Icons.event, size: 44, color: theme.hintColor)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 14),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(e.title ?? e.name ?? '', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold), maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
const SizedBox(height: 10),
|
||||
Row(children: [
|
||||
Container(width: 26, height: 26, decoration: BoxDecoration(color: theme.colorScheme.primary.withOpacity(0.12), borderRadius: BorderRadius.circular(6)), child: Icon(Icons.calendar_today, size: 14, color: theme.colorScheme.primary)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(dateLabel, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor))),
|
||||
]),
|
||||
const SizedBox(height: 8),
|
||||
Row(children: [
|
||||
Container(width: 26, height: 26, decoration: BoxDecoration(color: theme.colorScheme.primary.withOpacity(0.12), borderRadius: BorderRadius.circular(6)), child: Icon(Icons.location_on, size: 14, color: theme.colorScheme.primary)),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(e.place ?? '', style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor))),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
final isMobile = width < 700;
|
||||
final theme = Theme.of(context);
|
||||
|
||||
// For non-mobile, keep original split layout
|
||||
if (!isMobile) {
|
||||
return Scaffold(
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
body: SafeArea(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(flex: 3, child: Padding(padding: const EdgeInsets.all(24.0), child: _calendarCard(context))),
|
||||
Expanded(flex: 1, child: _detailsPanel()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// MOBILE layout
|
||||
// Stack: extended gradient panel (below appbar) that visually extends behind the calendar.
|
||||
return Scaffold(
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
body: Stack(
|
||||
children: [
|
||||
// Extended blue gradient panel behind calendar (matches reference)
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
height: 260, // controls how much gradient shows behind calendar
|
||||
decoration: AppDecoration.blueGradient.copyWith(
|
||||
borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(30), bottomRight: Radius.circular(30)),
|
||||
boxShadow: [const BoxShadow(color: Colors.black12, blurRadius: 12, offset: Offset(0, 6))],
|
||||
),
|
||||
// leave child empty — title and bell are placed above
|
||||
child: const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
|
||||
// TOP APP BAR (title centered + notification at top-right) - unchanged placement
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: SizedBox(
|
||||
height: 56, // app bar height
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// centered title
|
||||
Text(
|
||||
"Event's Calendar",
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
|
||||
// notification icon at absolute top-right
|
||||
Positioned(
|
||||
right: 0,
|
||||
child: InkWell(
|
||||
onTap: () => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Notifications (demo)'))),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white24,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(Icons.notifications_none, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// CONTENT: calendar card overlapped on gradient, then summary and list
|
||||
Column(
|
||||
children: [
|
||||
const SizedBox(height: 110), // leave space for appbar + some gradient top
|
||||
_calendarCard(context), // calendar card sits visually on top of the gradient
|
||||
_selectedDateSummary(context),
|
||||
Expanded(
|
||||
child: _loadingDay
|
||||
? Center(child: CircularProgressIndicator(color: theme.colorScheme.primary))
|
||||
: _eventsOfDay.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.event_available, size: 48, color: theme.hintColor),
|
||||
const SizedBox(height: 10),
|
||||
Text('No events scheduled for this date', style: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 6, bottom: 32),
|
||||
itemCount: _eventsOfDay.length,
|
||||
itemBuilder: (context, idx) => _eventCardMobile(_eventsOfDay[idx]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _detailsPanel() {
|
||||
final theme = Theme.of(context);
|
||||
final shortDate = DateFormat('EEE, d MMM').format(selectedDate);
|
||||
final eventsCount = _eventsOfDay.length;
|
||||
|
||||
Widget _buildHeaderCompact() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 12.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: AppDecoration.blueGradientRounded(10),
|
||||
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [Text('${selectedDate.day}', style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold)), const SizedBox(height: 2), Text(monthNames[selectedDate.month].substring(0, 3), style: const TextStyle(color: Colors.white70, fontSize: 10))]),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [Text(shortDate, style: Theme.of(context).textTheme.bodyLarge?.copyWith(fontWeight: FontWeight.w600)), const SizedBox(height: 4), Text('$eventsCount ${eventsCount == 1 ? "Event" : "Events"}', style: Theme.of(context).textTheme.bodySmall?.copyWith(color: Theme.of(context).hintColor))]),
|
||||
const Spacer(),
|
||||
IconButton(onPressed: () {}, icon: Icon(Icons.more_horiz, color: Theme.of(context).iconTheme.color)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
_buildHeaderCompact(),
|
||||
Divider(height: 1, color: theme.dividerColor),
|
||||
Expanded(
|
||||
child: _loadingDay
|
||||
? Center(child: CircularProgressIndicator(color: theme.colorScheme.primary))
|
||||
: _eventsOfDay.isEmpty
|
||||
? const SizedBox.shrink()
|
||||
: ListView.builder(padding: const EdgeInsets.only(top: 6, bottom: 24), itemCount: _eventsOfDay.length, itemBuilder: (context, idx) => _eventCardMobile(_eventsOfDay[idx])),
|
||||
)
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
556
lib/screens/contribute_screen.dart
Normal file
556
lib/screens/contribute_screen.dart
Normal file
@@ -0,0 +1,556 @@
|
||||
// lib/screens/contribute_screen.dart
|
||||
import 'dart:io';
|
||||
import '../core/app_decoration.dart';
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class ContributeScreen extends StatefulWidget {
|
||||
const ContributeScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ContributeScreen> createState() => _ContributeScreenState();
|
||||
}
|
||||
|
||||
class _ContributeScreenState extends State<ContributeScreen> with SingleTickerProviderStateMixin {
|
||||
// Primary accent used for buttons / active tab (kept as a single constant)
|
||||
static const Color _primary = Color(0xFF0B63D6);
|
||||
|
||||
// single corner radius to use everywhere
|
||||
static const double _cornerRadius = 18.0;
|
||||
|
||||
// Form controllers
|
||||
final TextEditingController _titleCtl = TextEditingController();
|
||||
final TextEditingController _locationCtl = TextEditingController();
|
||||
final TextEditingController _organizerCtl = TextEditingController();
|
||||
final TextEditingController _descriptionCtl = TextEditingController();
|
||||
DateTime? _selectedDate;
|
||||
String _selectedCategory = 'Music';
|
||||
|
||||
// Image pickers
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
XFile? _coverImageFile;
|
||||
XFile? _thumbImageFile;
|
||||
|
||||
bool _submitting = false;
|
||||
|
||||
// Tab state: 0 = Contribute, 1 = Leaderboard, 2 = Achievements
|
||||
int _activeTab = 0;
|
||||
|
||||
// Example progress value (0..1)
|
||||
double _progress = 0.45;
|
||||
|
||||
// A few category options
|
||||
final List<String> _categories = ['Music', 'Food', 'Arts', 'Sports', 'Tech', 'Community'];
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_titleCtl.dispose();
|
||||
_locationCtl.dispose();
|
||||
_organizerCtl.dispose();
|
||||
_descriptionCtl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _pickCoverImage() async {
|
||||
try {
|
||||
final XFile? picked = await _picker.pickImage(source: ImageSource.gallery, imageQuality: 85);
|
||||
if (picked != null) setState(() => _coverImageFile = picked);
|
||||
} catch (e) {
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Failed to pick image: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickThumbnailImage() async {
|
||||
try {
|
||||
final XFile? picked = await _picker.pickImage(source: ImageSource.gallery, imageQuality: 85);
|
||||
if (picked != null) setState(() => _thumbImageFile = picked);
|
||||
} catch (e) {
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Failed to pick image: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickDate() async {
|
||||
final now = DateTime.now();
|
||||
final picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedDate ?? now,
|
||||
firstDate: DateTime(now.year - 2),
|
||||
lastDate: DateTime(now.year + 3),
|
||||
builder: (context, child) {
|
||||
return Theme(
|
||||
data: Theme.of(context).copyWith(colorScheme: ColorScheme.light(primary: _primary)),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
);
|
||||
if (picked != null) setState(() => _selectedDate = picked);
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
if (_titleCtl.text.trim().isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Please enter an event title')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _submitting = true);
|
||||
// simulate work
|
||||
await Future.delayed(const Duration(milliseconds: 800));
|
||||
|
||||
setState(() => _submitting = false);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Submitted for verification (demo)')));
|
||||
_clearForm();
|
||||
}
|
||||
}
|
||||
|
||||
void _clearForm() {
|
||||
_titleCtl.clear();
|
||||
_locationCtl.clear();
|
||||
_organizerCtl.clear();
|
||||
_descriptionCtl.clear();
|
||||
_selectedDate = null;
|
||||
_selectedCategory = _categories.first;
|
||||
_coverImageFile = null;
|
||||
_thumbImageFile = null;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
// ---------- UI Builders ----------
|
||||
|
||||
Widget _buildHeader(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
// header uses AppDecoration.blueGradient for background (project-specific)
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.fromLTRB(20, 32, 20, 24),
|
||||
decoration: AppDecoration.blueGradient.copyWith(
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(_cornerRadius),
|
||||
bottomRight: Radius.circular(_cornerRadius),
|
||||
),
|
||||
// subtle shadow only
|
||||
boxShadow: [
|
||||
BoxShadow(color: Colors.black.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 4)),
|
||||
],
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
children: [
|
||||
// increased spacing to create a breathable layout
|
||||
const SizedBox(height: 6),
|
||||
|
||||
// Title & subtitle (centered) — smaller title weight, clearer hierarchy
|
||||
Text(
|
||||
'Contributor Dashboard',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12), // more space between title & subtitle
|
||||
Text(
|
||||
'Track your impact, earn rewards, and climb the ranks!',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(color: Colors.white.withOpacity(0.92), fontSize: 13, height: 1.35),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20), // more space before tabs
|
||||
|
||||
// Pill-style segmented tabs (animated active) — slimmer / minimal
|
||||
_buildSegmentedTabs(context),
|
||||
|
||||
const SizedBox(height: 18), // comfortable spacing before contributor card
|
||||
|
||||
// Contributor level card — lighter, soft border, thinner progress
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(14),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.08), // slightly lighter than before
|
||||
borderRadius: BorderRadius.circular(_cornerRadius - 2),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.09)), // soft border
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Contributor Level',
|
||||
style: theme.textTheme.titleSmall?.copyWith(color: Colors.white, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 8),
|
||||
Text('Start earning rewards by contributing!', style: theme.textTheme.bodySmall?.copyWith(color: Colors.white70)),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
// animated progress using TweenAnimationBuilder
|
||||
child: TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0.0, end: _progress),
|
||||
duration: const Duration(milliseconds: 700),
|
||||
builder: (context, value, _) => ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: LinearProgressIndicator(
|
||||
value: value,
|
||||
minHeight: 6, // thinner progress bar
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
backgroundColor: Colors.white24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text('Explorer', style: theme.textTheme.bodySmall?.copyWith(color: Colors.white, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('30 pts', style: theme.textTheme.bodyMedium?.copyWith(color: Colors.white, fontWeight: FontWeight.w600)),
|
||||
Text('Next: Enthusiast (50 pts)', style: theme.textTheme.bodyMedium?.copyWith(color: Colors.white70)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSegmentedTabs(BuildContext context) {
|
||||
final tabs = ['Contribute', 'Leaderboard', 'Achievements'];
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.06),
|
||||
borderRadius: BorderRadius.circular(_cornerRadius + 6),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.10)),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 8, offset: const Offset(0, 6))],
|
||||
),
|
||||
child: Row(
|
||||
children: List.generate(tabs.length, (i) {
|
||||
final active = i == _activeTab;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() => _activeTab = i),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 220),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 10),
|
||||
margin: EdgeInsets.only(right: i == tabs.length - 1 ? 0 : 8),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? Colors.white : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(_cornerRadius - 4),
|
||||
boxShadow: active ? [BoxShadow(color: Colors.black.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 4))] : null,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// show a small icon only for active tab
|
||||
if (active) ...[
|
||||
Icon(Icons.edit, size: 14, color: _primary),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
// FittedBox ensures the whole word is visible (scales down if necessary)
|
||||
Flexible(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
tabs[i],
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: active ? _primary : Colors.white.withOpacity(0.95),
|
||||
fontWeight: active ? FontWeight.w800 : FontWeight.w600,
|
||||
fontSize: 16, // preferred size; FittedBox will shrink if needed
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Widget _buildForm(BuildContext ctx) {
|
||||
final theme = Theme.of(ctx);
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(top: 18),
|
||||
padding: const EdgeInsets.fromLTRB(18, 20, 18, 28),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.scaffoldBackgroundColor,
|
||||
borderRadius: BorderRadius.circular(_cornerRadius),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.03), blurRadius: 12, offset: const Offset(0, 6))],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// sheet title
|
||||
Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text('Contribute an Event', style: theme.textTheme.headlineSmall?.copyWith(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 8),
|
||||
Text('Share local events. Earn points for every verified submission!',
|
||||
textAlign: TextAlign.center, style: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 18),
|
||||
|
||||
// small helper button
|
||||
Center(
|
||||
child: OutlinedButton(
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Want to edit an existing event? (demo)')));
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: BorderSide(color: Colors.grey.shade300),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(_cornerRadius - 6)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
|
||||
),
|
||||
child: const Text('Want to edit an existing event?'),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 18),
|
||||
|
||||
// Event Title
|
||||
Text('Event Title', style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: 8),
|
||||
_roundedTextField(controller: _titleCtl, hint: 'e.g. Local Food Festival'),
|
||||
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Category
|
||||
Text('Category', style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(color: theme.cardColor, borderRadius: BorderRadius.circular(_cornerRadius - 8)),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: _selectedCategory,
|
||||
isExpanded: true,
|
||||
items: _categories.map((c) => DropdownMenuItem(value: c, child: Text(c))).toList(),
|
||||
onChanged: (v) => setState(() => _selectedCategory = v ?? _selectedCategory),
|
||||
icon: const Icon(Icons.keyboard_arrow_down),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Date
|
||||
Text('Date', style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: _pickDate,
|
||||
child: Container(
|
||||
height: 48,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
alignment: Alignment.centerLeft,
|
||||
decoration: BoxDecoration(color: theme.cardColor, borderRadius: BorderRadius.circular(_cornerRadius - 8)),
|
||||
child: Text(_selectedDate == null ? 'Select date' : '${_selectedDate!.day}/${_selectedDate!.month}/${_selectedDate!.year}', style: theme.textTheme.bodyMedium),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Location
|
||||
Text('Location', style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: 8),
|
||||
_roundedTextField(controller: _locationCtl, hint: 'e.g. City Park, Calicut'),
|
||||
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Organizer
|
||||
Text('Organizer Name', style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: 8),
|
||||
_roundedTextField(controller: _organizerCtl, hint: 'Individual or Organization Name'),
|
||||
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Description
|
||||
Text('Description', style: theme.textTheme.labelLarge),
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _descriptionCtl,
|
||||
minLines: 4,
|
||||
maxLines: 6,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Tell us more about the event...',
|
||||
filled: true,
|
||||
fillColor: theme.cardColor,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(_cornerRadius - 8), borderSide: BorderSide.none),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 18),
|
||||
|
||||
// Event Images header
|
||||
Text('Event Images', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Cover image
|
||||
Text('Cover Image', style: theme.textTheme.bodySmall),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: _pickCoverImage,
|
||||
child: _imagePickerPlaceholder(file: _coverImageFile, label: 'Cover Image'),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Thumbnail image
|
||||
Text('Thumbnail', style: theme.textTheme.bodySmall),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: _pickThumbnailImage,
|
||||
child: _imagePickerPlaceholder(file: _thumbImageFile, label: 'Thumbnail'),
|
||||
),
|
||||
|
||||
const SizedBox(height: 22),
|
||||
|
||||
// Submit button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: ElevatedButton(
|
||||
onPressed: _submitting ? null : _submit,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _primary,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(_cornerRadius - 6)),
|
||||
),
|
||||
child: _submitting
|
||||
? const SizedBox(width: 22, height: 22, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2.2))
|
||||
: const Text('Submit for Verification', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _roundedTextField({required TextEditingController controller, required String hint}) {
|
||||
final theme = Theme.of(context);
|
||||
return TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: hint,
|
||||
filled: true,
|
||||
fillColor: theme.cardColor,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(_cornerRadius - 8), borderSide: BorderSide.none),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _imagePickerPlaceholder({XFile? file, required String label}) {
|
||||
final theme = Theme.of(context);
|
||||
if (file == null) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(color: theme.cardColor, borderRadius: BorderRadius.circular(_cornerRadius - 8)),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.image, size: 28, color: theme.hintColor),
|
||||
const SizedBox(height: 8),
|
||||
Text(label, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// show picked image (file or network depending on platform)
|
||||
if (kIsWeb || file.path.startsWith('http')) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(_cornerRadius - 8),
|
||||
child: Image.network(file.path, width: double.infinity, height: 120, fit: BoxFit.cover, errorBuilder: (_, __, ___) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(color: theme.cardColor, borderRadius: BorderRadius.circular(_cornerRadius - 8)),
|
||||
child: Center(child: Text(label, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor))),
|
||||
);
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
final f = File(file.path);
|
||||
if (!f.existsSync()) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(color: theme.cardColor, borderRadius: BorderRadius.circular(_cornerRadius - 8)),
|
||||
child: Center(child: Text(label, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor))),
|
||||
);
|
||||
}
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(_cornerRadius - 8),
|
||||
child: Image.file(f, width: double.infinity, height: 120, fit: BoxFit.cover, errorBuilder: (_, __, ___) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(color: theme.cardColor, borderRadius: BorderRadius.circular(_cornerRadius - 8)),
|
||||
child: Center(child: Text(label, style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor))),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// The whole screen is scrollable — header is part of the normal scroll (not floating).
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
body: SafeArea(
|
||||
bottom: false,
|
||||
child: SingleChildScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildHeader(context),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: _buildForm(context),
|
||||
),
|
||||
const SizedBox(height: 36),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
374
lib/screens/desktop_login_screen.dart
Normal file
374
lib/screens/desktop_login_screen.dart
Normal file
@@ -0,0 +1,374 @@
|
||||
// lib/screens/desktop_login_screen.dart
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../features/auth/services/auth_service.dart';
|
||||
import 'home_desktop_screen.dart';
|
||||
import '../core/app_decoration.dart';
|
||||
|
||||
class DesktopLoginScreen extends StatefulWidget {
|
||||
const DesktopLoginScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DesktopLoginScreen> createState() => _DesktopLoginScreenState();
|
||||
}
|
||||
|
||||
class _DesktopLoginScreenState extends State<DesktopLoginScreen> with SingleTickerProviderStateMixin {
|
||||
final TextEditingController _emailCtrl = TextEditingController();
|
||||
final TextEditingController _passCtrl = TextEditingController();
|
||||
|
||||
final AuthService _auth = AuthService();
|
||||
|
||||
AnimationController? _controller;
|
||||
Animation<double>? _leftWidthAnim;
|
||||
Animation<double>? _leftTextOpacityAnim;
|
||||
Animation<double>? _formOpacityAnim;
|
||||
Animation<double>? _formOffsetAnim;
|
||||
|
||||
final double _collapsedWidth = 220;
|
||||
final Duration _duration = const Duration(milliseconds: 700);
|
||||
final Curve _curve = Curves.easeInOutCubic;
|
||||
|
||||
bool _isAnimating = false;
|
||||
bool _loading = false; // network loading flag
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller?.dispose();
|
||||
_emailCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _startCollapseAnimation(double initialLeftWidth) async {
|
||||
_controller?.dispose();
|
||||
|
||||
_controller = AnimationController(vsync: this, duration: _duration);
|
||||
|
||||
_leftWidthAnim = Tween<double>(begin: initialLeftWidth, end: _collapsedWidth).animate(
|
||||
CurvedAnimation(parent: _controller!, curve: _curve),
|
||||
);
|
||||
_leftTextOpacityAnim = Tween<double>(begin: 1.0, end: 0.0).animate(
|
||||
CurvedAnimation(parent: _controller!, curve: const Interval(0.0, 0.35, curve: Curves.easeOut)),
|
||||
);
|
||||
|
||||
_formOpacityAnim = Tween<double>(begin: 1.0, end: 0.0).animate(
|
||||
CurvedAnimation(parent: _controller!, curve: const Interval(0.0, 0.55, curve: Curves.easeOut)),
|
||||
);
|
||||
_formOffsetAnim = Tween<double>(begin: 0.0, end: -60.0).animate(
|
||||
CurvedAnimation(parent: _controller!, curve: const Interval(0.0, 0.55, curve: Curves.easeOut)),
|
||||
);
|
||||
|
||||
setState(() => _isAnimating = true);
|
||||
await _controller!.forward();
|
||||
await Future.delayed(const Duration(milliseconds: 120));
|
||||
}
|
||||
|
||||
Future<void> _performLoginFlow(double initialLeftWidth) async {
|
||||
if (_isAnimating || _loading) return;
|
||||
|
||||
setState(() {
|
||||
_loading = true;
|
||||
});
|
||||
|
||||
final email = _emailCtrl.text.trim();
|
||||
final password = _passCtrl.text;
|
||||
|
||||
if (email.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter email')));
|
||||
setState(() => _loading = false);
|
||||
return;
|
||||
}
|
||||
if (password.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter password')));
|
||||
setState(() => _loading = false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Capture user model returned by AuthService (AuthService already saves prefs)
|
||||
await _auth.login(email, password);
|
||||
|
||||
// on success run opening animation
|
||||
await _startCollapseAnimation(initialLeftWidth);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
Navigator.of(context).pushReplacement(PageRouteBuilder(
|
||||
pageBuilder: (context, a1, a2) => const HomeDesktopScreen(skipSidebarEntranceAnimation: true),
|
||||
transitionDuration: Duration.zero,
|
||||
reverseTransitionDuration: Duration.zero,
|
||||
));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
final message = e.toString().replaceAll('Exception: ', '');
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
setState(() => _isAnimating = false);
|
||||
} finally {
|
||||
if (mounted) setState(() {
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _openRegister() {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const DesktopRegisterScreen()));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenW = MediaQuery.of(context).size.width;
|
||||
|
||||
final double safeInitialWidth = (screenW * 0.45).clamp(360.0, screenW * 0.65);
|
||||
final bool animAvailable = _controller != null && _leftWidthAnim != null;
|
||||
final Listenable animation = _controller ?? AlwaysStoppedAnimation(0.0);
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: AnimatedBuilder(
|
||||
animation: animation,
|
||||
builder: (context, child) {
|
||||
final leftWidth = animAvailable ? _leftWidthAnim!.value : safeInitialWidth;
|
||||
final leftTextOpacity = animAvailable && _leftTextOpacityAnim != null ? _leftTextOpacityAnim!.value : 1.0;
|
||||
final formOpacity = animAvailable && _formOpacityAnim != null ? _formOpacityAnim!.value : 1.0;
|
||||
final formOffset = animAvailable && _formOffsetAnim != null ? _formOffsetAnim!.value : 0.0;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: leftWidth,
|
||||
height: double.infinity,
|
||||
// color: const Color(0xFF0B63D6),
|
||||
decoration: AppDecoration.blueGradient,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 36, vertical: 28),
|
||||
child: Opacity(
|
||||
opacity: leftTextOpacity,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
const Text('EVENTIFY', style: TextStyle(color: Colors.white, fontWeight: FontWeight.w800, fontSize: 22)),
|
||||
const Spacer(),
|
||||
const Text('Welcome Back!', style: TextStyle(color: Colors.white, fontSize: 34, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Sign in to access your dashboard, manage events, and stay connected.',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
const Spacer(flex: 2),
|
||||
Opacity(
|
||||
opacity: leftWidth > (_collapsedWidth + 8) ? 1.0 : 0.0,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(bottom: 12.0),
|
||||
child: Text('© Eventify', style: TextStyle(color: Colors.white54)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: Transform.translate(
|
||||
offset: Offset(formOffset, 0),
|
||||
child: Opacity(
|
||||
opacity: formOpacity,
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 48, vertical: 36),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28.0, vertical: 28.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('Sign In', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||
const SizedBox(height: 6),
|
||||
const Text('Please enter your details to continue', textAlign: TextAlign.center, style: TextStyle(color: Colors.black54)),
|
||||
const SizedBox(height: 22),
|
||||
TextField(
|
||||
controller: _emailCtrl,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.email),
|
||||
labelText: 'Email Address',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _passCtrl,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.lock),
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
const Text('Remember me')
|
||||
]),
|
||||
TextButton(onPressed: () {}, child: const Text('Forgot Password?'))
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: (_isAnimating || _loading)
|
||||
? null
|
||||
: () {
|
||||
final double initial = safeInitialWidth;
|
||||
_performLoginFlow(initial);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))),
|
||||
child: (_isAnimating || _loading)
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: const Text('Sign In', style: TextStyle(fontSize: 16)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
TextButton(onPressed: _openRegister, child: const Text("Don't have an account? Register")),
|
||||
TextButton(onPressed: () {}, child: const Text('Contact support'))
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DesktopRegisterScreen extends StatefulWidget {
|
||||
const DesktopRegisterScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DesktopRegisterScreen> createState() => _DesktopRegisterScreenState();
|
||||
}
|
||||
|
||||
class _DesktopRegisterScreenState extends State<DesktopRegisterScreen> {
|
||||
final TextEditingController _emailCtrl = TextEditingController();
|
||||
final TextEditingController _phoneCtrl = TextEditingController();
|
||||
final TextEditingController _passCtrl = TextEditingController();
|
||||
final TextEditingController _confirmCtrl = TextEditingController();
|
||||
final AuthService _auth = AuthService();
|
||||
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailCtrl.dispose();
|
||||
_phoneCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
_confirmCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _performRegister() async {
|
||||
final email = _emailCtrl.text.trim();
|
||||
final phone = _phoneCtrl.text.trim();
|
||||
final pass = _passCtrl.text;
|
||||
final confirm = _confirmCtrl.text;
|
||||
|
||||
if (email.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter email')));
|
||||
return;
|
||||
}
|
||||
if (phone.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter phone number')));
|
||||
return;
|
||||
}
|
||||
if (pass.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Enter password')));
|
||||
return;
|
||||
}
|
||||
if (pass != confirm) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Passwords do not match')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _loading = true);
|
||||
|
||||
try {
|
||||
await _auth.register(
|
||||
email: email,
|
||||
phoneNumber: phone,
|
||||
password: pass,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const HomeDesktopScreen(skipSidebarEntranceAnimation: true)));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
final message = e.toString().replaceAll('Exception: ', '');
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Register')),
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(controller: _emailCtrl, decoration: const InputDecoration(labelText: 'Email')),
|
||||
const SizedBox(height: 8),
|
||||
TextField(controller: _phoneCtrl, decoration: const InputDecoration(labelText: 'Phone')),
|
||||
const SizedBox(height: 8),
|
||||
TextField(controller: _passCtrl, obscureText: true, decoration: const InputDecoration(labelText: 'Password')),
|
||||
const SizedBox(height: 8),
|
||||
TextField(controller: _confirmCtrl, obscureText: true, decoration: const InputDecoration(labelText: 'Confirm password')),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
ElevatedButton(onPressed: _loading ? null : _performRegister, child: _loading ? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2)) : const Text('Register')),
|
||||
const SizedBox(width: 12),
|
||||
OutlinedButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Cancel')),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
81
lib/screens/form_screen.dart
Normal file
81
lib/screens/form_screen.dart
Normal file
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class UserFormScreen extends StatefulWidget {
|
||||
@override
|
||||
_UserFormScreenState createState() => _UserFormScreenState();
|
||||
}
|
||||
|
||||
class _UserFormScreenState extends State<UserFormScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
String _username = '', _email = '', _location = '';
|
||||
String? _profileImage;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('User Details')),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final picked = await ImagePicker().pickImage(source: ImageSource.gallery);
|
||||
if (picked != null) {
|
||||
final bytes = await picked.readAsBytes();
|
||||
String base64Image = base64Encode(bytes);
|
||||
setState(() { _profileImage = base64Image; });
|
||||
}
|
||||
},
|
||||
child: CircleAvatar(
|
||||
radius: 50,
|
||||
backgroundColor: Colors.grey[300],
|
||||
backgroundImage: _profileImage != null ? MemoryImage(base64Decode(_profileImage!)) : null,
|
||||
child: _profileImage == null ? Icon(Icons.person, size: 50, color: Colors.white) : null,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: 'Username'),
|
||||
validator: (value) => value!.isEmpty ? 'Please enter a username' : null,
|
||||
onSaved: (value) => _username = value!,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: 'Email'),
|
||||
validator: (value) => value!.isEmpty ? 'Please enter an email' : null,
|
||||
onSaved: (value) => _email = value!,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(labelText: 'Location'),
|
||||
validator: (value) => value!.isEmpty ? 'Please enter a location' : null,
|
||||
onSaved: (value) => _location = value!,
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
child: Text('Submit'),
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('username', _username);
|
||||
await prefs.setString('email', _email);
|
||||
await prefs.setString('location', _location);
|
||||
if (_profileImage != null) {
|
||||
await prefs.setString('profileImage', _profileImage!);
|
||||
}
|
||||
Navigator.pushReplacementNamed(context, '/home');
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
1042
lib/screens/home_desktop_screen.dart
Normal file
1042
lib/screens/home_desktop_screen.dart
Normal file
File diff suppressed because it is too large
Load Diff
946
lib/screens/home_screen.dart
Normal file
946
lib/screens/home_screen.dart
Normal file
@@ -0,0 +1,946 @@
|
||||
// lib/screens/home_screen.dart
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../features/events/models/event_models.dart';
|
||||
import '../features/events/services/events_service.dart';
|
||||
import 'calendar_screen.dart';
|
||||
import 'profile_screen.dart';
|
||||
import 'contribute_screen.dart';
|
||||
import 'learn_more_screen.dart';
|
||||
import 'search_screen.dart';
|
||||
import '../core/app_decoration.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({Key? key}) : super(key: key);
|
||||
@override
|
||||
_HomeScreenState createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
/// Main screen that hosts 4 tabs in an IndexedStack (Home, Calendar, Contribute, Profile).
|
||||
class _HomeScreenState extends State<HomeScreen> with SingleTickerProviderStateMixin {
|
||||
int _selectedIndex = 0;
|
||||
String _username = '';
|
||||
String _location = '';
|
||||
String _pincode = 'all';
|
||||
|
||||
final EventsService _eventsService = EventsService();
|
||||
|
||||
// backend-driven
|
||||
List<EventModel> _events = [];
|
||||
List<EventTypeModel> _types = [];
|
||||
int _selectedTypeId = -1; // -1 == All
|
||||
|
||||
bool _loading = true;
|
||||
|
||||
// Hero carousel
|
||||
final PageController _heroPageController = PageController();
|
||||
int _heroCurrentPage = 0;
|
||||
Timer? _autoScrollTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadUserDataAndEvents();
|
||||
_startAutoScroll();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_autoScrollTimer?.cancel();
|
||||
_heroPageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startAutoScroll() {
|
||||
_autoScrollTimer?.cancel();
|
||||
_autoScrollTimer = Timer.periodic(const Duration(seconds: 3), (timer) {
|
||||
if (_heroEvents.isEmpty) return;
|
||||
final nextPage = (_heroCurrentPage + 1) % _heroEvents.length;
|
||||
if (_heroPageController.hasClients) {
|
||||
_heroPageController.animateToPage(
|
||||
nextPage,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadUserDataAndEvents() async {
|
||||
setState(() => _loading = true);
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_username = prefs.getString('display_name') ?? prefs.getString('username') ?? '';
|
||||
_location = prefs.getString('location') ?? 'Whitefield, Bengaluru';
|
||||
_pincode = prefs.getString('pincode') ?? 'all';
|
||||
|
||||
try {
|
||||
final types = await _events_service_getEventTypesSafe();
|
||||
final events = await _events_service_getEventsSafe(_pincode);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_types = types;
|
||||
_events = events;
|
||||
_selectedTypeId = -1;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
}
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<EventTypeModel>> _events_service_getEventTypesSafe() async {
|
||||
try {
|
||||
return await _eventsService.getEventTypes();
|
||||
} catch (_) {
|
||||
return <EventTypeModel>[];
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<EventModel>> _events_service_getEventsSafe(String pincode) async {
|
||||
try {
|
||||
return await _eventsService.getEventsByPincode(pincode);
|
||||
} catch (_) {
|
||||
return <EventModel>[];
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _refresh() async {
|
||||
await _loadUserDataAndEvents();
|
||||
}
|
||||
|
||||
void _bookEventAtIndex(int index) {
|
||||
if (index >= 0 && index < _events.length) {
|
||||
setState(() => _events.removeAt(index));
|
||||
}
|
||||
}
|
||||
|
||||
Widget _categoryChip({
|
||||
required String label,
|
||||
required bool selected,
|
||||
required VoidCallback onTap,
|
||||
IconData? icon,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
height: 40,
|
||||
alignment: Alignment.center,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? theme.colorScheme.primary : theme.cardColor,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: selected ? theme.colorScheme.primary : theme.dividerColor,
|
||||
width: 1,
|
||||
),
|
||||
boxShadow: selected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: theme.colorScheme.primary.withOpacity(0.3),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 4),
|
||||
)
|
||||
]
|
||||
: [],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (icon != null) ...[
|
||||
Icon(icon, size: 16, color: selected ? Colors.white : theme.colorScheme.primary),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected ? Colors.white : theme.textTheme.bodyLarge?.color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openLocationSearch() async {
|
||||
final selected = await Navigator.of(context).push(PageRouteBuilder(
|
||||
opaque: false,
|
||||
pageBuilder: (context, animation, secondaryAnimation) => const SearchScreen(),
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
||||
return FadeTransition(opacity: animation, child: child);
|
||||
},
|
||||
transitionDuration: const Duration(milliseconds: 220),
|
||||
));
|
||||
|
||||
if (selected != null && selected is String) {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('location', selected);
|
||||
setState(() {
|
||||
_location = selected;
|
||||
});
|
||||
await _refresh();
|
||||
}
|
||||
}
|
||||
|
||||
void _openEventSearch() {
|
||||
final theme = Theme.of(context);
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (ctx) {
|
||||
return DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.6,
|
||||
minChildSize: 0.3,
|
||||
maxChildSize: 0.95,
|
||||
builder: (context, scrollController) {
|
||||
String query = '';
|
||||
List<EventModel> results = List.from(_events);
|
||||
return StatefulBuilder(builder: (context, setModalState) {
|
||||
void _onQueryChanged(String v) {
|
||||
query = v.trim().toLowerCase();
|
||||
final r = _events.where((e) {
|
||||
final title = (e.title ?? e.name ?? '').toLowerCase();
|
||||
return title.contains(query);
|
||||
}).toList();
|
||||
setModalState(() {
|
||||
results = r;
|
||||
});
|
||||
}
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.cardColor,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: SingleChildScrollView(
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 6,
|
||||
decoration: BoxDecoration(color: theme.dividerColor, borderRadius: BorderRadius.circular(6)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 48,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(color: theme.cardColor, borderRadius: BorderRadius.circular(12), border: Border.all(color: theme.dividerColor)),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.search, color: theme.hintColor),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
style: theme.textTheme.bodyLarge,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search events by name',
|
||||
hintStyle: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
autofocus: true,
|
||||
onChanged: _onQueryChanged,
|
||||
textInputAction: TextInputAction.search,
|
||||
onSubmitted: (v) => _onQueryChanged(v),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: Icon(Icons.close, color: theme.iconTheme.color),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
if (_loading)
|
||||
Center(child: CircularProgressIndicator(color: theme.colorScheme.primary))
|
||||
else if (results.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(child: Text(query.isEmpty ? 'Type to search events' : 'No events found', style: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor))),
|
||||
)
|
||||
else
|
||||
ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemBuilder: (ctx, idx) {
|
||||
final ev = results[idx];
|
||||
final img = (ev.thumbImg != null && ev.thumbImg!.isNotEmpty) ? ev.thumbImg! : (ev.images.isNotEmpty ? ev.images.first.image : null);
|
||||
final title = ev.title ?? ev.name ?? '';
|
||||
final subtitle = ev.startDate ?? '';
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 0, vertical: 8),
|
||||
leading: img != null && img.isNotEmpty
|
||||
? ClipRRect(borderRadius: BorderRadius.circular(8), child: Image.network(img, width: 56, height: 56, fit: BoxFit.cover))
|
||||
: Container(width: 56, height: 56, decoration: BoxDecoration(color: theme.dividerColor, borderRadius: BorderRadius.circular(8)), child: Icon(Icons.event, color: theme.hintColor)),
|
||||
title: Text(title, maxLines: 1, overflow: TextOverflow.ellipsis, style: theme.textTheme.bodyLarge),
|
||||
subtitle: Text(subtitle, maxLines: 1, overflow: TextOverflow.ellipsis, style: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor)),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
if (ev.id != null) {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (_) => LearnMoreScreen(eventId: ev.id)));
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
separatorBuilder: (_, __) => Divider(color: theme.dividerColor),
|
||||
itemCount: results.length,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
body: Stack(
|
||||
children: [
|
||||
// IndexedStack keeps each tab alive and preserves state.
|
||||
IndexedStack(
|
||||
index: _selectedIndex,
|
||||
children: [
|
||||
_buildHomeContent(), // index 0
|
||||
const CalendarScreen(), // index 1
|
||||
const ContributeScreen(), // index 2 (full page, scrollable)
|
||||
const ProfileScreen(), // index 3
|
||||
],
|
||||
),
|
||||
|
||||
// Floating bottom navigation (always visible)
|
||||
Positioned(
|
||||
left: 16,
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
child: _buildFloatingBottomNav(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFloatingBottomNav() {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.cardColor,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [BoxShadow(color: theme.shadowColor.withOpacity(0.06), blurRadius: 12)],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_bottomNavItem(0, Icons.home, 'Home'),
|
||||
_bottomNavItem(1, Icons.calendar_today, 'Calendar'),
|
||||
_bottomNavItem(2, Icons.volunteer_activism, 'Contribute'),
|
||||
_bottomNavItem(3, Icons.person, 'Profile'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _bottomNavItem(int index, IconData icon, String label) {
|
||||
final theme = Theme.of(context);
|
||||
bool active = _selectedIndex == index;
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
},
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: active ? theme.colorScheme.primary.withOpacity(0.08) : Colors.transparent,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: active ? theme.colorScheme.primary : theme.iconTheme.color),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(label, style: theme.textTheme.bodySmall?.copyWith(color: active ? theme.colorScheme.primary : theme.iconTheme.color, fontSize: 12)),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
// Get hero events (first 4 events for the carousel)
|
||||
List<EventModel> get _heroEvents => _events.take(4).toList();
|
||||
|
||||
Widget _buildHomeContent() {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
// Get current hero event image for full-screen blurred background
|
||||
String? currentBgImage;
|
||||
if (_heroEvents.isNotEmpty && _heroCurrentPage < _heroEvents.length) {
|
||||
final event = _heroEvents[_heroCurrentPage];
|
||||
if (event.thumbImg != null && event.thumbImg!.isNotEmpty) {
|
||||
currentBgImage = event.thumbImg;
|
||||
} else if (event.images.isNotEmpty && event.images.first.image.isNotEmpty) {
|
||||
currentBgImage = event.images.first.image;
|
||||
}
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
// Full-screen blurred background of current event image OR the AppDecoration blue gradient if no image
|
||||
Positioned.fill(
|
||||
child: currentBgImage != null
|
||||
? Image.network(
|
||||
currentBgImage,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) => Container(decoration: AppDecoration.blueGradient),
|
||||
)
|
||||
: Container(
|
||||
decoration: AppDecoration.blueGradient,
|
||||
),
|
||||
),
|
||||
|
||||
// Blur overlay on background (applies both when an image is present and when using the blue gradient)
|
||||
Positioned.fill(
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 40, sigmaY: 40),
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.15),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Hero section with cards
|
||||
_buildHeroSection(),
|
||||
|
||||
// Draggable bottom sheet
|
||||
DraggableScrollableSheet(
|
||||
initialChildSize: 0.28,
|
||||
minChildSize: 0.22,
|
||||
maxChildSize: 0.92,
|
||||
builder: (context, scrollController) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.scaffoldBackgroundColor,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.15),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, -5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _buildSheetContent(scrollController),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeroSection() {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
// 0.5 cm gap approximation in logical pixels (approx. 32)
|
||||
const double gapBetweenLocationAndHero = 32.0;
|
||||
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Top bar with location and search
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Location pill
|
||||
GestureDetector(
|
||||
onTap: _openLocationSearch,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.3)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.location_on_outlined, color: Colors.white, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
_location.length > 20 ? '${_location.substring(0, 20)}...' : _location,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const Icon(Icons.keyboard_arrow_down, color: Colors.white, size: 18),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
// Search button
|
||||
GestureDetector(
|
||||
onTap: _openEventSearch,
|
||||
child: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white.withOpacity(0.3)),
|
||||
),
|
||||
child: const Icon(Icons.search, color: Colors.white, size: 24),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 0.5 cm gap (approx. 32 logical pixels)
|
||||
const SizedBox(height: gapBetweenLocationAndHero),
|
||||
|
||||
// Hero image carousel (PageView) and fixed indicators under it.
|
||||
_heroEvents.isEmpty
|
||||
? SizedBox(
|
||||
height: 360,
|
||||
child: Center(
|
||||
child: _loading ? const CircularProgressIndicator(color: Colors.white) : const Text('No events available', style: TextStyle(color: Colors.white70)),
|
||||
),
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
// PageView with only the images/titles
|
||||
SizedBox(
|
||||
height: 360,
|
||||
child: PageView.builder(
|
||||
controller: _heroPageController,
|
||||
onPageChanged: (page) {
|
||||
setState(() => _heroCurrentPage = page);
|
||||
},
|
||||
itemCount: _heroEvents.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _buildHeroEventImage(_heroEvents[index]);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// fixed indicators (outside PageView)
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
height: 28,
|
||||
child: Center(
|
||||
child: AnimatedBuilder(
|
||||
animation: _heroPageController,
|
||||
builder: (context, child) {
|
||||
double page = _heroCurrentPage.toDouble();
|
||||
if (_heroPageController.hasClients) {
|
||||
page = _heroPageController.page ?? page;
|
||||
}
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: List.generate(_heroEvents.length, (i) {
|
||||
final dx = (i - page).abs();
|
||||
final t = 1.0 - dx.clamp(0.0, 1.0); // 1 when focused, 0 when far
|
||||
final width = 10 + (36 - 10) * t; // interpolate between 10 and 36
|
||||
final opacity = 0.35 + (0.65 * t);
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (_heroPageController.hasClients) {
|
||||
_heroPageController.animateToPage(
|
||||
i,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
width: width,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(opacity),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// spacing so the sheet handle doesn't overlap the indicator
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Build a hero image card (image + gradient + title).
|
||||
/// If there's no image, show the AppDecoration blue gradient rounded background
|
||||
/// and a black overlay gradient for contrast.
|
||||
Widget _buildHeroEventImage(EventModel event) {
|
||||
String? img;
|
||||
if (event.thumbImg != null && event.thumbImg!.isNotEmpty) {
|
||||
img = event.thumbImg;
|
||||
} else if (event.images.isNotEmpty && event.images.first.image.isNotEmpty) {
|
||||
img = event.images.first.image;
|
||||
}
|
||||
|
||||
final radius = 24.0;
|
||||
final startDate = event.startDate ?? '';
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (event.id != null) {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (_) => LearnMoreScreen(eventId: event.id)));
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// If image available show it; otherwise use AppDecoration blue gradient.
|
||||
if (img != null && img.isNotEmpty)
|
||||
Image.network(
|
||||
img,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) => Container(decoration: AppDecoration.blueGradientRounded(radius)),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
decoration: AppDecoration.blueGradientRounded(radius),
|
||||
),
|
||||
|
||||
// BLACK gradient overlay to darken bottom area for text (stronger to match your reference)
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.bottomCenter,
|
||||
end: Alignment.topCenter,
|
||||
colors: [
|
||||
Colors.black.withOpacity(0.72), // strong black near bottom for contrast
|
||||
Colors.black.withOpacity(0.38),
|
||||
Colors.black.withOpacity(0.08), // subtle near top
|
||||
],
|
||||
stops: const [0.0, 0.45, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Title and date positioned bottom-left
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 20, 20, 18),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (startDate.isNotEmpty)
|
||||
Text(
|
||||
startDate,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withOpacity(0.9),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
if (startDate.isNotEmpty) const SizedBox(height: 8),
|
||||
Text(
|
||||
event.title ?? event.name ?? '',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 1.1,
|
||||
shadows: [
|
||||
Shadow(color: Colors.black38, blurRadius: 6, offset: Offset(0, 2)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSheetContent(ScrollController scrollController) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return ListView(
|
||||
controller: scrollController,
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
// Drag handle and "see more" text
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12, bottom: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
// Arrow up icon
|
||||
Icon(
|
||||
Icons.keyboard_arrow_up,
|
||||
color: theme.hintColor,
|
||||
size: 28,
|
||||
),
|
||||
Text(
|
||||
'see more',
|
||||
style: TextStyle(
|
||||
color: theme.hintColor,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// "Events Around You" header
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Events Around You',
|
||||
style: theme.textTheme.titleLarge?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 22,
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// View all action
|
||||
},
|
||||
child: Text(
|
||||
'View All',
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Category chips
|
||||
SizedBox(
|
||||
height: 48,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
children: [
|
||||
_categoryChip(
|
||||
label: 'All Events',
|
||||
icon: Icons.grid_view_rounded,
|
||||
selected: _selectedTypeId == -1,
|
||||
onTap: () => _onSelectType(-1),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
for (final t in _types) ...[
|
||||
_categoryChip(
|
||||
label: t.name,
|
||||
icon: _getIconForType(t.name),
|
||||
selected: _selectedTypeId == t.id,
|
||||
onTap: () => _onSelectType(t.id),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Event cards
|
||||
if (_loading)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(40),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
else if (_events.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(40),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'No events found',
|
||||
style: theme.textTheme.bodyLarge?.copyWith(color: theme.hintColor),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
for (int i = 0; i < _events.length; i++) ...[
|
||||
_buildEventCard(_events[i], i),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Bottom padding for nav bar
|
||||
const SizedBox(height: 100),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
IconData _getIconForType(String typeName) {
|
||||
final name = typeName.toLowerCase();
|
||||
if (name.contains('music')) return Icons.music_note;
|
||||
if (name.contains('art') || name.contains('comedy')) return Icons.palette;
|
||||
if (name.contains('festival')) return Icons.celebration;
|
||||
if (name.contains('heritage') || name.contains('history')) return Icons.account_balance;
|
||||
if (name.contains('sport')) return Icons.sports;
|
||||
if (name.contains('food')) return Icons.restaurant;
|
||||
return Icons.event;
|
||||
}
|
||||
|
||||
void _onSelectType(int id) async {
|
||||
setState(() {
|
||||
_selectedTypeId = id;
|
||||
});
|
||||
|
||||
try {
|
||||
final all = await _eventsService.getEventsByPincode(_pincode);
|
||||
final filtered = id == -1 ? all : all.where((e) => e.eventTypeId == id).toList();
|
||||
if (mounted) setState(() => _events = filtered);
|
||||
} catch (e) {
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(e.toString())));
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildEventCard(EventModel e, int index) {
|
||||
final theme = Theme.of(context);
|
||||
String? img;
|
||||
if (e.thumbImg != null && e.thumbImg!.isNotEmpty) {
|
||||
img = e.thumbImg;
|
||||
} else if (e.images.isNotEmpty && e.images.first.image.isNotEmpty) {
|
||||
img = e.images.first.image;
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (e.id != null) {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (_) => LearnMoreScreen(eventId: e.id)));
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 18),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.cardColor,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(color: theme.shadowColor.withOpacity(0.12), blurRadius: 18, offset: const Offset(0, 8)),
|
||||
BoxShadow(color: theme.shadowColor.withOpacity(0.04), blurRadius: 6, offset: const Offset(0, 2)),
|
||||
],
|
||||
),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
||||
child: img != null && img.isNotEmpty
|
||||
? Image.network(img, fit: BoxFit.cover, width: double.infinity, height: 160)
|
||||
: Image.asset('assets/images/event1.jpg', fit: BoxFit.cover, width: double.infinity, height: 160),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(
|
||||
e.title ?? e.name ?? '',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.calendar_today, size: 14, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
'${e.startDate ?? ''}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: theme.textTheme.bodySmall?.color?.withOpacity(0.9), fontSize: 13),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
child: Text('•', style: TextStyle(color: theme.textTheme.bodySmall?.color?.withOpacity(0.4))),
|
||||
),
|
||||
Icon(Icons.location_on, size: 14, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
e.place ?? '',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: theme.textTheme.bodySmall?.color?.withOpacity(0.9), fontSize: 13),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]),
|
||||
)
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _getShortEmailLabel() {
|
||||
try {
|
||||
final parts = _username.split('@');
|
||||
if (parts.isNotEmpty && parts[0].isNotEmpty) return parts[0];
|
||||
} catch (_) {}
|
||||
return 'You';
|
||||
}
|
||||
}
|
||||
174
lib/screens/learn_more_screen.dart
Normal file
174
lib/screens/learn_more_screen.dart
Normal file
@@ -0,0 +1,174 @@
|
||||
// lib/screens/learn_more_screen.dart
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../features/events/models/event_models.dart';
|
||||
import '../features/events/services/events_service.dart';
|
||||
import 'booking_screen.dart';
|
||||
|
||||
class LearnMoreScreen extends StatefulWidget {
|
||||
final int eventId;
|
||||
const LearnMoreScreen({Key? key, required this.eventId}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LearnMoreScreen> createState() => _LearnMoreScreenState();
|
||||
}
|
||||
|
||||
class _LearnMoreScreenState extends State<LearnMoreScreen> {
|
||||
final EventsService _service = EventsService();
|
||||
|
||||
bool _loading = true;
|
||||
EventModel? _event;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadEvent();
|
||||
}
|
||||
|
||||
Future<void> _loadEvent() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
try {
|
||||
final ev = await _service.getEventDetails(widget.eventId);
|
||||
if (!mounted) return;
|
||||
setState(() => _event = ev);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _error = e.toString());
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildImageCarousel() {
|
||||
final imgs = _event?.images ?? [];
|
||||
final thumb = _event?.thumbImg;
|
||||
final list = <String>[];
|
||||
|
||||
if (thumb != null && thumb.isNotEmpty) list.add(thumb);
|
||||
for (final i in imgs) {
|
||||
if (i.image.isNotEmpty && !list.contains(i.image)) list.add(i.image);
|
||||
}
|
||||
|
||||
if (list.isEmpty) {
|
||||
return Container(
|
||||
height: 220,
|
||||
color: Colors.grey.shade200,
|
||||
child: const Center(child: Icon(Icons.event, size: 80, color: Colors.grey)),
|
||||
);
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: 220,
|
||||
child: PageView.builder(
|
||||
itemCount: list.length,
|
||||
itemBuilder: (context, i) => Image.network(list[i], fit: BoxFit.cover, width: double.infinity),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Event Details'),
|
||||
),
|
||||
body: _loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _error != null
|
||||
? Center(child: Text('Error: $_error'))
|
||||
: _event == null
|
||||
? const Center(child: Text('Event not found'))
|
||||
: SingleChildScrollView(
|
||||
child: DefaultTextStyle.merge(
|
||||
// force child Text widgets to use theme-aware foreground color (works in light/dark)
|
||||
style: TextStyle(color: theme.colorScheme.onSurface, height: 1.45),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildImageCarousel(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Title — use theme typography
|
||||
Text(
|
||||
_event!.title ?? _event!.name ?? '',
|
||||
style: theme.textTheme.headlineSmall?.copyWith(fontSize: 22, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Meta row (date, location) — icons will use theme icon color
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.calendar_today, size: 16, color: theme.iconTheme.color),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${_event!.startDate}${_event!.startTime != null ? ' • ${_event!.startTime}' : ''}',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Icon(Icons.location_on, size: 16, color: theme.iconTheme.color),
|
||||
const SizedBox(width: 6),
|
||||
Flexible(child: Text(_event!.place ?? _event!.venueName ?? '', style: theme.textTheme.bodyMedium)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Description — themed body text (no hardcoded black)
|
||||
Text(
|
||||
_event!.description ?? '',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Important section (if present)
|
||||
if ((_event!.importantInformation ?? '').isNotEmpty) ...[
|
||||
Text('Important', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 6),
|
||||
Text(_event!.importantInformation!, style: theme.textTheme.bodyMedium),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
|
||||
// Book button
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => BookingScreen(
|
||||
onBook: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Booked (demo)')));
|
||||
},
|
||||
image: _event!.thumbImg ?? '',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
child: Text('Book Tickets'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
358
lib/screens/login_screen.dart
Normal file
358
lib/screens/login_screen.dart
Normal file
@@ -0,0 +1,358 @@
|
||||
// lib/screens/login_screen.dart
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../features/auth/services/auth_service.dart';
|
||||
import 'home_screen.dart';
|
||||
import '../core/app_decoration.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
final TextEditingController _emailCtrl = TextEditingController();
|
||||
final TextEditingController _passCtrl = TextEditingController();
|
||||
final FocusNode _emailFocus = FocusNode();
|
||||
final FocusNode _passFocus = FocusNode();
|
||||
|
||||
final AuthService _auth = AuthService();
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
_emailFocus.dispose();
|
||||
_passFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String? _emailValidator(String? v) {
|
||||
if (v == null || v.trim().isEmpty) return 'Enter email';
|
||||
final email = v.trim();
|
||||
// Basic email pattern check
|
||||
final emailRegex = RegExp(r"^[^@]+@[^@]+\.[^@]+");
|
||||
if (!emailRegex.hasMatch(email)) return 'Enter a valid email';
|
||||
return null;
|
||||
}
|
||||
|
||||
String? _passwordValidator(String? v) {
|
||||
if (v == null || v.trim().isEmpty) return 'Enter password';
|
||||
if (v.length < 6) return 'Password must be at least 6 characters';
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _performLogin() async {
|
||||
final form = _formKey.currentState;
|
||||
if (form == null) return;
|
||||
if (!form.validate()) return;
|
||||
|
||||
final email = _emailCtrl.text.trim();
|
||||
final password = _passCtrl.text;
|
||||
|
||||
setState(() => _loading = true);
|
||||
|
||||
try {
|
||||
// AuthService.login now returns a UserModel and also persists profile info.
|
||||
await _auth.login(email, password);
|
||||
|
||||
if (!mounted) return;
|
||||
// small delay for UX
|
||||
await Future.delayed(const Duration(milliseconds: 150));
|
||||
|
||||
Navigator.of(context).pushReplacement(PageRouteBuilder(
|
||||
pageBuilder: (context, a1, a2) => const HomeScreen(),
|
||||
transitionDuration: const Duration(milliseconds: 650),
|
||||
reverseTransitionDuration: const Duration(milliseconds: 350),
|
||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
||||
return FadeTransition(opacity: animation, child: child);
|
||||
},
|
||||
));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
final message = e.toString().replaceAll('Exception: ', '');
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _openRegister() {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const RegisterScreen(isDesktop: false)));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const primary = Color(0xFF0B63D6);
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
return Scaffold(
|
||||
// backgroundColor: primary,
|
||||
body: Container(
|
||||
decoration: AppDecoration.blueGradient,
|
||||
child: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 18),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: width < 720 ? width : 720),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(height: 6),
|
||||
const Text('Welcome', style: TextStyle(fontSize: 34, fontWeight: FontWeight.bold, color: Colors.white)),
|
||||
const SizedBox(height: 6),
|
||||
const Text('Sign in to continue', style: TextStyle(color: Colors.white70, fontSize: 16)),
|
||||
const SizedBox(height: 26),
|
||||
|
||||
// HERO card
|
||||
Hero(
|
||||
tag: 'headerCard',
|
||||
flightShuttleBuilder: (flightContext, animation, flightDirection, fromContext, toContext) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: ScaleTransition(
|
||||
scale: animation.drive(Tween(begin: 0.98, end: 1.0).chain(CurveTween(curve: Curves.easeOut))),
|
||||
child: fromContext.widget,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
decoration: AppDecoration.blueGradientRounded(20).copyWith(
|
||||
boxShadow: const [BoxShadow(color: Colors.black26, blurRadius: 18, offset: Offset(0, 8))],
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(18, 18, 18, 18),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
const Text('Eventify', style: TextStyle(color: Colors.white, fontSize: 22, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// white card inside the blue card — now uses Form
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(12)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
child: Column(
|
||||
children: [
|
||||
// Email
|
||||
TextFormField(
|
||||
controller: _emailCtrl,
|
||||
focusNode: _emailFocus,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autofillHints: const [AutofillHints.email],
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Email',
|
||||
border: InputBorder.none,
|
||||
prefixIcon: Icon(Icons.email, color: primary),
|
||||
),
|
||||
validator: _emailValidator,
|
||||
textInputAction: TextInputAction.next,
|
||||
onFieldSubmitted: (_) {
|
||||
FocusScope.of(context).requestFocus(_passFocus);
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
// Password
|
||||
TextFormField(
|
||||
controller: _passCtrl,
|
||||
focusNode: _passFocus,
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password',
|
||||
border: InputBorder.none,
|
||||
prefixIcon: Icon(Icons.lock, color: primary),
|
||||
),
|
||||
validator: _passwordValidator,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => _performLogin(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 18),
|
||||
|
||||
// Login button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _loading ? null : _performLogin,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: primary,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
child: _loading
|
||||
? SizedBox(height: 18, width: 18, child: CircularProgressIndicator(strokeWidth: 2, color: primary))
|
||||
: const Text('Login', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 18),
|
||||
Center(
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
TextButton(
|
||||
onPressed: _openRegister,
|
||||
child: const Text("Don't have an account? Register", style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Register screen calls backend register endpoint via AuthService.register
|
||||
class RegisterScreen extends StatefulWidget {
|
||||
final bool isDesktop;
|
||||
const RegisterScreen({Key? key, this.isDesktop = false}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<RegisterScreen> createState() => _RegisterScreenState();
|
||||
}
|
||||
|
||||
class _RegisterScreenState extends State<RegisterScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final TextEditingController _emailCtrl = TextEditingController();
|
||||
final TextEditingController _phoneCtrl = TextEditingController();
|
||||
final TextEditingController _passCtrl = TextEditingController();
|
||||
final TextEditingController _confirmCtrl = TextEditingController();
|
||||
final AuthService _auth = AuthService();
|
||||
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailCtrl.dispose();
|
||||
_phoneCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
_confirmCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _performRegister() async {
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
|
||||
final email = _emailCtrl.text.trim();
|
||||
final phone = _phoneCtrl.text.trim();
|
||||
final pass = _passCtrl.text;
|
||||
final confirm = _confirmCtrl.text;
|
||||
|
||||
if (pass != confirm) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Passwords do not match')));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _loading = true);
|
||||
|
||||
try {
|
||||
await _auth.register(
|
||||
email: email,
|
||||
phoneNumber: phone,
|
||||
password: pass,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => const HomeScreen()));
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
final message = e.toString().replaceAll('Exception: ', '');
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
String? _emailValidator(String? v) {
|
||||
if (v == null || v.trim().isEmpty) return 'Enter email';
|
||||
final emailRegex = RegExp(r"^[^@]+@[^@]+\.[^@]+");
|
||||
if (!emailRegex.hasMatch(v.trim())) return 'Enter a valid email';
|
||||
return null;
|
||||
}
|
||||
|
||||
String? _phoneValidator(String? v) {
|
||||
if (v == null || v.trim().isEmpty) return 'Enter phone number';
|
||||
if (v.trim().length < 7) return 'Enter a valid phone number';
|
||||
return null;
|
||||
}
|
||||
|
||||
String? _passwordValidator(String? v) {
|
||||
if (v == null || v.isEmpty) return 'Enter password';
|
||||
if (v.length < 6) return 'Password must be at least 6 characters';
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Register')),
|
||||
body: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(controller: _emailCtrl, decoration: const InputDecoration(labelText: 'Email'), validator: _emailValidator, keyboardType: TextInputType.emailAddress),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(controller: _phoneCtrl, decoration: const InputDecoration(labelText: 'Phone'), validator: _phoneValidator, keyboardType: TextInputType.phone),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(controller: _passCtrl, obscureText: true, decoration: const InputDecoration(labelText: 'Password'), validator: _passwordValidator),
|
||||
const SizedBox(height: 8),
|
||||
TextFormField(controller: _confirmCtrl, obscureText: true, decoration: const InputDecoration(labelText: 'Confirm password'), validator: _passwordValidator),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _loading ? null : _performRegister,
|
||||
child: _loading ? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2)) : const Text('Register'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
104
lib/screens/privacy_policy_screen.dart
Normal file
104
lib/screens/privacy_policy_screen.dart
Normal file
@@ -0,0 +1,104 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PrivacyPolicyScreen extends StatelessWidget {
|
||||
const PrivacyPolicyScreen({Key? key}) : super(key: key);
|
||||
|
||||
static const String _policy = '''
|
||||
Privacy Policy for Eventify™
|
||||
Effective Date: 16 September 2025
|
||||
Last Updated: 16 September 2025
|
||||
|
||||
Eventify™ (“we,” “our,” or “us”) respects your privacy and is committed to protecting it through this Privacy Policy. This Privacy Policy explains how we collect, use, and safeguard personal information when you use our application Eventify™ (the “App”). Eventify™ is currently in its beta testing phase and may undergo adjustments or improvements in the future.
|
||||
|
||||
By using Eventify™, you agree to the collection and use of information in accordance with this Privacy Policy.
|
||||
|
||||
Information We Collect
|
||||
Currently, as part of our internal beta testing, Eventify™ may collect limited information, which includes:
|
||||
|
||||
• Calendar entries and event data you choose to create or manage within the App.
|
||||
|
||||
• Basic account information, if required for testing purposes (such as name or email).
|
||||
|
||||
• Device information (such as operating system type, app version, and performance logs) to improve stability and functionality during the beta phase.
|
||||
|
||||
• Usage data (like features accessed and time spent in the app) to help us optimize performance.
|
||||
|
||||
We do not intentionally collect sensitive personal data unless explicitly required for testing and with your consent.
|
||||
|
||||
How We Use Your Information
|
||||
We use the information we collect to:
|
||||
|
||||
• Provide and improve the functionality of Eventify™.
|
||||
|
||||
• Identify issues and enhance user experience during the beta testing phase.
|
||||
|
||||
• Communicate with testers about app updates or feedback requests.
|
||||
|
||||
• Ensure the security and stability of the application.
|
||||
|
||||
Your data will not be sold or shared with third parties for commercial purposes.
|
||||
|
||||
Data Sharing and Disclosure
|
||||
We may share information in limited circumstances:
|
||||
|
||||
• With service providers that help us process data and improve app performance.
|
||||
|
||||
• If required by law, regulation, or legal process.
|
||||
|
||||
• In the event of a company restructuring, merger, or acquisition.
|
||||
|
||||
Outside of these circumstances, your personal data will remain private.
|
||||
|
||||
Data Security
|
||||
We implement industry-standard security measures to protect your data. However, since Eventify™ is in its beta stage, no method of transmission or storage can be guaranteed entirely secure. We encourage testers to avoid entering sensitive or confidential information in the App during beta testing.
|
||||
|
||||
Data Retention
|
||||
Data collected during the beta testing phase will only be retained for as long as necessary to fulfill the purposes outlined in this Policy. Test data may be deleted upon conclusion of the beta testing program, unless otherwise required by law.
|
||||
|
||||
Your Rights
|
||||
Depending on your region, you may have rights regarding your personal data, including:
|
||||
|
||||
• Accessing the data we hold about you.
|
||||
|
||||
• Requesting correction or deletion of your data.
|
||||
|
||||
• Withdrawing consent at any time (note: withdrawal may affect participation in beta testing).
|
||||
|
||||
You may contact us to exercise these rights.
|
||||
|
||||
Children’s Privacy
|
||||
Eventify™ is not directed toward children under 13 years of age. We do not knowingly collect personal data from children. If we learn that information of a child under 13 has been collected, we will promptly delete it.
|
||||
|
||||
Changes to This Privacy Policy
|
||||
As Eventify™ evolves from beta to public release, we may update this Privacy Policy from time to time. Any changes will be reflected with a new “Last Updated” date. We encourage testers to review this page periodically to stay informed.
|
||||
|
||||
Contact Us
|
||||
If you have questions, concerns, or feedback regarding this Privacy Policy, you may contact us at:
|
||||
|
||||
Eventify™ Support Team
|
||||
Email: info@wp.sicherhaven.com
|
||||
''';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final textStyle = theme.textTheme.bodyMedium;
|
||||
final headingStyle = theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Privacy Policy'),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 20.0),
|
||||
child: SelectableText(
|
||||
_policy,
|
||||
style: textStyle?.copyWith(height: 1.45, color: theme.colorScheme.onSurface) ?? TextStyle(height: 1.45, color: theme.colorScheme.onSurface),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
482
lib/screens/profile_screen.dart
Normal file
482
lib/screens/profile_screen.dart
Normal file
@@ -0,0 +1,482 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../features/events/services/events_service.dart';
|
||||
import '../features/events/models/event_models.dart';
|
||||
import 'learn_more_screen.dart';
|
||||
import 'settings_screen.dart'; // <- added import
|
||||
import '../core/app_decoration.dart';
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
const ProfileScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ProfileScreen> createState() => _ProfileScreenState();
|
||||
}
|
||||
|
||||
class _ProfileScreenState extends State<ProfileScreen> {
|
||||
String _username = '';
|
||||
String _email = 'not provided';
|
||||
String _profileImage = ''; // per-account stored path or URL (may be empty)
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
final EventsService _eventsService = EventsService();
|
||||
|
||||
// events coming from backend
|
||||
List<EventModel> _upcomingEvents = [];
|
||||
List<EventModel> _pastEvents = [];
|
||||
|
||||
bool _loadingEvents = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadProfile();
|
||||
}
|
||||
|
||||
/// Load profile for the currently signed-in account.
|
||||
Future<void> _loadProfile() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
// current_email marks the active account (set at login/register)
|
||||
final currentEmail = prefs.getString('current_email') ?? prefs.getString('email') ?? '';
|
||||
|
||||
_email = currentEmail.isNotEmpty ? currentEmail : 'not provided';
|
||||
|
||||
// per-account display name key
|
||||
final displayKey = currentEmail.isNotEmpty ? 'display_name_$currentEmail' : 'display_name';
|
||||
final profileImageKey = currentEmail.isNotEmpty ? 'profileImage_$currentEmail' : 'profileImage';
|
||||
|
||||
// Prefer per-account display_name, else fallback to email
|
||||
_username = prefs.getString(displayKey) ?? prefs.getString('display_name') ?? _email;
|
||||
_profileImage = prefs.getString(profileImageKey) ?? prefs.getString('profileImage') ?? '';
|
||||
|
||||
// load events for this account's pincode (or default)
|
||||
await _loadEventsForProfile(prefs);
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
Future<void> _loadEventsForProfile([SharedPreferences? prefs]) async {
|
||||
setState(() {
|
||||
_loadingEvents = true;
|
||||
_upcomingEvents = [];
|
||||
_pastEvents = [];
|
||||
});
|
||||
|
||||
prefs ??= await SharedPreferences.getInstance();
|
||||
final pincode = prefs.getString('pincode') ?? 'all';
|
||||
|
||||
try {
|
||||
final events = await _eventsService.getEventsByPincode(pincode);
|
||||
|
||||
final now = DateTime.now();
|
||||
final upcoming = <EventModel>[];
|
||||
final past = <EventModel>[];
|
||||
|
||||
DateTime? tryParseDate(String? s) {
|
||||
if (s == null) return null;
|
||||
try {
|
||||
return DateTime.tryParse(s);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
for (final e in events) {
|
||||
final parsed = tryParseDate(e.startDate);
|
||||
if (parsed == null) {
|
||||
upcoming.add(e);
|
||||
} else {
|
||||
if (parsed.isBefore(DateTime(now.year, now.month, now.day))) {
|
||||
past.add(e);
|
||||
} else {
|
||||
upcoming.add(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
upcoming.sort((a, b) {
|
||||
final da = tryParseDate(a.startDate) ?? DateTime(9999);
|
||||
final db = tryParseDate(b.startDate) ?? DateTime(9999);
|
||||
return da.compareTo(db);
|
||||
});
|
||||
past.sort((a, b) {
|
||||
final da = tryParseDate(a.startDate) ?? DateTime(0);
|
||||
final db = tryParseDate(b.startDate) ?? DateTime(0);
|
||||
return db.compareTo(da);
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_upcomingEvents = upcoming;
|
||||
_pastEvents = past;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Failed to load events: $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);
|
||||
|
||||
// update 'email' canonical pointer and 'current_email' (defensive)
|
||||
await prefs.setString('email', currentEmail);
|
||||
await prefs.setString('current_email', currentEmail);
|
||||
|
||||
setState(() {
|
||||
_username = name;
|
||||
_email = currentEmail.isNotEmpty ? currentEmail : 'not provided';
|
||||
_profileImage = profileImage;
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- Image picking / manual path ----------
|
||||
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);
|
||||
} catch (e) {
|
||||
debugPrint('Image pick error: $e');
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Failed to pick image: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _enterAssetPathDialog() async {
|
||||
final ctl = TextEditingController(text: _profileImage);
|
||||
final result = await showDialog<String?>(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
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')),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result == null || result.isEmpty) return;
|
||||
await _saveProfile(_username, _email, result);
|
||||
}
|
||||
|
||||
Future<void> _openEditDialog() async {
|
||||
final nameCtl = TextEditingController(text: _username);
|
||||
final emailCtl = TextEditingController(text: _email);
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (ctx) {
|
||||
final theme = Theme.of(ctx);
|
||||
return DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.44,
|
||||
minChildSize: 0.28,
|
||||
maxChildSize: 0.92,
|
||||
builder: (context, scrollController) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(18, 14, 18, 18),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.cardColor,
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
controller: scrollController,
|
||||
child: Column(
|
||||
children: [
|
||||
Container(width: 48, height: 6, decoration: BoxDecoration(color: theme.dividerColor, borderRadius: BorderRadius.circular(6))),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Text('Edit profile', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold)),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.photo_camera),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop(); // close sheet then launch picker to avoid nested modal issues
|
||||
await _pickFromGallery();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.link),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
_enterAssetPathDialog();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
TextField(controller: nameCtl, decoration: InputDecoration(labelText: 'Name', filled: true, fillColor: theme.cardColor, border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)))),
|
||||
const SizedBox(height: 8),
|
||||
TextField(controller: emailCtl, decoration: InputDecoration(labelText: 'Email', filled: true, fillColor: theme.cardColor, border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)))),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
Row(
|
||||
children: [
|
||||
const Spacer(),
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Cancel')),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final newName = nameCtl.text.trim().isEmpty ? _email : nameCtl.text.trim();
|
||||
final newEmail = emailCtl.text.trim().isEmpty ? _email : emailCtl.text.trim();
|
||||
|
||||
// If user changes email here (edge-case) we will treat newEmail as current account pointer.
|
||||
await _saveProfile(newName, newEmail, _profileImage);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Tip: tap the camera icon to pick from gallery (mobile). Or tap the link icon to paste an asset path or URL.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// ---------- UI helpers ----------
|
||||
Widget _topIcon(IconData icon, {VoidCallback? onTap}) {
|
||||
final theme = Theme.of(context);
|
||||
return InkWell(
|
||||
onTap: onTap ?? () {},
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(color: theme.cardColor.withOpacity(0.6), borderRadius: BorderRadius.circular(12)),
|
||||
child: Icon(icon, color: theme.iconTheme.color),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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.withOpacity(0.7) : theme.hintColor);
|
||||
|
||||
Widget leadingWidget() {
|
||||
if (imageUrl != null && imageUrl.trim().isNotEmpty) {
|
||||
if (imageUrl.startsWith('http')) {
|
||||
return ClipRRect(borderRadius: BorderRadius.circular(8), child: Image.network(imageUrl, width: 56, height: 56, fit: BoxFit.cover, errorBuilder: (_, __, ___) => Container(width: 56, height: 56, color: Theme.of(context).dividerColor, child: Icon(Icons.image, color: Theme.of(context).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(8), child: Image.file(file, width: 56, height: 56, fit: BoxFit.cover, errorBuilder: (_, __, ___) => Container(width: 56, height: 56, color: Theme.of(context).dividerColor, child: Icon(Icons.image, color: Theme.of(context).hintColor))));
|
||||
} else {
|
||||
return ClipRRect(borderRadius: BorderRadius.circular(8), child: Image.asset(imageUrl, width: 56, height: 56, fit: BoxFit.cover, errorBuilder: (_, __, ___) => Container(width: 56, height: 56, color: Theme.of(context).dividerColor, child: Icon(Icons.image, color: Theme.of(context).hintColor))));
|
||||
}
|
||||
} else {
|
||||
return ClipRRect(borderRadius: BorderRadius.circular(8), child: Image.asset(imageUrl, width: 56, height: 56, fit: BoxFit.cover, errorBuilder: (_, __, ___) => Container(width: 56, height: 56, color: Theme.of(context).dividerColor, child: Icon(Icons.image, color: Theme.of(context).hintColor))));
|
||||
}
|
||||
} else {
|
||||
return ClipRRect(borderRadius: BorderRadius.circular(8), child: Image.asset(imageUrl, width: 56, height: 56, fit: BoxFit.cover, errorBuilder: (_, __, ___) => Container(width: 56, height: 56, color: Theme.of(context).dividerColor, child: Icon(Icons.image, color: Theme.of(context).hintColor))));
|
||||
}
|
||||
}
|
||||
|
||||
return Container(width: 56, height: 56, color: Theme.of(context).dividerColor, child: Icon(Icons.image, color: Theme.of(context).hintColor));
|
||||
}
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [BoxShadow(color: Theme.of(context).shadowColor.withOpacity(0.06), blurRadius: 10, offset: const Offset(0, 6))],
|
||||
),
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
if (ev.id != null) {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (_) => LearnMoreScreen(eventId: ev.id)));
|
||||
}
|
||||
},
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
leading: ClipRRect(borderRadius: BorderRadius.circular(8), child: leadingWidget()),
|
||||
title: Text(title, style: titleStyle),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 6),
|
||||
Text(dateLabel, style: subtitleStyle),
|
||||
const SizedBox(height: 2),
|
||||
Text(location, style: subtitleStyle),
|
||||
],
|
||||
),
|
||||
trailing: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.primary.withOpacity(0.12), borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(Icons.qr_code_scanner, color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProfileAvatar() {
|
||||
final path = _profileImage.trim();
|
||||
if (path.startsWith('http')) {
|
||||
return ClipOval(child: Image.network(path, width: 96, height: 96, fit: BoxFit.cover, errorBuilder: (_, __, ___) => const Icon(Icons.person, size: 48, color: Colors.grey)));
|
||||
}
|
||||
if (kIsWeb) {
|
||||
return ClipOval(child: Image.asset(path.isNotEmpty ? path : 'assets/images/profile.jpg', width: 96, height: 96, fit: BoxFit.cover, errorBuilder: (_, __, ___) => const Icon(Icons.person, size: 48, color: Colors.grey)));
|
||||
}
|
||||
if (path.isNotEmpty && (path.startsWith('/') || path.contains(Platform.pathSeparator))) {
|
||||
final file = File(path);
|
||||
if (file.existsSync()) {
|
||||
return ClipOval(child: Image.file(file, width: 96, height: 96, fit: BoxFit.cover, errorBuilder: (_, __, ___) => const Icon(Icons.person, size: 48, color: Colors.grey)));
|
||||
} else {
|
||||
return ClipOval(child: Image.asset('assets/images/profile.jpg', width: 96, height: 96, fit: BoxFit.cover, errorBuilder: (_, __, ___) => const Icon(Icons.person, size: 48, color: Colors.grey)));
|
||||
}
|
||||
}
|
||||
return ClipOval(child: Image.asset('assets/images/profile.jpg', width: 96, height: 96, fit: BoxFit.cover, errorBuilder: (_, __, ___) => const Icon(Icons.person, size: 48, color: Colors.grey)));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final gradient = const LinearGradient(colors: [Color(0xFF0B63D6), Color(0xFF1449B8)], begin: Alignment.topLeft, end: Alignment.bottomRight);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: theme.scaffoldBackgroundColor,
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: double.infinity,
|
||||
decoration: AppDecoration.blueGradient.copyWith(borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24))),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 18, 20, 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Expanded(child: SizedBox()),
|
||||
Text('Profile', style: theme.textTheme.titleMedium?.copyWith(color: Colors.white, fontWeight: FontWeight.w600)),
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => _openEditDialog(),
|
||||
child: Container(margin: const EdgeInsets.only(right: 10), width: 40, height: 40, decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(10)), child: const Icon(Icons.edit, color: Colors.white)),
|
||||
),
|
||||
// <-- REPLACED the reminder icon with settings icon and navigation
|
||||
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: 18),
|
||||
|
||||
GestureDetector(
|
||||
onTap: () => _openEditDialog(),
|
||||
child: CircleAvatar(radius: 48, backgroundColor: Colors.white, child: _buildProfileAvatar()),
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
Text(_username, style: theme.textTheme.titleLarge?.copyWith(color: Colors.white, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 6),
|
||||
Container(padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(16)), child: Text(_email, style: const TextStyle(color: Colors.white70))),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(18, 18, 18, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Removed Upcoming Events section — kept only Past Events below
|
||||
|
||||
Text('Past Events', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
if (_loadingEvents)
|
||||
const SizedBox.shrink()
|
||||
else if (_pastEvents.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Text('No past events', style: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor)),
|
||||
)
|
||||
else
|
||||
Column(children: _pastEvents.map((e) => _eventListTileFromModel(e, faded: true)).toList()),
|
||||
|
||||
const SizedBox(height: 28),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
51
lib/screens/responsive_layout.dart
Normal file
51
lib/screens/responsive_layout.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
// lib/widgets/responsive_layout.dart
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Simple responsive layout chooser.
|
||||
///
|
||||
/// Behavior:
|
||||
/// - On desktop platforms (Windows / macOS / Linux) -> always use `desktop`.
|
||||
/// - On web -> treat as desktop (tablet/desktop UI). If you want web to act
|
||||
/// like mobile at very narrow widths, you can change that logic here.
|
||||
/// - On mobile platforms (Android / iOS) -> use `mobile` when width < mobileBreakpoint,
|
||||
/// otherwise use `desktop`.
|
||||
///
|
||||
/// Tablet uses the desktop UI by design (per your request).
|
||||
class ResponsiveLayout extends StatelessWidget {
|
||||
final Widget mobile;
|
||||
final Widget desktop;
|
||||
final double mobileBreakpoint;
|
||||
|
||||
const ResponsiveLayout({
|
||||
Key? key,
|
||||
required this.mobile,
|
||||
required this.desktop,
|
||||
this.mobileBreakpoint = 700, // tune this value if you prefer different breakpoint
|
||||
}) : assert(mobileBreakpoint > 0),
|
||||
super(key: key);
|
||||
|
||||
bool _isMobilePlatform() {
|
||||
// kIsWeb is true for web builds.
|
||||
if (kIsWeb) return false; // treat web as desktop/tablet by default
|
||||
// defaultTargetPlatform works on Flutter (all non-web platforms).
|
||||
return defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS;
|
||||
}
|
||||
|
||||
bool _chooseMobile(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
// If running on Android/iOS, allow width to determine mobile vs desktop.
|
||||
if (_isMobilePlatform()) {
|
||||
return width < mobileBreakpoint;
|
||||
}
|
||||
|
||||
// On desktop platforms (Windows/macOS/Linux) and on web, always use desktop UI.
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _chooseMobile(context) ? mobile : desktop;
|
||||
}
|
||||
}
|
||||
307
lib/screens/search_screen.dart
Normal file
307
lib/screens/search_screen.dart
Normal file
@@ -0,0 +1,307 @@
|
||||
// lib/screens/search_screen.dart
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Location packages (add to pubspec.yaml)
|
||||
// geolocator -> for permission & coordinates
|
||||
// geocoding -> for reverse geocoding coordinates to a placemark
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
|
||||
class SearchScreen extends StatefulWidget {
|
||||
const SearchScreen({Key? key}) : super(key: key);
|
||||
|
||||
/// Returns a String to the caller via Navigator.pop(string).
|
||||
/// Could be:
|
||||
/// - a city name (e.g. "Bengaluru")
|
||||
/// - 'Current Location' or a resolved locality like "Whitefield, Bengaluru"
|
||||
@override
|
||||
State<SearchScreen> createState() => _SearchScreenState();
|
||||
}
|
||||
|
||||
class _SearchScreenState extends State<SearchScreen> {
|
||||
final TextEditingController _ctrl = TextEditingController();
|
||||
final List<String> _popularCities = const [
|
||||
'Delhi NCR',
|
||||
'Mumbai',
|
||||
'Kolkata',
|
||||
'Bengaluru',
|
||||
'Hyderabad',
|
||||
'Chandigarh',
|
||||
'Pune',
|
||||
'Chennai',
|
||||
'Ahmedabad',
|
||||
'Jaipur',
|
||||
];
|
||||
|
||||
List<String> _filtered = [];
|
||||
bool _loadingLocation = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_filtered = List.from(_popularCities);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onQueryChanged(String q) {
|
||||
final ql = q.trim().toLowerCase();
|
||||
setState(() {
|
||||
if (ql.isEmpty) {
|
||||
_filtered = List.from(_popularCities);
|
||||
} else {
|
||||
_filtered = _popularCities.where((c) => c.toLowerCase().contains(ql)).toList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _selectAndClose(String city) {
|
||||
Navigator.of(context).pop(city);
|
||||
}
|
||||
|
||||
Future<void> _useCurrentLocation() async {
|
||||
setState(() => _loadingLocation = true);
|
||||
|
||||
try {
|
||||
// Check / request permission
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever || permission == LocationPermission.denied) {
|
||||
// Can't get permission — inform user and return a fallback label
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Location permission denied')));
|
||||
Navigator.of(context).pop('Current Location');
|
||||
return;
|
||||
}
|
||||
|
||||
// Get current position
|
||||
final pos = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
|
||||
|
||||
// Try reverse geocoding to get a readable place name
|
||||
try {
|
||||
final placemarks = await placemarkFromCoordinates(pos.latitude, pos.longitude);
|
||||
if (placemarks.isNotEmpty) {
|
||||
final p = placemarks.first;
|
||||
final parts = <String>[];
|
||||
if ((p.subLocality ?? '').isNotEmpty) parts.add(p.subLocality!);
|
||||
if ((p.locality ?? '').isNotEmpty) parts.add(p.locality!);
|
||||
if ((p.subAdministrativeArea ?? '').isNotEmpty) parts.add(p.subAdministrativeArea!);
|
||||
if ((p.administrativeArea ?? '').isNotEmpty) parts.add(p.administrativeArea!);
|
||||
final label = parts.isNotEmpty ? parts.join(', ') : 'Current Location';
|
||||
Navigator.of(context).pop(label);
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore reverse geocode failures and fallback to coordinates or simple label
|
||||
}
|
||||
|
||||
// fallback: return lat,lng string or simple label
|
||||
Navigator.of(context).pop('${pos.latitude.toStringAsFixed(5)},${pos.longitude.toStringAsFixed(5)}');
|
||||
} catch (e) {
|
||||
// If any error, fallback to simple label
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Could not determine location: $e')));
|
||||
Navigator.of(context).pop('Current Location');
|
||||
} finally {
|
||||
if (mounted) setState(() => _loadingLocation = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Full-screen transparent Scaffold so the BackdropFilter can blur underlying UI.
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
body: GestureDetector(
|
||||
// Tap outside sheet to dismiss
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Stack(
|
||||
children: [
|
||||
// BackdropFilter + dim overlay
|
||||
BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 8.0, sigmaY: 8.0),
|
||||
child: Container(color: Colors.black.withOpacity(0.16)),
|
||||
),
|
||||
|
||||
// Align bottom: the sheet content
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: _SearchBottomSheet(
|
||||
controller: _ctrl,
|
||||
filteredCities: _filtered,
|
||||
onCityTap: (city) => _selectAndClose(city),
|
||||
onQueryChanged: _onQueryChanged,
|
||||
onUseCurrentLocation: _useCurrentLocation,
|
||||
loadingLocation: _loadingLocation,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SearchBottomSheet extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final List<String> filteredCities;
|
||||
final void Function(String) onCityTap;
|
||||
final void Function(String) onQueryChanged;
|
||||
final Future<void> Function() onUseCurrentLocation;
|
||||
final bool loadingLocation;
|
||||
|
||||
const _SearchBottomSheet({
|
||||
Key? key,
|
||||
required this.controller,
|
||||
required this.filteredCities,
|
||||
required this.onCityTap,
|
||||
required this.onQueryChanged,
|
||||
required this.onUseCurrentLocation,
|
||||
required this.loadingLocation,
|
||||
}) : super(key: key);
|
||||
|
||||
Widget _cityChip(String name, BuildContext context, void Function() onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(color: Colors.grey[100], borderRadius: BorderRadius.circular(12)),
|
||||
child: Text(name, style: const TextStyle(color: Colors.black87)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// The bottom sheet container
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Container(
|
||||
// limit height so it looks like a sheet
|
||||
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.78, minHeight: 240),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
boxShadow: [BoxShadow(color: Colors.black26, blurRadius: 12)],
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(20, 18, 20, 28),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// center drag handle
|
||||
Center(
|
||||
child: Container(width: 48, height: 6, decoration: BoxDecoration(color: Colors.grey[300], borderRadius: BorderRadius.circular(6))),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Header
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('Set Your Location', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
// Close button (inside sheet)
|
||||
InkWell(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(width: 40, height: 40, decoration: BoxDecoration(color: Colors.grey[100], borderRadius: BorderRadius.circular(10)), child: const Icon(Icons.close, color: Colors.black54)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Search field (now functional)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(color: Colors.grey[100], borderRadius: BorderRadius.circular(12)),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.search, color: Colors.black38),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(hintText: 'Search city, area or locality', border: InputBorder.none),
|
||||
textInputAction: TextInputAction.search,
|
||||
onChanged: onQueryChanged,
|
||||
onSubmitted: (v) {
|
||||
final q = v.trim();
|
||||
if (q.isEmpty) return;
|
||||
// If there's an exact/first match in filteredCities, pick it; otherwise pass the raw query.
|
||||
final match = filteredCities.isNotEmpty ? filteredCities.first : null;
|
||||
Navigator.of(context).pop(match ?? q);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (controller.text.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
controller.clear();
|
||||
onQueryChanged('');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Use current location button
|
||||
ElevatedButton(
|
||||
onPressed: loadingLocation ? null : () => onUseCurrentLocation(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 12),
|
||||
backgroundColor: const Color(0xFF0B63D6),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.my_location, color: Colors.white),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: Text(loadingLocation ? 'Detecting location...' : 'Use Current Location', style: const TextStyle(color: Colors.white))),
|
||||
if (loadingLocation)
|
||||
const SizedBox(width: 18, height: 18, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
else
|
||||
const Icon(Icons.chevron_right, color: Colors.white),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
|
||||
// Popular cities
|
||||
const Text('Popular Cities', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
for (final city in filteredCities.take(8)) _cityChip(city, context, () => onCityTap(city)),
|
||||
// if filteredCities is empty show empty state
|
||||
if (filteredCities.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Text('No suggestions', style: TextStyle(color: Colors.grey[600])),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
254
lib/screens/settings_screen.dart
Normal file
254
lib/screens/settings_screen.dart
Normal file
@@ -0,0 +1,254 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'login_screen.dart';
|
||||
import 'desktop_login_screen.dart';
|
||||
import '../core/theme_manager.dart';
|
||||
import 'privacy_policy_screen.dart'; // new import
|
||||
import '../core/app_decoration.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
bool _notifications = true;
|
||||
String _appVersion = '1.2(p)';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadPreferences();
|
||||
}
|
||||
|
||||
Future<void> _loadPreferences() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
setState(() {
|
||||
_notifications = prefs.getBool('reminders_enabled') ?? true;
|
||||
// app version may come from pubspec or preferences; kept static otherwise
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _saveNotifications(bool value) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool('reminders_enabled', value);
|
||||
setState(() => _notifications = value);
|
||||
}
|
||||
|
||||
Future<void> _confirmLogout() async {
|
||||
final should = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return AlertDialog(
|
||||
title: const Text('Logout'),
|
||||
content: const Text('Are you sure you want to logout? This will clear saved login data.'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(ctx).pop(false), child: const Text('Cancel')),
|
||||
ElevatedButton(onPressed: () => Navigator.of(ctx).pop(true), child: const Text('Logout')),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (should == true) {
|
||||
await _performLogout();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _performLogout() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove('username');
|
||||
await prefs.remove('email');
|
||||
await prefs.remove('profileImage');
|
||||
|
||||
// Decide which login screen to show depending on current window width
|
||||
final double width = MediaQuery.of(context).size.width;
|
||||
const double desktopBreakpoint = 820; // same breakpoint used elsewhere
|
||||
final bool isDesktop = width >= desktopBreakpoint;
|
||||
|
||||
// Navigate and remove all previous routes
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => isDesktop ? const DesktopLoginScreen() : const LoginScreen(),
|
||||
),
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTile({required IconData icon, required String title, String? subtitle, VoidCallback? onTap}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 4))],
|
||||
),
|
||||
child: ListTile(
|
||||
leading: Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(color: Theme.of(context).scaffoldBackgroundColor, borderRadius: BorderRadius.circular(10)),
|
||||
child: Icon(icon, color: const Color(0xFF0B63D6)),
|
||||
),
|
||||
title: Text(title, style: const TextStyle(fontWeight: FontWeight.w600)),
|
||||
subtitle: subtitle != null ? Text(subtitle) : null,
|
||||
onTap: onTap,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const primary = Color(0xFF0B63D6);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// Header
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.fromLTRB(20, 18, 20, 18),
|
||||
decoration: AppDecoration.blueGradient.copyWith(
|
||||
borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(24), bottomRight: Radius.circular(24)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Expanded(child: Text('Settings', style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w600))),
|
||||
InkWell(
|
||||
onTap: () => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Help tapped (demo)'))),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(color: Colors.white24, borderRadius: BorderRadius.circular(10)),
|
||||
child: const Icon(Icons.help_outline, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 18),
|
||||
|
||||
// Content
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(18, 0, 18, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Account
|
||||
const Text('Account', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
_buildTile(
|
||||
icon: Icons.person,
|
||||
title: 'Edit Profile',
|
||||
subtitle: 'Change username, email or photo',
|
||||
onTap: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Open Profile tab (demo)')));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Preferences
|
||||
const Text('Preferences', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Reminders switch wrapped in card-like container
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 4))],
|
||||
),
|
||||
child: SwitchListTile(
|
||||
tileColor: Theme.of(context).cardColor,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
value: _notifications,
|
||||
onChanged: (v) => _saveNotifications(v),
|
||||
title: const Text('Reminders'),
|
||||
secondary: const Icon(Icons.notifications, color: primary),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Dark Mode switch wrapped in card-like container and hooked to ThemeManager
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: const [BoxShadow(color: Colors.black12, blurRadius: 6, offset: Offset(0, 4))],
|
||||
),
|
||||
child: ValueListenableBuilder<ThemeMode>(
|
||||
valueListenable: ThemeManager.themeMode,
|
||||
builder: (context, mode, _) {
|
||||
final isDark = mode == ThemeMode.dark;
|
||||
return SwitchListTile(
|
||||
tileColor: Theme.of(context).cardColor,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
value: isDark,
|
||||
onChanged: (v) => ThemeManager.setThemeMode(v ? ThemeMode.dark : ThemeMode.light),
|
||||
title: const Text('Dark Mode'),
|
||||
secondary: const Icon(Icons.dark_mode, color: primary),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 18),
|
||||
|
||||
// About
|
||||
const Text('About', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 12),
|
||||
_buildTile(icon: Icons.info_outline, title: 'App Version', subtitle: _appVersion, onTap: () {}),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Privacy Policy tile now navigates to PrivacyPolicyScreen
|
||||
_buildTile(
|
||||
icon: Icons.privacy_tip_outlined,
|
||||
title: 'Privacy Policy',
|
||||
subtitle: 'Demo app',
|
||||
onTap: () {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (_) => const PrivacyPolicyScreen()));
|
||||
},
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Logout area
|
||||
Center(
|
||||
child: Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: _confirmLogout,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: primary,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 14),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
),
|
||||
child: const Text('Logout', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text('Logging out will return you to the login screen.', style: TextStyle(color: Colors.black54, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
134
lib/screens/tickets_booked_screen.dart
Normal file
134
lib/screens/tickets_booked_screen.dart
Normal file
@@ -0,0 +1,134 @@
|
||||
// lib/screens/tickets_booked_screen.dart
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TicketsBookedScreen extends StatelessWidget {
|
||||
const TicketsBookedScreen({Key? key}) : super(key: key);
|
||||
|
||||
void _onScannerTap(BuildContext context) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Scanner tapped (demo)')),
|
||||
);
|
||||
}
|
||||
|
||||
void _onWhatsappTap(BuildContext context) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Chat/WhatsApp tapped (demo)')),
|
||||
);
|
||||
}
|
||||
|
||||
void _onCallTap(BuildContext context) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Call tapped (demo)')),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color bg = Color(0xFFF7F5FB); // app background
|
||||
final Color primary = Color(0xFF0B63D6); // blue theme
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: bg,
|
||||
appBar: AppBar(
|
||||
backgroundColor: bg,
|
||||
elevation: 0,
|
||||
iconTheme: IconThemeData(color: Colors.black87),
|
||||
title: Text('Tickets Booked', style: TextStyle(color: Colors.black87)),
|
||||
centerTitle: false,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: 36),
|
||||
|
||||
// Confirmation text
|
||||
Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Your tickets have been booked!',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600, color: Colors.black87),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Text(
|
||||
'Enjoy the event.',
|
||||
style: TextStyle(fontSize: 14, color: Colors.black54),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 36),
|
||||
|
||||
// Row of rounded blue icons
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_actionButton(context, primary, Icons.qr_code_scanner, 'Scanner', _onScannerTap),
|
||||
_actionButton(context, primary, Icons.chat, 'Chat', _onWhatsappTap), // 👈 replaced
|
||||
_actionButton(context, primary, Icons.call, 'Call', _onCallTap),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 28),
|
||||
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28.0),
|
||||
child: Text(
|
||||
'Save this confirmation — you may need it at the venue.\nUse the buttons above to share or show your ticket.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.black54),
|
||||
),
|
||||
),
|
||||
|
||||
Spacer(),
|
||||
|
||||
// Return to Home button
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 22.0),
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: primary,
|
||||
padding: EdgeInsets.symmetric(horizontal: 28, vertical: 14),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
|
||||
),
|
||||
child: Text('Return to Home', style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// helper
|
||||
Widget _actionButton(
|
||||
BuildContext context, Color color, IconData icon, String label, Function onTap) {
|
||||
return Column(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () => onTap(context),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 8, offset: Offset(0, 4))],
|
||||
),
|
||||
child: Center(child: Icon(icon, color: Colors.white, size: 30)),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
Text(label, style: TextStyle(color: Colors.black87)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user