diff --git a/lib/api/api.dart b/lib/api/api.dart index c8d9e8d..24797b6 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -360,8 +360,8 @@ class PostPlayerFeslidAPI extends APIBase { } class BFPlayInfoAPI extends APIBase { - Future fetchBFPlayInfo(String playerId) async { - final String url = '$gametoolsBaseAPI/bfglobal/games/?playerid=$playerId'; + Future fetchBFPlayInfo(String name) async { + final String url = '$gametoolsBaseAPI/bfglobal/games/?name=$name'; try { final response = await http.get(Uri.parse(url)).timeout(timeout); diff --git a/lib/screen/player_info_screen.dart b/lib/screen/player_info_screen.dart index 4a3fab7..2d7bb28 100644 --- a/lib/screen/player_info_screen.dart +++ b/lib/screen/player_info_screen.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:battlefield_2042_state/api/api.dart'; import 'package:battlefield_2042_state/api/gametools/bf_play_info.dart'; import 'package:battlefield_2042_state/api/gametools/player_feslid.dart'; @@ -43,9 +45,10 @@ class PlayerInfoScreen extends StatelessWidget { PlayerInfoScreen({super.key}); - Future getBFPlayInfo(String playerId) async { + Future getBFPlayInfo(String name) async { + log(name); try { - BFPlayInfo bfPlayInfo = await bfPlayInfoAPI.fetchBFPlayInfo(playerId); + BFPlayInfo bfPlayInfo = await bfPlayInfoAPI.fetchBFPlayInfo(name); return bfPlayInfo; } catch (e) { return null; @@ -55,8 +58,7 @@ class PlayerInfoScreen extends StatelessWidget { Future getPlayerFeslid( String platform, String personaId, - String nucleusId, - ) async { + String nucleusId,) async { // pc: 1, psn: 2, xboxseries: 3 String platformId = '1'; switch (platform) { @@ -85,11 +87,11 @@ class PlayerInfoScreen extends StatelessWidget { } } - void onInfoButtonPressed(BuildContext context, String playerId) { + void onInfoButtonPressed(BuildContext context, String name) { ConstraintsModalBottomSheet.showConstraintsModalBottomSheet( context, FutureBuilder( - future: getBFPlayInfo(playerId), + future: getBFPlayInfo(name), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return Row( @@ -121,86 +123,86 @@ class PlayerInfoScreen extends StatelessWidget { } else if (snapshot.connectionState == ConnectionState.done) { return snapshot.data == null ? Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - children: [ - Text( - AppLocalizations.of(context)! - .playerBFHistorySearchingError, - style: Theme.of(context).textTheme.bodyMedium, - softWrap: true, - textAlign: TextAlign.center, - ), - ], - ) + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + children: [ + Text( + AppLocalizations.of(context)! + .playerBFHistorySearchingError, + style: Theme.of(context).textTheme.bodyMedium, + softWrap: true, + textAlign: TextAlign.center, + ), + ], + ) : Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - children: [ - Text( - AppLocalizations.of(context)!.playerBFHistoryTitle, - style: Theme.of(context).textTheme.titleMedium, - ), - const Padding(padding: EdgeInsets.only(top: 8)), - InfoListItem( - keyName: AppLocalizations.of(context)!.battlefield3, - showValueString: snapshot.data!.bf3 - ? AppLocalizations.of(context)! - .playerBFHistoryPlayed - : AppLocalizations.of(context)! - .playerBFHistoryNotPlayed, - textColor: snapshot.data!.bf3 - ? Theme.of(context).colorScheme.primary - : Theme.of(context).colorScheme.error, - ), - InfoListItem( - keyName: AppLocalizations.of(context)!.battlefield4, - showValueString: snapshot.data!.bf4 - ? AppLocalizations.of(context)! - .playerBFHistoryPlayed - : AppLocalizations.of(context)! - .playerBFHistoryNotPlayed, - textColor: snapshot.data!.bf4 - ? Theme.of(context).colorScheme.primary - : Theme.of(context).colorScheme.error, - ), - InfoListItem( - keyName: AppLocalizations.of(context)!.battlefieldH, - showValueString: snapshot.data!.bfh - ? AppLocalizations.of(context)! - .playerBFHistoryPlayed - : AppLocalizations.of(context)! - .playerBFHistoryNotPlayed, - textColor: snapshot.data!.bfh - ? Theme.of(context).colorScheme.primary - : Theme.of(context).colorScheme.error, - ), - InfoListItem( - keyName: AppLocalizations.of(context)!.battlefield1, - showValueString: snapshot.data!.bf1 - ? AppLocalizations.of(context)! - .playerBFHistoryPlayed - : AppLocalizations.of(context)! - .playerBFHistoryNotPlayed, - textColor: snapshot.data!.bf1 - ? Theme.of(context).colorScheme.primary - : Theme.of(context).colorScheme.error, - ), - InfoListItem( - keyName: AppLocalizations.of(context)!.battlefieldV, - showValueString: snapshot.data!.bfv - ? AppLocalizations.of(context)! - .playerBFHistoryPlayed - : AppLocalizations.of(context)! - .playerBFHistoryNotPlayed, - textColor: snapshot.data!.bfv - ? Theme.of(context).colorScheme.primary - : Theme.of(context).colorScheme.error, - ), - ], - ); + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + AppLocalizations.of(context)!.playerBFHistoryTitle, + style: Theme.of(context).textTheme.titleMedium, + ), + const Padding(padding: EdgeInsets.only(top: 8)), + InfoListItem( + keyName: AppLocalizations.of(context)!.battlefield3, + showValueString: snapshot.data!.bf3 + ? AppLocalizations.of(context)! + .playerBFHistoryPlayed + : AppLocalizations.of(context)! + .playerBFHistoryNotPlayed, + textColor: snapshot.data!.bf3 + ? Theme.of(context).colorScheme.primary + : Theme.of(context).colorScheme.error, + ), + InfoListItem( + keyName: AppLocalizations.of(context)!.battlefield4, + showValueString: snapshot.data!.bf4 + ? AppLocalizations.of(context)! + .playerBFHistoryPlayed + : AppLocalizations.of(context)! + .playerBFHistoryNotPlayed, + textColor: snapshot.data!.bf4 + ? Theme.of(context).colorScheme.primary + : Theme.of(context).colorScheme.error, + ), + InfoListItem( + keyName: AppLocalizations.of(context)!.battlefieldH, + showValueString: snapshot.data!.bfh + ? AppLocalizations.of(context)! + .playerBFHistoryPlayed + : AppLocalizations.of(context)! + .playerBFHistoryNotPlayed, + textColor: snapshot.data!.bfh + ? Theme.of(context).colorScheme.primary + : Theme.of(context).colorScheme.error, + ), + InfoListItem( + keyName: AppLocalizations.of(context)!.battlefield1, + showValueString: snapshot.data!.bf1 + ? AppLocalizations.of(context)! + .playerBFHistoryPlayed + : AppLocalizations.of(context)! + .playerBFHistoryNotPlayed, + textColor: snapshot.data!.bf1 + ? Theme.of(context).colorScheme.primary + : Theme.of(context).colorScheme.error, + ), + InfoListItem( + keyName: AppLocalizations.of(context)!.battlefieldV, + showValueString: snapshot.data!.bfv + ? AppLocalizations.of(context)! + .playerBFHistoryPlayed + : AppLocalizations.of(context)! + .playerBFHistoryNotPlayed, + textColor: snapshot.data!.bfv + ? Theme.of(context).colorScheme.primary + : Theme.of(context).colorScheme.error, + ), + ], + ); } else { return Row( mainAxisAlignment: MainAxisAlignment.center, @@ -226,150 +228,150 @@ class PlayerInfoScreen extends StatelessWidget { return Scaffold( appBar: AppBar( title: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox( - width: 42, - height: 42, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - ), - clipBehavior: Clip.antiAlias, - child: FutureBuilder( - future: getPlayerFeslid( - playerInfo.platform ?? '1', - playerInfo.playerInfoEnsemble.personaId, - playerInfo.playerInfoEnsemble.nucleusId, + scrollDirection: Axis.horizontal, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox( + width: 42, + height: 42, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), ), - builder: (context, snapshot) { - if (snapshot.connectionState == - ConnectionState.waiting) { - return SpinKitCubeGrid( - size: 24, - color: Theme.of(context).colorScheme.primary, - ); - } else if (snapshot.connectionState == - ConnectionState.done) { - if (snapshot.data == null) { - return Image.asset( - 'assets/avatar_span.png', - fit: BoxFit.cover, - ); - } else { - return Image.network( - snapshot.data!.avatar ?? - 'assets/avatar_span.png', - fit: BoxFit.cover, - errorBuilder: (context, error, stackTrace) { + clipBehavior: Clip.antiAlias, + child: FutureBuilder( + future: getPlayerFeslid( + playerInfo.platform ?? '1', + playerInfo.playerInfoEnsemble.personaId, + playerInfo.playerInfoEnsemble.nucleusId, + ), + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.waiting) { + return SpinKitCubeGrid( + size: 24, + color: Theme.of(context).colorScheme.primary, + ); + } else if (snapshot.connectionState == + ConnectionState.done) { + if (snapshot.data == null) { return Image.asset( 'assets/avatar_span.png', fit: BoxFit.cover, - cacheHeight: 42, - cacheWidth: 42, ); - }, - loadingBuilder: - (context, child, loadingProgress) { - if (loadingProgress == null) { - return child; - } else { - return SpinKitCubeGrid( - size: 24, - color: Theme.of(context) - .colorScheme - .primary, - ); - } - }, - ); - } - } else { - return Image.asset( - 'assets/avatar_span.png', - fit: BoxFit.cover, - ); - } - }))), - const Padding(padding: EdgeInsets.only(left: 8)), - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - FittedBox( - child: Text( - playerInfo.playerInfoEnsemble.username, - style: TextStyle( - fontSize: + } else { + return Image.network( + snapshot.data!.avatar ?? + 'assets/avatar_span.png', + fit: BoxFit.cover, + errorBuilder: (context, error, stackTrace) { + return Image.asset( + 'assets/avatar_span.png', + fit: BoxFit.cover, + cacheHeight: 42, + cacheWidth: 42, + ); + }, + loadingBuilder: + (context, child, loadingProgress) { + if (loadingProgress == null) { + return child; + } else { + return SpinKitCubeGrid( + size: 24, + color: Theme.of(context) + .colorScheme + .primary, + ); + } + }, + ); + } + } else { + return Image.asset( + 'assets/avatar_span.png', + fit: BoxFit.cover, + ); + } + }))), + const Padding(padding: EdgeInsets.only(left: 8)), + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + FittedBox( + child: Text( + playerInfo.playerInfoEnsemble.username, + style: TextStyle( + fontSize: Theme.of(context).textTheme.titleLarge?.fontSize, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.primary, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), ), - ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - if (playerInfo.iconData != null) - Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - FaIcon( - playerInfo.iconData, - size: Theme.of(context) + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + if (playerInfo.iconData != null) + Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + FaIcon( + playerInfo.iconData, + size: Theme.of(context) + .textTheme + .labelSmall + ?.fontSize, + ), + const Padding(padding: EdgeInsets.only(left: 4)), + ], + ), + Text( + 'UID: ${playerInfo.playerInfoEnsemble.nucleusId}', + style: TextStyle( + fontSize: Theme.of(context) .textTheme .labelSmall ?.fontSize, + fontWeight: Theme.of(context) + .textTheme + .labelSmall + ?.fontWeight, ), - const Padding(padding: EdgeInsets.only(left: 4)), - ], - ), - Text( - 'UID: ${playerInfo.playerInfoEnsemble.nucleusId}', - style: TextStyle( - fontSize: Theme.of(context) - .textTheme - .labelSmall - ?.fontSize, - fontWeight: Theme.of(context) - .textTheme - .labelSmall - ?.fontWeight, - ), - ), - const Padding(padding: EdgeInsets.only(left: 10)), - Text( - AppLocalizations.of(context)!.playedTime( - playerInfo.playerInfoEnsemble.playedTime), - style: TextStyle( - fontSize: Theme.of(context) - .textTheme - .labelSmall - ?.fontSize, - fontWeight: Theme.of(context) - .textTheme - .labelSmall - ?.fontWeight, - ), - ), + ), + const Padding(padding: EdgeInsets.only(left: 10)), + Text( + AppLocalizations.of(context)!.playedTime( + playerInfo.playerInfoEnsemble.playedTime), + style: TextStyle( + fontSize: Theme.of(context) + .textTheme + .labelSmall + ?.fontSize, + fontWeight: Theme.of(context) + .textTheme + .labelSmall + ?.fontWeight, + ), + ), + ], + ) ], - ) - ], - ), - IconButton( - onPressed: () => onInfoButtonPressed( - context, playerInfo.playerInfoEnsemble.personaId), + ), + IconButton( + onPressed: () => onInfoButtonPressed( + context, playerInfo.playerInfoEnsemble.username), icon: const Icon(Icons.help_outline), ) - ], - ), - )), + ], + ), + )), body: SafeArea( child: LayoutBuilder( builder: (context, constraints) { @@ -404,8 +406,7 @@ class PlayerInfoScreen extends StatelessWidget { class PlayerInfoMainContent extends StatelessWidget { final double playerInfoCardWidthScale; - const PlayerInfoMainContent( - {required this.playerInfoCardWidthScale, super.key}); + const PlayerInfoMainContent({required this.playerInfoCardWidthScale, super.key}); @override Widget build(BuildContext context) { @@ -467,8 +468,7 @@ class PlayerBaseInfoCard extends StatelessWidget { class PlayerDetailsInfoCard extends StatelessWidget { final double playerInfoCardWidthScale; - const PlayerDetailsInfoCard( - {required this.playerInfoCardWidthScale, super.key}); + const PlayerDetailsInfoCard({required this.playerInfoCardWidthScale, super.key}); @override Widget build(BuildContext context) { @@ -489,10 +489,10 @@ class PlayerDetailsInfoCard extends StatelessWidget { TabBar( tabAlignment: TabAlignment.start, splashBorderRadius: - const BorderRadius.all(Radius.circular(19)), + const BorderRadius.all(Radius.circular(19)), indicator: BoxDecoration( borderRadius: - const BorderRadius.all(Radius.circular(19)), + const BorderRadius.all(Radius.circular(19)), color: Theme.of(context).colorScheme.primary, ), indicatorPadding: const EdgeInsets.only( @@ -503,12 +503,12 @@ class PlayerDetailsInfoCard extends StatelessWidget { isScrollable: true, tabs: TabList.values .map((e) => Tab( - child: Container( - padding: const EdgeInsets.only( - left: 8, right: 8), - child: Text(AppLocalizations.of(context)! - .playerInfoScreenTabItem(e.name)), - ))) + child: Container( + padding: const EdgeInsets.only( + left: 8, right: 8), + child: Text(AppLocalizations.of(context)! + .playerInfoScreenTabItem(e.name)), + ))) .toList(), ), const Expanded( diff --git a/pubspec.lock b/pubspec.lock index a51a25d..d101758 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: build_runner_core - sha256: c9e32d21dd6626b5c163d48b037ce906bbe428bc23ab77bcd77bb21e593b6185 + sha256: "4ae8ffe5ac758da294ecf1802f2aff01558d8b1b00616aa7538ea9a8a5d50799" url: "https://pub.dev" source: hosted - version: "7.2.11" + version: "7.3.0" built_collection: dependency: transitive description: @@ -101,10 +101,10 @@ packages: dependency: transitive description: name: built_value - sha256: c9aabae0718ec394e5bc3c7272e6bb0dc0b32201a08fe185ec1d8401d3e39309 + sha256: a3ec2e0f967bc47f69f95009bb93db936288d61d5343b9436e378b28a2f830c6 url: "https://pub.dev" source: hosted - version: "8.8.1" + version: "8.9.0" change_app_package_name: dependency: "direct dev" description: @@ -257,10 +257,10 @@ packages: dependency: "direct main" description: name: font_awesome_flutter - sha256: "52671aea66da73b58d42ec6d0912b727a42248dd9a7c76d6c20f275783c48c08" + sha256: "275ff26905134bcb59417cf60ad979136f1f8257f2f449914b2c3e05bbb4cd6f" url: "https://pub.dev" source: hosted - version: "10.6.0" + version: "10.7.0" frontend_server_client: dependency: transitive description: @@ -409,10 +409,10 @@ packages: dependency: transitive description: name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.5" nested: dependency: transitive description: @@ -678,10 +678,10 @@ packages: dependency: "direct main" description: name: url_launcher - sha256: d25bb0ca00432a5e1ee40e69c36c85863addf7cc45e433769d61bed3fe81fd96 + sha256: c512655380d241a337521703af62d2c122bf7b77a46ff7dd750092aa9433499c url: "https://pub.dev" source: hosted - version: "6.2.3" + version: "6.2.4" url_launcher_android: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 75474e0..b7d0f71 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 2.2.4+61 +version: 2.2.4+62 environment: sdk: '>=3.1.3 <4.0.0'