Insparkspokalen-ui/lib/info/informationPage.dart
2025-05-13 15:06:22 +02:00

82 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../models/informationModel.dart';
import '../services/informationService.dart';
class InformationPage extends StatefulWidget {
const InformationPage({Key? key}) : super(key: key);
@override
State<InformationPage> createState() => _InformationPageState();
}
class _InformationPageState extends State<InformationPage> {
final InformationService _infoService = InformationService();
List<InformationModel> _infoList = [];
@override
void initState() {
super.initState();
fetchAndSetInformation();
}
Future<void> fetchAndSetInformation() async {
try {
final info = await _infoService.fetchInformation();
setState(() => _infoList = info);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Kunde inte ladda information")),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF2E2E2E),
appBar: AppBar(
backgroundColor: const Color(0xFF2E2E2E),
title: const Text(
"Information",
style: TextStyle(color: Color(0xFFDAA520)),
),
iconTheme: const IconThemeData(color: Color(0xFFDAA520)),
),
body: _infoList.isEmpty
? const Center(
child: CircularProgressIndicator(color: Color(0xFFDAA520)),
)
: ListView.builder(
itemCount: _infoList.length,
itemBuilder: (context, index) {
final info = _infoList[index];
return Card(
color: Colors.grey[850],
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: ListTile(
title: Text(
info.title,
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 4),
Text(info.content, style: const TextStyle(color: Colors.white70)),
const SizedBox(height: 6),
Text("Av: ${info.author}", style: const TextStyle(color: Colors.white54)),
Text(
DateFormat('yyyy-MM-dd HH:mm').format(info.createdAt),
style: const TextStyle(color: Colors.white38, fontSize: 12),
),
],
),
),
);
},
),
);
}
}