feat: Add splash screen and update routing to include it
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
|
||||
import 'screens/login_screen.dart';
|
||||
import 'screens/profile_screen.dart';
|
||||
import 'screens/schedule_screen.dart';
|
||||
import 'screens/splash_screen.dart';
|
||||
import 'services/auth_service.dart';
|
||||
|
||||
void main() {
|
||||
@@ -21,8 +22,9 @@ class MyApp extends StatelessWidget {
|
||||
primaryColor: Color(0xFFA24BFA),
|
||||
scaffoldBackgroundColor: Color(0xFF0c0a0a),
|
||||
),
|
||||
initialRoute: '/',
|
||||
initialRoute: '/splash',
|
||||
routes: {
|
||||
'/splash': (context) => SplashScreen(),
|
||||
'/': (context) => LoginScreen(),
|
||||
'/profile': (context) => ProfileScreen(),
|
||||
'/schedule': (context) => ScheduleScreen(),
|
||||
|
||||
@@ -13,6 +13,7 @@ class _ScheduleScreenState extends State<ScheduleScreen> {
|
||||
DateTime currentWeek = DateTime.now();
|
||||
bool loading = false;
|
||||
List<dynamic> workdays = [];
|
||||
String? errorMsg;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -31,34 +32,48 @@ class _ScheduleScreenState extends State<ScheduleScreen> {
|
||||
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(),
|
||||
);
|
||||
})
|
||||
)
|
||||
if (errorMsg != null) ...[
|
||||
Text(errorMsg!, style: TextStyle(color: Colors.red)),
|
||||
SizedBox(height: 8),
|
||||
ElevatedButton(onPressed: fetchWorkdays, child: Text('Próbálja újra')),
|
||||
SizedBox(height: 8),
|
||||
],
|
||||
loading
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
: Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: fetchWorkdays,
|
||||
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(),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
65
lib/screens/splash_screen.dart
Normal file
65
lib/screens/splash_screen.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
@override
|
||||
_SplashScreenState createState() => _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> with SingleTickerProviderStateMixin {
|
||||
late AnimationController _ctrl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ctrl = AnimationController(vsync: this, duration: Duration(seconds: 3))..repeat(reverse: true);
|
||||
// simulate load then navigate
|
||||
Timer(Duration(seconds: 2), () {
|
||||
Navigator.pushReplacementNamed(context, '/');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFF0c0a0a),
|
||||
body: Center(
|
||||
child: AnimatedBuilder(
|
||||
animation: _ctrl,
|
||||
builder: (ctx, child) {
|
||||
final t = _ctrl.value;
|
||||
return Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
// liquid-ish blurred circles
|
||||
Container(
|
||||
width: 220 + 40 * t,
|
||||
height: 220 + 40 * (1 - t),
|
||||
decoration: BoxDecoration(
|
||||
gradient: RadialGradient(colors: [Color(0xFFB388FF).withOpacity(0.25), Colors.transparent]),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 140 + 60 * (1 - t),
|
||||
height: 140 + 60 * t,
|
||||
decoration: BoxDecoration(
|
||||
gradient: RadialGradient(colors: [Color(0xFFA24BFA).withOpacity(0.6), Color(0xFF5E2FD3).withOpacity(0.2)]),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
Text('mcbeno', style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold, color: Colors.white)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -69,10 +69,25 @@ class AuthService extends ChangeNotifier {
|
||||
}
|
||||
|
||||
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;
|
||||
if (token == null) {
|
||||
if (kDebugMode) print('[AuthService] _httpGet called without token for $path');
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final res = await http.get(Uri.parse('$_base$path'), headers: {'Authorization': 'Bearer $token'});
|
||||
if (res.statusCode == 200) {
|
||||
return jsonDecode(res.body);
|
||||
} else {
|
||||
if (kDebugMode) {
|
||||
print('[AuthService] GET $path -> ${res.statusCode}');
|
||||
print('[AuthService] response body: ${res.body}');
|
||||
}
|
||||
throw Exception('HTTP ${res.statusCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
if (kDebugMode) print('[AuthService] _httpGet error: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadToken() async {
|
||||
|
||||
Reference in New Issue
Block a user