diff --git a/Sources/bowlin_project/lib/main.dart b/Sources/bowlin_project/lib/main.dart index eb7f158..1046f67 100644 --- a/Sources/bowlin_project/lib/main.dart +++ b/Sources/bowlin_project/lib/main.dart @@ -8,11 +8,15 @@ import 'package:flutter/services.dart'; import 'package:go_router/go_router.dart'; import 'package:bowl_in/config/app_router.dart'; +import 'model/IManager.dart'; +import 'model/StubManager/StubData.dart'; + void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { + static IManager controller = StubData(); const MyApp({super.key}); @override Widget build(BuildContext context) { diff --git a/Sources/bowlin_project/lib/model/Game.dart b/Sources/bowlin_project/lib/model/Game.dart index 16cc875..aeeb35e 100644 --- a/Sources/bowlin_project/lib/model/Game.dart +++ b/Sources/bowlin_project/lib/model/Game.dart @@ -2,13 +2,13 @@ import 'package:uuid/uuid.dart'; class Game { Uuid _id; - DateTime _time; + DateTime _date; int _pointsCurrentUser; bool _isFinished; List _playersId = []; // Constructor - Game(this._id, this._time, this._pointsCurrentUser, this._isFinished, + Game(this._id, this._date, this._pointsCurrentUser, this._isFinished, this._playersId); // Getters and setters @@ -18,10 +18,10 @@ class Game { _id = value; } - DateTime get time => _time; + DateTime get date => _date; - set time(DateTime value) { - _time = value; + set date(DateTime value) { + _date = value; } int get pointsCurrentUser => _pointsCurrentUser; diff --git a/Sources/bowlin_project/lib/model/IManager.dart b/Sources/bowlin_project/lib/model/IManager.dart index aca3c7a..f30f996 100644 --- a/Sources/bowlin_project/lib/model/IManager.dart +++ b/Sources/bowlin_project/lib/model/IManager.dart @@ -9,9 +9,14 @@ abstract class IManager { late Game _gameCurrent; late IUserManager _userMgr; late IGameManager _gameMgr; - + // Getters and setters User get userCurrent => _userCurrent; + + set userCurrent(User user) { + _userCurrent = user; + } + Game get gameCurrent => _gameCurrent; IUserManager get userMgr => _userMgr; IGameManager get gameMgr => _gameMgr; diff --git a/Sources/bowlin_project/lib/model/StubManager/StubData.dart b/Sources/bowlin_project/lib/model/StubManager/StubData.dart index 0be09df..88a5efe 100644 --- a/Sources/bowlin_project/lib/model/StubManager/StubData.dart +++ b/Sources/bowlin_project/lib/model/StubManager/StubData.dart @@ -25,6 +25,8 @@ class StubData extends IManager { _initRounds(); _initGameDetails(); _initGame(); + users[1].games = games; + userCurrent = users[1]; } List players = [ @@ -41,7 +43,7 @@ class StubData extends IManager { User( Uuid(), "Emre", - "https://fastly.picsum.photos/id/1060/2000/2000.jpg?hmac=_RrU8GpkCDUlVKfgyWE-GcX-GS5TKNyUzdFbJAGXHV4", + "./assets/images/image_user_cyan.png", "emre.kartal@etu.uca.fr", [ Achievement("5 games"), @@ -53,7 +55,7 @@ class StubData extends IManager { User( Uuid(), "Dave", - "https://fastly.picsum.photos/id/820/2000/2000.jpg?hmac=Ctxx2feJNZnG1S7UPx_YrWcEw89tKb7fR8i1W-VTOz4", + "./assets/images/image_user_cyan.png", "david.d_almeida@etu.uca.fr", [ Achievement("5 games"), @@ -99,7 +101,8 @@ class StubData extends IManager { List games = []; void _initGame() { - games.add(Game(gameDetails[0].id, DateTime.now(), 123, true, [])); + games.add(Game(gameDetails[0].id, + DateTime.now().subtract(Duration(days: 14)), 123, true, [])); games.add(Game(gameDetails[1].id, DateTime.now(), 101, true, [])); } } diff --git a/Sources/bowlin_project/lib/views/analysis_screen.dart b/Sources/bowlin_project/lib/views/analysis_screen.dart index 7defc1f..77992da 100644 --- a/Sources/bowlin_project/lib/views/analysis_screen.dart +++ b/Sources/bowlin_project/lib/views/analysis_screen.dart @@ -1,3 +1,4 @@ +import 'package:bowl_in/main.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -42,15 +43,18 @@ class _AnalysisScreenState extends State { children: [ Positioned( left: 34, - child: SpareCard(score: 12), + child: SpareCard( + score: MyApp.controller.userCurrent.stat.nbSpares), ), Positioned( top: 0, - child: StrikeCard(score: 12), + child: StrikeCard( + score: MyApp.controller.userCurrent.stat.nbStrikes), ), Positioned( right: 34, - child: GameCard(score: 12), + child: GameCard( + score: MyApp.controller.userCurrent.stat.nbGames), ) ], ), diff --git a/Sources/bowlin_project/lib/widgets/achievements_list_widget.dart b/Sources/bowlin_project/lib/widgets/achievements_list_widget.dart index b79be72..fe29292 100644 --- a/Sources/bowlin_project/lib/widgets/achievements_list_widget.dart +++ b/Sources/bowlin_project/lib/widgets/achievements_list_widget.dart @@ -1,3 +1,4 @@ +import 'package:bowl_in/main.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -152,7 +153,7 @@ class ProfileWidget extends StatelessWidget { width: 80, decoration: BoxDecoration( image: DecorationImage( - image: AssetImage("assets/images/image_user_orange.png"), + image: AssetImage(MyApp.controller.userCurrent.image), fit: BoxFit.cover), borderRadius: BorderRadius.all(Radius.circular(100)), ), @@ -163,7 +164,7 @@ class ProfileWidget extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - "Lucas", + MyApp.controller.userCurrent.name, style: GoogleFonts.roboto( color: Colors.white, fontStyle: FontStyle.italic, @@ -186,7 +187,9 @@ class ProfileWidget extends StatelessWidget { fontSize: 15), ), TextSpan( - text: "122 pts", + text: MyApp.controller.userCurrent.stat.highscore + .toString() + + " pts", style: GoogleFonts.roboto( color: Color(0xffF40375).withOpacity(0.75), fontStyle: FontStyle.italic, @@ -197,38 +200,44 @@ class ProfileWidget extends StatelessWidget { ), ), ), - RichText( - text: TextSpan( - text: '', - style: DefaultTextStyle.of(context).style, - children: [ - TextSpan( - text: "Last game ", - style: GoogleFonts.roboto( - color: Colors.white.withOpacity(0.65), - fontStyle: FontStyle.italic, - fontWeight: FontWeight.bold, - fontSize: 15), - ), - TextSpan( - text: "23", - style: GoogleFonts.roboto( - color: Colors.white, - fontStyle: FontStyle.italic, - fontWeight: FontWeight.bold, - fontSize: 15), - ), - TextSpan( - text: " days(s) ago", - style: GoogleFonts.roboto( - color: Colors.white.withOpacity(0.65), - fontStyle: FontStyle.italic, - fontWeight: FontWeight.bold, - fontSize: 15), - ), - ], - ), - ), + MyApp.controller.userCurrent.games.length > 0 + ? RichText( + text: TextSpan( + text: '', + style: DefaultTextStyle.of(context).style, + children: [ + TextSpan( + text: "Last game ", + style: GoogleFonts.roboto( + color: Colors.white.withOpacity(0.65), + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, + fontSize: 15), + ), + TextSpan( + text: DateTime.now() + .difference(MyApp + .controller.userCurrent.games.first.date) + .inDays + .toString(), + style: GoogleFonts.roboto( + color: Colors.white, + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, + fontSize: 15), + ), + TextSpan( + text: " days(s) ago", + style: GoogleFonts.roboto( + color: Colors.white.withOpacity(0.65), + fontStyle: FontStyle.italic, + fontWeight: FontWeight.bold, + fontSize: 15), + ), + ], + ), + ) + : Container(), ], ), ) diff --git a/Sources/bowlin_project/lib/widgets/scores_list_widget.dart b/Sources/bowlin_project/lib/widgets/scores_list_widget.dart index 01e20c2..f2acc8f 100644 --- a/Sources/bowlin_project/lib/widgets/scores_list_widget.dart +++ b/Sources/bowlin_project/lib/widgets/scores_list_widget.dart @@ -1,13 +1,22 @@ +import 'package:bowl_in/main.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:intl/date_symbol_data_local.dart'; +import 'package:intl/intl.dart'; import 'package:simple_gradient_text/simple_gradient_text.dart'; +import '../model/Game.dart'; + class CardGame extends StatelessWidget { + final Game game; + + const CardGame({Key? key, required this.game}) : super(key: key); @override Widget build(BuildContext context) { + initializeDateFormatting(); return Padding( padding: EdgeInsets.fromLTRB(41, 0, 41, 10), child: GestureDetector( @@ -29,7 +38,7 @@ class CardGame extends StatelessWidget { ), ), child: Padding( - padding: EdgeInsets.fromLTRB(130, 3, 0, 0), + padding: EdgeInsets.fromLTRB(120, 3, 0, 0), child: ClipRect( clipBehavior: Clip.hardEdge, child: Opacity( @@ -37,7 +46,7 @@ class CardGame extends StatelessWidget { child: Stack( children: [ GradientText( - "125", + game.pointsCurrentUser.toString(), style: GoogleFonts.karla( fontSize: 105.0, fontWeight: FontWeight.w900, @@ -56,7 +65,7 @@ class CardGame extends StatelessWidget { ], ), GradientText( - "125", + game.pointsCurrentUser.toString(), style: GoogleFonts.karla( fontSize: 105.0, fontWeight: FontWeight.w900, @@ -80,8 +89,10 @@ class CardGame extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - Toast(), - Toast(), + Toast( + value: + DateFormat('dd MMMM', 'fr_FR').format(game.date)), + Toast(value: DateFormat('HH:mm').format(game.date)), ], ), Stack( @@ -111,7 +122,7 @@ class CardGame extends StatelessWidget { Padding( padding: EdgeInsets.fromLTRB(0, 30, 15, 0), child: GradientText( - "125", + game.pointsCurrentUser.toString(), style: TextStyle( fontSize: 40.0, fontWeight: FontWeight.w900, @@ -151,22 +162,12 @@ class ListCardGame extends StatelessWidget { Widget build(BuildContext context) { return ScrollConfiguration( behavior: CustomScroll(), - child: ListView( + child: ListView.builder( shrinkWrap: false, - children: [ - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - CardGame(), - ], + itemCount: MyApp.controller.userCurrent.games.length, + itemBuilder: (BuildContext context, int index) { + return CardGame(game: MyApp.controller.userCurrent.games[index]); + }, )); } } @@ -188,6 +189,9 @@ class ProfilPicture extends StatelessWidget { } class Toast extends StatelessWidget { + final String value; + + const Toast({Key? key, required this.value}) : super(key: key); @override Widget build(BuildContext context) { return Padding( @@ -200,7 +204,7 @@ class Toast extends StatelessWidget { child: Padding( padding: EdgeInsets.fromLTRB(11.0, 3, 11.0, 3), child: Text( - "12 janv.", + value, style: TextStyle( fontSize: 10, color: Colors.white, diff --git a/Sources/bowlin_project/pubspec.lock b/Sources/bowlin_project/pubspec.lock index 581d755..da29b07 100644 --- a/Sources/bowlin_project/pubspec.lock +++ b/Sources/bowlin_project/pubspec.lock @@ -170,6 +170,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.3.0" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.18.0" js: dependency: transitive description: diff --git a/Sources/bowlin_project/pubspec.yaml b/Sources/bowlin_project/pubspec.yaml index 6b6031d..d4df740 100644 --- a/Sources/bowlin_project/pubspec.yaml +++ b/Sources/bowlin_project/pubspec.yaml @@ -40,6 +40,8 @@ dependencies: google_fonts: ^3.0.1 go_router: ^6.0.1 uuid: ^3.0.7 + intl: ^0.18.0 + dev_dependencies: flutter_test: