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 2ae0ffc..8325b89 100644 --- a/Sources/bowlin_project/lib/model/Game.dart +++ b/Sources/bowlin_project/lib/model/Game.dart @@ -1,12 +1,12 @@ class Game { int _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 @@ -16,10 +16,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/IUserManager.dart b/Sources/bowlin_project/lib/model/IUserManager.dart index ab07ec0..883c548 100644 --- a/Sources/bowlin_project/lib/model/IUserManager.dart +++ b/Sources/bowlin_project/lib/model/IUserManager.dart @@ -1,5 +1,6 @@ import 'package:uuid/uuid.dart'; import 'Player.dart'; +import 'User.dart'; import 'IAuthManager.dart'; abstract class IUserManager { diff --git a/Sources/bowlin_project/lib/model/StubManager/StubData.dart b/Sources/bowlin_project/lib/model/StubManager/StubData.dart index 27b6693..a0d4fb1 100644 --- a/Sources/bowlin_project/lib/model/StubManager/StubData.dart +++ b/Sources/bowlin_project/lib/model/StubManager/StubData.dart @@ -24,7 +24,8 @@ class StubData extends IManager { _initRounds(); _initGameDetails(); _initGame(); - + players[8].games = games; + userCurrent = players[8]; } IUserManager get userMgr => _userMgr; @@ -42,7 +43,7 @@ class StubData extends IManager { User( 8, "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"), @@ -55,7 +56,7 @@ class StubData extends IManager { User( 9, "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"), @@ -105,8 +106,14 @@ class StubData extends IManager { List _games = []; void _initGame() { - games.add(Game(gameDetails[0].id, DateTime.now(), 123, true, [])); - games.add(Game(gameDetails[1].id, DateTime.now(), 101, true, [])); + games.add(Game( + gameDetails[0].id, + DateTime.now().subtract(Duration(days: 14)), + 123, + true, + [players[0].id, players[1].id])); + games.add(Game(gameDetails[1].id, DateTime.now(), 101, true, + [players[1].id, players[0].id])); } List get games => _games; diff --git a/Sources/bowlin_project/lib/model/StubManager/UserManager.dart b/Sources/bowlin_project/lib/model/StubManager/UserManager.dart index bdbcdef..a90bceb 100644 --- a/Sources/bowlin_project/lib/model/StubManager/UserManager.dart +++ b/Sources/bowlin_project/lib/model/StubManager/UserManager.dart @@ -1,6 +1,8 @@ library StubLib; + import '../IUserManager.dart'; import '../IAuthManager.dart'; +import '../Player.dart'; import 'AuthManager.dart'; import 'StubData.dart'; import '../Player.dart'; @@ -10,7 +12,7 @@ class UserManager extends IUserManager { final StubData parent; // Constructor - UserManager(this.parent):super(AuthManager(parent)); + UserManager(this.parent) : super(AuthManager(parent)); // Methods List getUsersByName(String name) { @@ -35,4 +37,4 @@ class UserManager extends IUserManager { } throw new Exception("Player not found"); } -} \ No newline at end of file +} 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..4b70297 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, 3, 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, @@ -77,13 +86,17 @@ class CardGame extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Toast(), - Toast(), - ], - ), + Padding( + padding: EdgeInsets.fromLTRB(5, 5, 10, 3), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Toast( + value: DateFormat('dd MMMM', 'fr_FR') + .format(game.date)), + Toast(value: DateFormat('HH:mm').format(game.date)), + ], + )), Stack( children: [ Row( @@ -93,25 +106,23 @@ class CardGame extends StatelessWidget { Padding( padding: EdgeInsets.fromLTRB(25, 15, 0, 0), child: SizedBox( - width: 130, - child: Wrap( - spacing: 5, - runSpacing: 5, - children: [ - ProfilPicture(), - ProfilPicture(), - ProfilPicture(), - ProfilPicture(), - ProfilPicture(), - ProfilPicture(), - ], - ), - )), + width: 130, + child: Wrap( + spacing: 5, + runSpacing: 5, + children: game.playersId + .map((item) => ProfilPicture( + path: MyApp.controller.userMgr + .getUserById(item) + .image, + )) + .toList(), + ))), Spacer(), Padding( padding: EdgeInsets.fromLTRB(0, 30, 15, 0), child: GradientText( - "125", + game.pointsCurrentUser.toString(), style: TextStyle( fontSize: 40.0, fontWeight: FontWeight.w900, @@ -151,36 +162,27 @@ 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]); + }, )); } } class ProfilPicture extends StatelessWidget { + final String path; + + const ProfilPicture({Key? key, required this.path}) : super(key: key); @override Widget build(BuildContext context) { return Container( height: 25, width: 25, decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("assets/images/image_user_green.png"), - fit: BoxFit.cover), + image: DecorationImage(image: AssetImage(path), fit: BoxFit.cover), borderRadius: BorderRadius.all(Radius.circular(20)), ), ); @@ -188,6 +190,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 +205,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 445d36e..67e2bc8 100644 --- a/Sources/bowlin_project/pubspec.lock +++ b/Sources/bowlin_project/pubspec.lock @@ -192,6 +192,13 @@ packages: url: "https://pub.dev" 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: