import 'package:flutter/material.dart'; import 'package:testmoduled/username.dart'; List dishList = [ "fg", "mk", "pf", "fish", "gt" ]; Map mapData ={ "fg":{ 'score':10, "assets":"Baguette.png" }, "mk":{ 'score':20, "assets":"macaron.png" }, 'pf':{ 'score':30, 'assets':"puff.png" }, 'fish':{ "score":-20, "assets":"fishbone.png" }, "gt":{ "score":-10, "assets":"bone.png" } }; class ScoreModal{ late int score; late int duration; late String name; ScoreModal(this.score,this.duration,this.name); static int compare(ScoreModal a,ScoreModal b){ if(a.score>b.score){ return b.score.compareTo(a.score); }else if(a.duration>b.duration){ return a.duration.compareTo(b.duration); }else{ return 0; } } } List rankList = [ ScoreModal(20, 40, "dasd"), ScoreModal(43, 43, "saas"), ScoreModal(32, 223, "fd"), ScoreModal(2112, 323, "dasdasdd"), ]; class Ranking extends StatefulWidget { const Ranking({super.key}); @override State createState() => _RankingState(); } class _RankingState extends State { @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, body: DefaultTextStyle( style: TextStyle(fontSize: 18,fontWeight: FontWeight.w500,color: Colors.black87), child: Column( children: [ Row( children: ["Rank","name","Time","Score"].map((e) => Text(e)).toList(), ), myRankingList(), myButton(50, 220, "Tap To Retry", Colors.black87, () => Navigator.of(context).push(MaterialPageRoute(builder: (c)=>userName()))) ], ), ) ); } myRankingList(){ rankList.sort(ScoreModal.compare); int rank = 1; return Column( children: List.generate(rankList.length, (index){ if(index>0){ if(rankList[index].duration==rankList[index-1].duration && rankList[index].score==rankList[index-1].score){ }else{ rank++; } } return Row( children: [ Text("$rank"), Text(rankList[index].name), Text("Time: ${((rankList[index]).duration~/60).toString().padLeft(2,"0")}:${((rankList[index]).duration%60).toString().padLeft(2,"0")}",style: TextStyle(fontSize: 16,fontWeight: FontWeight.w500,color: Colors.black87),) ,Text(rankList[index].score.toString()), ], ); }) ); } } myButton(double height,double width,String text,Color backColor,Function()? onTap){ return GestureDetector( onTap: onTap, child: Container( alignment: Alignment.center, height: height, width: width, decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), border: Border.all(width: 1,color: Colors.black54), color: backColor ), child: Text(text,style: TextStyle(fontSize: 14,fontWeight: FontWeight.w500,color: Colors.white)) ), ); }