- Removed TypeScript configuration file (tsconfig.json). - Added Flutter plugin dependencies for secure storage. - Implemented main application structure with routing for login, profile, and schedule screens. - Developed LoginScreen with authentication logic and user feedback. - Created ProfileScreen to display user profile information and logout functionality. - Built ScheduleScreen to show weekly work schedule with navigation controls. - Integrated AuthService for handling authentication, token storage, and API interactions. - Updated pubspec.yaml with necessary dependencies for the Flutter project.
97 lines
3.9 KiB
Dart
97 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../services/auth_service.dart';
|
|
|
|
class ScheduleScreen extends StatefulWidget {
|
|
@override
|
|
_ScheduleScreenState createState() => _ScheduleScreenState();
|
|
}
|
|
|
|
class _ScheduleScreenState extends State<ScheduleScreen> {
|
|
DateTime currentWeek = DateTime.now();
|
|
bool loading = false;
|
|
List<dynamic> workdays = [];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final df = DateFormat('yyyy. MMM d.');
|
|
final weekStart = currentWeek.subtract(Duration(days: currentWeek.weekday - 1));
|
|
final weekDays = List.generate(7, (i) => weekStart.add(Duration(days: i)));
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text('Beosztás')),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
children: [
|
|
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
|
IconButton(icon: Icon(Icons.chevron_left), onPressed: () { setState(() { currentWeek = currentWeek.subtract(Duration(days: 7)); }); fetchWorkdays(); }),
|
|
Text('${df.format(weekStart)} - ${df.format(weekStart.add(Duration(days:6)))}', style: TextStyle(fontWeight: FontWeight.bold)),
|
|
IconButton(icon: Icon(Icons.chevron_right), onPressed: () { setState(() { currentWeek = currentWeek.add(Duration(days: 7)); }); fetchWorkdays(); }),
|
|
]),
|
|
SizedBox(height: 8),
|
|
loading ? CircularProgressIndicator() : Expanded(
|
|
child: LayoutBuilder(builder: (ctx, cons) {
|
|
final cross = cons.maxWidth > 480 ? 4 : 2;
|
|
return GridView.count(
|
|
crossAxisCount: cross,
|
|
childAspectRatio: 0.9,
|
|
children: weekDays.map((day) {
|
|
final formatted = DateFormat('yyyy-MM-dd').format(day);
|
|
final wd = workdays.firstWhere((w) => (w['WorkDay'] ?? '').toString().substring(0,10) == formatted, orElse: () => null);
|
|
String title = '';
|
|
if (wd != null) {
|
|
if (wd['Type'] == 1) title = 'PN';
|
|
else if (wd['Type'] == 10) title = wd['text'] ?? '';
|
|
}
|
|
return Card(
|
|
color: wd != null && wd['Type'] == 10 ? Color(0xFFA24BFA) : (wd != null && wd['Type'] == 1 ? Color(0xFFB388FF) : Color(0xFFede7f6)),
|
|
child: Center(
|
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
Text('${day.day}', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
|
SizedBox(height: 6),
|
|
Text(title, style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
|
|
]),
|
|
),
|
|
);
|
|
}).toList(),
|
|
);
|
|
})
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> fetchWorkdays() async {
|
|
setState(() { loading = true; });
|
|
final auth = Provider.of<AuthService>(context, listen: false);
|
|
final token = auth.token;
|
|
if (token == null) { setState(() { workdays = []; loading = false; }); return; }
|
|
final weekStart = currentWeek.subtract(Duration(days: currentWeek.weekday - 1));
|
|
final weekEnd = weekStart.add(Duration(days: 6));
|
|
final months = {weekStart.month, weekEnd.month};
|
|
final years = {weekStart.year, weekEnd.year};
|
|
List all = [];
|
|
for (final y in years) {
|
|
for (final m in months) {
|
|
try {
|
|
final resList = await auth.fetchSchedule(y, m);
|
|
if (resList.isNotEmpty) all.addAll(resList);
|
|
} catch (e) {
|
|
// ignore per-month errors
|
|
}
|
|
}
|
|
}
|
|
setState(() { workdays = all; loading = false; });
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
fetchWorkdays();
|
|
}
|
|
}
|