119 lines
3.1 KiB
Dart
119 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'dart:math'; // hejsan
|
|
|
|
class LeaderboardPage extends StatelessWidget {
|
|
LeaderboardPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List<Map<String, dynamic>> leaderboardData = List.generate(
|
|
6,
|
|
(index) => {'name': _getRandomName(), 'points': _getRandomPoints()},
|
|
);
|
|
|
|
leaderboardData.sort((a, b) => b['points'].compareTo(a['points']));
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Leaderboard')),
|
|
body: Container(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [Color(0xFFA800DB), Color(0xFFFF31E0)],
|
|
),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 8,
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'Användarnamn',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
Text(
|
|
'Poäng',
|
|
style: TextStyle(color: Colors.white, fontSize: 16),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: ListView(
|
|
children:
|
|
leaderboardData.map((entry) {
|
|
return _infoTile(entry['name'], entry['points']);
|
|
}).toList(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _infoTile(String name, int points) {
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(32),
|
|
),
|
|
child: ListTile(
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
name,
|
|
style: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
Text(
|
|
points.toString(),
|
|
style: const TextStyle(color: Colors.black),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
final List<String> randomNames = [
|
|
'aaa',
|
|
'bbb',
|
|
'ccc',
|
|
'ddd',
|
|
'eee',
|
|
'fff',
|
|
'ggg',
|
|
'hhh',
|
|
'iii',
|
|
'jjj',
|
|
];
|
|
|
|
String _getRandomName() {
|
|
return randomNames[Random().nextInt(randomNames.length)];
|
|
}
|
|
|
|
int _getRandomPoints() {
|
|
return Random().nextInt(10000);
|
|
}
|
|
}
|