// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, file_names, use_build_context_synchronously, library_private_types_in_public_api import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:smilet/LoginPage.dart'; import 'package:smilet/User.dart'; import 'package:smilet/StartPage.dart'; import 'dart:async'; import 'package:http/http.dart' as http; // Get points for the user Future getPoints(String username) async { var response = await http .get(Uri.parse("http://group-15-3.pvt.dsv.su.se/points/$username")); if (response.statusCode == 200) { // If the server did return a 200 OK response, // then parse the JSON. return jsonDecode(utf8.decode(response.bodyBytes)) as int; } else { // If the server did not return a 200 OK response, // then return 0. return 0; } } class Profile extends StatefulWidget { final User user; final Map schoolDetails; const Profile({super.key, required this.user, required this.schoolDetails}); @override _ProfileState createState() => _ProfileState(); } class _ProfileState extends State { late Future futurePoints; String file = ""; @override void initState() { super.initState(); futurePoints = getPoints(user.getUsername()); } @override Widget build(BuildContext context) { switch (schoolDetails["school"].toString().toUpperCase()) { case 'SU': { file = "SULogga"; break; } case 'KTH': { file = "KTHlogga"; break; } case 'UU': { file = "UUlogga"; break; } case 'KI': { file = "KIlogga"; break; } } return Center( child: Column(children: [ SizedBox( height: 50.0, ), Text(user.getUsername(), style: TextStyle( color: Colors.white, fontSize: 30, fontWeight: FontWeight.bold, )), SizedBox( height: 60.0, ), Container( width: 180.0, height: 180.0, decoration: BoxDecoration( color: Colors.white, shape: BoxShape.circle, border: Border.all( width: 2.0, ), ), child: Padding( padding: const EdgeInsets.all(5), child: SizedBox( width: 150, height: 150, child: Image.asset('assets/images/$file.png', fit: BoxFit.fitHeight), ), ), ), SizedBox(height: 60), Padding( padding: const EdgeInsets.only(left: 110), child: Row( children: [ Icon(Icons.school), Text( ' Universitet: ${schoolDetails["school"].toString().toUpperCase()}', style: TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold, )), ], ), ), SizedBox(height: 5), Padding( padding: const EdgeInsets.only(left: 110), child: Row( children: [ Icon(Icons.account_balance), Text( ' Institution: ${schoolDetails["institution"].toString().toUpperCase()}', style: TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold, )), ], ), ), SizedBox(height: 5), FutureBuilder( future: futurePoints, builder: (context, snapshot) { if (snapshot.hasData) { return Padding( padding: const EdgeInsets.only(left: 110), child: Row( children: [ Icon(Icons.star), Text(' Dina poäng: ${snapshot.data!.toString()}', style: TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold, )), ], ), ); } else if (snapshot.hasError) { return Text('${snapshot.error}'); } else { return Padding( padding: const EdgeInsets.only(left: 110), child: Row( children: [ Icon(Icons.star), Text(' Dina poäng:', style: TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold, )), ], ), ); } }), Spacer(), ElevatedButton( style: TextButton.styleFrom( backgroundColor: Color.fromARGB(255, 233, 52, 52), fixedSize: Size(130, 40), ), onPressed: () { Navigator.push(context, MaterialPageRoute(builder: (context) => StartPage())); }, child: Text('Logga ut', style: TextStyle(fontSize: 15, color: Colors.white))), SizedBox(height: 10) ]), ); } }