feat: Initialize Flutter app with authentication and scheduling features

- 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.
This commit is contained in:
2025-08-20 22:48:54 +02:00
parent 925dc6e0c0
commit 871bfcdccb
47 changed files with 629 additions and 13403 deletions

33
lib/main.dart Normal file
View File

@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'screens/login_screen.dart';
import 'screens/profile_screen.dart';
import 'screens/schedule_screen.dart';
import 'services/auth_service.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => AuthService(),
child: MaterialApp(
title: 'ISO Flutter',
theme: ThemeData.dark().copyWith(
primaryColor: Color(0xFFA24BFA),
scaffoldBackgroundColor: Color(0xFF0c0a0a),
),
initialRoute: '/',
routes: {
'/': (context) => LoginScreen(),
'/profile': (context) => ProfileScreen(),
'/schedule': (context) => ScheduleScreen(),
},
),
);
}
}

View File

@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/auth_service.dart';
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _userCtrl = TextEditingController();
final _pwCtrl = TextEditingController();
bool _loading = false;
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthService>(context);
// Auto-redirect if already logged in
if (auth.token != null) {
Future.microtask(() => Navigator.pushReplacementNamed(context, '/profile'));
}
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Bejelentkezés', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
SizedBox(height: 16),
TextField(controller: _userCtrl, decoration: InputDecoration(labelText: 'Felhasználó')),
SizedBox(height: 8),
TextField(controller: _pwCtrl, decoration: InputDecoration(labelText: 'Jelszó'), obscureText: true),
SizedBox(height: 16),
ElevatedButton(
onPressed: _loading ? null : () async {
final username = _userCtrl.text.trim();
final password = _pwCtrl.text.trim();
if (username.isEmpty || password.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Kérlek add meg a felhasználónevet és jelszót')));
return;
}
setState(() { _loading = true; });
final ok = await auth.login(username, password);
setState(() { _loading = false; });
if (ok) Navigator.pushReplacementNamed(context, '/profile');
else ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Bejelentkezés sikertelen')));
},
child: _loading ? SizedBox(height: 16, width: 16, child: CircularProgressIndicator(strokeWidth: 2)) : Text('Bejelentkezés'),
)
],
),
),
),
);
}
}

View File

@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/auth_service.dart';
class ProfileScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final auth = Provider.of<AuthService>(context);
final profile = auth.profile;
return Scaffold(
appBar: AppBar(title: Text('Profil')),
body: Center(
child: profile == null ? Text('Nincs profil') : Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(profile['FullName'] ?? '', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
SizedBox(height: 8),
Text('UserID: ${profile['UserID'] ?? ''}'),
SizedBox(height: 16),
Row(mainAxisSize: MainAxisSize.min, children: [
ElevatedButton(onPressed: () async { await auth.logout(); Navigator.pushReplacementNamed(context, '/'); }, child: Text('Kijelentkezés')),
SizedBox(width: 12),
ElevatedButton(onPressed: () async { await auth.loadProfile(); }, child: Text('Frissít'))
])
],
),
),
);
}
}

View File

@@ -0,0 +1,96 @@
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();
}
}

View File

@@ -0,0 +1,83 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:http/http.dart' as http;
class AuthService extends ChangeNotifier {
final _storage = const FlutterSecureStorage();
String? token;
Map<String, dynamic>? profile;
final _base = 'https://menuapi.devbeni.lol/api';
AuthService() {
_loadToken();
}
/// Convenience wrapper that returns the Data array for schedule or empty list
Future<List<dynamic>> fetchSchedule(int year, int month) async {
final resp = await _httpGet('/@me/schedule?year=$year&month=$month');
if (resp == null) return [];
try {
if (resp['data'] != null && resp['data']['Data'] is List) {
return List<dynamic>.from(resp['data']['Data']);
}
} catch (e) {
return [];
}
return [];
}
Future<void> loadProfile() async {
if (token == null) return;
final res = await http.get(
Uri.parse('https://menuapi.devbeni.lol/api/me'),
headers: {'Authorization': 'Bearer $token'},
);
if (res.statusCode == 200) {
profile = jsonDecode(res.body)['data'];
notifyListeners();
}
}
Future<bool> login(String username, String password) async {
try {
final res = await http.post(
Uri.parse('$_base/login'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'username': username, 'password': password}),
);
if (res.statusCode != 200) return false;
final data = jsonDecode(res.body);
// token might be in different places; try common keys
token = data['token'] ?? data['access_token'] ?? (data['data'] != null ? data['data']['token'] : null);
if (token == null) return false;
await _storage.write(key: 'token', value: token);
await loadProfile();
notifyListeners();
return true;
} catch (e) {
return false;
}
}
Future<void> logout() async {
token = null;
profile = null;
await _storage.delete(key: 'token');
notifyListeners();
}
Future<dynamic> _httpGet(String path) async {
if (token == null) return null;
final res = await http.get(Uri.parse('$_base$path'), headers: {'Authorization': 'Bearer $token'});
if (res.statusCode == 200) return jsonDecode(res.body);
return null;
}
Future<void> _loadToken() async {
token = await _storage.read(key: 'token');
if (token != null) await loadProfile();
notifyListeners();
}
}