Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/username #650

Merged
merged 25 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ jobs:
echo "IOS_BUNDLE_ID=${{ secrets.IOS_BUNDLE_ID }}" >> .env
echo "DEFAULT_IMAGE_URL=${{ secrets.DEFAULT_IMAGE_URL }}" >> .env
echo "DEFAULT_BANNER_URL=${{ secrets.DEFAULT_BANNER_URL }}" >> .env
echo "RAWG_API_KEY=${{ secrets.RAWG_API_KEY }}" >> .env
echo "RAWG_API_KEY2=${{ secrets.RAWG_API_KEY2 }}" >> .env
echo "RAWG_API_KEY3=${{ secrets.RAWG_API_KEY3 }}" >> .env
echo "RAWG_API_KEY4=${{ secrets.RAWG_API_KEY4 }}" >> .env
echo "RAWG_API_KEY5=${{ secrets.RAWG_API_KEY5 }}" >> .env
echo "RAWG_API_KEY6=${{ secrets.RAWG_API_KEY6 }}" >> .env
shell: bash

# Step 5: Create local.properties file
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ jobs:
echo "IOS_BUNDLE_ID=${{ secrets.IOS_BUNDLE_ID }}" >> .env
echo "DEFAULT_IMAGE_URL=${{ secrets.DEFAULT_IMAGE_URL }}" >> .env
echo "DEFAULT_BANNER_URL=${{ secrets.DEFAULT_BANNER_URL }}" >> .env
echo "RAWG_API_KEY=${{ secrets.RAWG_API_KEY }}" >> .env
echo "RAWG_API_KEY2=${{ secrets.RAWG_API_KEY2 }}" >> .env
echo "RAWG_API_KEY3=${{ secrets.RAWG_API_KEY3 }}" >> .env
echo "RAWG_API_KEY4=${{ secrets.RAWG_API_KEY4 }}" >> .env
echo "RAWG_API_KEY5=${{ secrets.RAWG_API_KEY5 }}" >> .env
echo "RAWG_API_KEY6=${{ secrets.RAWG_API_KEY6 }}" >> .env
shell: bash

# Step 4: Install all the dependencies
Expand Down
229 changes: 169 additions & 60 deletions README.md

Large diffs are not rendered by default.

Binary file added assets/default_images/Frame 158.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/default_images/Logo_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/default_images/byte_squad_logo 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// ignore_for_file: prefer_const_constructors

import 'dart:math';

import 'package:flame/flame.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
Expand Down Expand Up @@ -32,7 +34,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();

await dotenv.load();
globals.apiKey = dotenv.env['RAWG_API_KEY'];
_loadRandomApiKey();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Expand Down Expand Up @@ -93,6 +95,22 @@ void main() async {
ChangeNotifierProvider.value(value: themeProvider, child: const MyApp()));
}

void _loadRandomApiKey() {
final apiKeys = [
dotenv.env['RAWG_API_KEY'],
dotenv.env['RAWG_API_KEY2'],
dotenv.env['RAWG_API_KEY3'],
dotenv.env['RAWG_API_KEY4'],
dotenv.env['RAWG_API_KEY5'],
dotenv.env['RAWG_API_KEY6'],
];

final random = Random(DateTime.now().millisecondsSinceEpoch);
final selectedApiKey = apiKeys[random.nextInt(apiKeys.length)];

globals.apiKey = selectedApiKey;
}

class MyApp extends StatelessWidget {
// ignore: use_super_parameters
const MyApp({Key? key}) : super(key: key);
Expand Down
36 changes: 23 additions & 13 deletions lib/services/profile_S/profile_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,31 @@

Future<String> getProfileName(String userId) async {
FirebaseFirestore db = FirebaseFirestore.instance;
const int maxRetries = 5;
const Duration retryDelay = Duration(milliseconds: 500);

DocumentSnapshot profileSnapshot = await db
.collection("profile_data")
.doc(userId)
.get(); //get the document
Map<String, dynamic> data =
profileSnapshot.data() as Map<String, dynamic>; //map the overall data
Map<String, dynamic> userInfo =
data['username'] as Map<String, dynamic>; //map the username data
// Return profile name if exists otherwise give an empty string
if (profileSnapshot.exists) {
return userInfo['profile_name'];
} else {
return '';
for (int attempt = 0; attempt < maxRetries; attempt++) {

Check warning on line 107 in lib/services/profile_S/profile_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/profile_S/profile_service.dart#L107

Added line #L107 was not covered by tests
try {
DocumentSnapshot profileSnapshot = await db
.collection("profile_data")
.doc(userId)
.get(); //get the document
Map<String, dynamic> data = profileSnapshot.data()

Check warning on line 113 in lib/services/profile_S/profile_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/profile_S/profile_service.dart#L110-L113

Added lines #L110 - L113 were not covered by tests
as Map<String, dynamic>; //map the overall data
Map<String, dynamic> userInfo =
data['username'] as Map<String, dynamic>; //map the username data

Check warning on line 116 in lib/services/profile_S/profile_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/profile_S/profile_service.dart#L116

Added line #L116 was not covered by tests
// Return profile name if exists otherwise give an empty string
if (profileSnapshot.exists) {
return userInfo['profile_name'];

Check warning on line 119 in lib/services/profile_S/profile_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/profile_S/profile_service.dart#L118-L119

Added lines #L118 - L119 were not covered by tests
}
} catch (e) {
//print('Attempt $attempt failed: $e');
}
// Wait before retrying
await Future.delayed(retryDelay);

Check warning on line 125 in lib/services/profile_S/profile_service.dart

View check run for this annotation

Codecov / codecov/patch

lib/services/profile_S/profile_service.dart#L125

Added line #L125 was not covered by tests
}
//return empty string if the profile name is not found
return '';
}

Future<void> setCurrentlyPlaying(String gameId) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/view/components/home/start_timer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class _GameTimer extends State<GameTimer> {
return Text('Error: ${snapshot.error}');
} else if (!snapshot.hasData ||
snapshot.data!.isEmpty) {
return const Text('No data found');
return const Text('Add a game to \'My Games\' to start');
} else {
return FittedBox(
child: DropdownMenu<String>(
Expand Down
2 changes: 1 addition & 1 deletion lib/view/pages/badges/badge_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class _BadgePageState extends State<BadgePage> {
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return const Text('No users with the unlocked badge');
return const Text('No connections with the unlocked badge');
} else {
List<String> profilePictures = snapshot.data!;

Expand Down
Loading
Loading