Cant join team if in team Profile page resets properly Post button spam no longer leads to crash due to duplicate calls Housekeeping: Made some name changes moved homescreenpages from layout -> homeFeed Deleted 2 unused classes, authService.dart and old loginPage.dart then renamed startPage.dart -> loginPage.dart Set up openApi on backend and added URL in Service classes
164 lines
5.9 KiB
Dart
164 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:insparkspokalen_ui/models/missionModel.dart';
|
|
import 'package:insparkspokalen_ui/services/backend/missionService.dart';
|
|
|
|
class MissionPage extends StatefulWidget {
|
|
@override
|
|
State<MissionPage> createState() => _MissionViewPageState();
|
|
}
|
|
|
|
class _MissionViewPageState extends State<MissionPage> {
|
|
List<MissionModel> challenges = [];
|
|
bool isLoading = true;
|
|
|
|
final MissionService _missionService = MissionService();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
fetchMissions();
|
|
}
|
|
|
|
Future<void> fetchMissions() async {
|
|
try {
|
|
final missions = await _missionService.fetchMissions();
|
|
setState(() {
|
|
challenges = missions;
|
|
isLoading = false;
|
|
});
|
|
} catch (e) {
|
|
print("Fel vid hämtning: $e");
|
|
setState(() {
|
|
isLoading = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final todaysChallenge = challenges.isNotEmpty ? challenges[0] : null;
|
|
|
|
return Scaffold(
|
|
backgroundColor: Color(0xFF2E2E2E),
|
|
body:
|
|
isLoading
|
|
? Center(
|
|
child: CircularProgressIndicator(color: Color(0XFFFEDF00)),
|
|
)
|
|
: Column(
|
|
children: [
|
|
// Dagens tema-banner
|
|
Container(
|
|
width: double.infinity,
|
|
margin: EdgeInsets.all(16),
|
|
padding: EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFFFEDF00),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
todaysChallenge?.name ?? "Ingen titel",
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
|
|
Text(
|
|
todaysChallenge?.description ?? "Ingen beskrivning",
|
|
style: TextStyle(fontSize: 14),
|
|
),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Text(
|
|
"+ ${todaysChallenge?.points ?? 0} poäng",
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// Tabbar (men bara en aktiv flik just nu)
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
"Kommande Uppdrag",
|
|
style: TextStyle(
|
|
color: Color(0xFFDAA520),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Spacer(),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 8),
|
|
|
|
// Lista med uppdrag
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount:
|
|
challenges.length > 1 ? challenges.length - 1 : 0,
|
|
itemBuilder: (context, index) {
|
|
final challenge = challenges[index + 1];
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16.0,
|
|
vertical: 6.0,
|
|
),
|
|
child: Container(
|
|
padding: EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[900],
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
challenge.name,
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
SizedBox(height: 4),
|
|
Text(
|
|
challenge.description ?? "Ingen beskrivning",
|
|
style: TextStyle(color: Colors.white70),
|
|
),
|
|
SizedBox(height: 8),
|
|
Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: Text(
|
|
"+ ${challenge.points} poäng",
|
|
style: TextStyle(
|
|
color: Color(0xFFFEDF00),
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|