106 lines
3.7 KiB
Dart
106 lines
3.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:insparkspokalen_ui/models/missionModel.dart';
|
|
import 'package:insparkspokalen_ui/services/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) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.black,
|
|
title: Text("Uppdrag", style: TextStyle(color: Colors.white)),
|
|
iconTheme: IconThemeData(color: Colors.white),
|
|
),
|
|
body: isLoading
|
|
? Center(child: CircularProgressIndicator())
|
|
: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: challenges.map((challenge) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
child: Card(
|
|
color: Color(0xFFFEDF00),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: ExpansionTile(
|
|
iconColor: Colors.black,
|
|
collapsedIconColor: Colors.black,
|
|
title: Text(
|
|
challenge.name,
|
|
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
|
|
),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"Deadline: ${challenge.deadline.toString().split(' ')[0]}",
|
|
style: TextStyle(color: Colors.black87),
|
|
),
|
|
Text(
|
|
"Poäng: ${challenge.points}",
|
|
style: TextStyle(color: Colors.black87),
|
|
),
|
|
],
|
|
),
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"Beskrivning:",
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
SizedBox(height: 4),
|
|
Text(
|
|
challenge.description,
|
|
style: TextStyle(color: Colors.black),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |