Skip to content

Commit

Permalink
Some more dependency version updates and restores Cloudstore function…
Browse files Browse the repository at this point in the history
…ality
  • Loading branch information
astivi committed Jul 2, 2024
1 parent c929483 commit 42359ee
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 174 deletions.
5 changes: 0 additions & 5 deletions .firebaserc

This file was deleted.

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ _Created using [Very Good CLI][very_good_cli_link] 🤖_

## Getting Started 🚀

### Firebase
First, please create a Firebase project for development.
After you create your project, remember to activate the following features:
- **Authentication** with the **anonymous** option
- **Firestore** with the rules in firestore.rules.

Next, use the instructions on [Firebase website](https://firebase.google.com/docs/flutter/setup?platform=web) to set up the **flutterfire_cli**.

Allow it to override the **lib/firebase_options.dart** file with your project settings.

### Running locally
To run the desired project either use the launch configuration in VSCode/Android Studio or use the following commands:

```sh
Expand Down
33 changes: 0 additions & 33 deletions firebase.json

This file was deleted.

9 changes: 0 additions & 9 deletions lib/bootstrap.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import 'dart:async';
import 'dart:developer';

import 'package:bloc/bloc.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/widgets.dart';

class AppBlocObserver extends BlocObserver {
@override
Expand All @@ -19,8 +15,3 @@ class AppBlocObserver extends BlocObserver {
super.onError(bloc, error, stackTrace);
}
}

typedef BootstrapBuilder = Future<Widget> Function(
FirebaseFirestore firestore,
FirebaseAuth firebaseAuth,
);
64 changes: 64 additions & 0 deletions lib/firebase_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// File generated by FlutterFire CLI.
// ignore_for_file: type=lint
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;

/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for android - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.iOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for ios - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.macOS:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for macos - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.windows:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for windows - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
case TargetPlatform.linux:
throw UnsupportedError(
'DefaultFirebaseOptions have not been configured for linux - '
'you can reconfigure this by running the FlutterFire CLI again.',
);
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}

static const FirebaseOptions web = FirebaseOptions(
apiKey: '',
appId: '',
messagingSenderId: '',
projectId: '',
authDomain: '',
storageBucket: '',
);

}
14 changes: 10 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import 'dart:async';

import 'package:authentication_repository/authentication_repository.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:leaderboard_repository/leaderboard_repository.dart';
import 'package:pinball/app/app.dart';
import 'package:pinball/bootstrap.dart';
import 'package:pinball/firebase_options.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:platform_helper/platform_helper.dart';
import 'package:share_repository/share_repository.dart';

Future<App> bootstrap() async {
WidgetsFlutterBinding.ensureInitialized();
// await Firebase.initializeApp();
const leaderboardRepository = LeaderboardRepository();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
final leaderboardRepository =
LeaderboardRepository(FirebaseFirestore.instance);
const shareRepository =
ShareRepository(appUrl: ShareRepository.pinballGameUrl);
final authenticationRepository = AuthenticationRepository();
final authenticationRepository =
AuthenticationRepository(FirebaseAuth.instance);
final pinballAudioPlayer = PinballAudioPlayer();
final platformHelper = PlatformHelper();
// await authenticationRepository.authenticateAnonymously();
await authenticationRepository.authenticateAnonymously();
return App(
authenticationRepository: authenticationRepository,
leaderboardRepository: leaderboardRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class AuthenticationException implements Exception {
/// {@endtemplate}
class AuthenticationRepository {
/// {@macro authentication_repository}
AuthenticationRepository(/*this._firebaseAuth*/);
AuthenticationRepository(this._firebaseAuth);

// final FirebaseAuth _firebaseAuth;
final FirebaseAuth _firebaseAuth;

/// Sign in the existing user anonymously using [FirebaseAuth]. If the
/// authentication process can't be completed, it will throw an
/// [AuthenticationException].
Future<void> authenticateAnonymously() async {
// try {
// await _firebaseAuth.signInAnonymously();
// } on Exception catch (error, stackTrace) {
// throw AuthenticationException(error, stackTrace);
// }
try {
await _firebaseAuth.signInAnonymously();
} on Exception catch (error, stackTrace) {
throw AuthenticationException(error, stackTrace);
}
}
}
10 changes: 5 additions & 5 deletions packages/authentication_repository/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ version: 1.0.0+1
publish_to: none

environment:
sdk: "^3.4.1"
sdk: "^3.4.3"

dependencies:
firebase_auth: ^4.20.0
firebase_core: ^2.32.0
firebase_auth: ^5.1.1
firebase_core: ^3.1.1
flutter:
sdk: flutter
intl: ^0.19.0

dev_dependencies:
flutter_test:
sdk: flutter
mocktail: ^0.2.0
very_good_analysis: ^2.4.0
mocktail: ^1.0.4
very_good_analysis: ^6.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() {
setUp(() {
firebaseAuth = _MockFirebaseAuth();
userCredential = _MockUserCredential();
authenticationRepository = AuthenticationRepository();
authenticationRepository = AuthenticationRepository(firebaseAuth);
});

group('authenticateAnonymously', () {
Expand Down
2 changes: 1 addition & 1 deletion packages/geometry/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 1.0.0+1
publish_to: none

environment:
sdk: "^3.4.1"
sdk: "^3.4.3"

dependencies:
vector_math: ^2.1.1
Expand Down
108 changes: 53 additions & 55 deletions packages/leaderboard_repository/lib/src/leaderboard_repository.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:leaderboard_repository/leaderboard_repository.dart';

/// {@template leaderboard_repository}
Expand All @@ -6,31 +7,30 @@ import 'package:leaderboard_repository/leaderboard_repository.dart';
class LeaderboardRepository {
/// {@macro leaderboard_repository}
const LeaderboardRepository(
//FirebaseFirestore firebaseFirestore,
); //: _firebaseFirestore = firebaseFirestore;
FirebaseFirestore firebaseFirestore,
) : _firebaseFirestore = firebaseFirestore;

//final FirebaseFirestore _firebaseFirestore;
final FirebaseFirestore _firebaseFirestore;

// static const _leaderboardLimit = 10;
// static const _leaderboardCollectionName = 'leaderboard';
// static const _scoreFieldName = 'score';
static const _leaderboardLimit = 10;
static const _leaderboardCollectionName = 'leaderboard';
static const _scoreFieldName = 'score';

/// Acquires top 10 [LeaderboardEntryData]s.
Future<List<LeaderboardEntryData>> fetchTop10Leaderboard() async {
// try {
// // final querySnapshot = await _firebaseFirestore
// // .collection(_leaderboardCollectionName)
// // .orderBy(_scoreFieldName, descending: true)
// // .limit(_leaderboardLimit)
// // .get();
// // final documents = querySnapshot.docs;
// // return documents.toLeaderboard();
// } on LeaderboardDeserializationException {
// rethrow;
// } on Exception catch (error, stackTrace) {
// throw FetchTop10LeaderboardException(error, stackTrace);
// }
return Future.value(List<LeaderboardEntryData>.empty());
try {
final querySnapshot = await _firebaseFirestore
.collection(_leaderboardCollectionName)
.orderBy(_scoreFieldName, descending: true)
.limit(_leaderboardLimit)
.get();
final documents = querySnapshot.docs;
return documents.toLeaderboard();
} on LeaderboardDeserializationException {
rethrow;
} on Exception catch (error, stackTrace) {
throw FetchTop10LeaderboardException(error, stackTrace);
}
}

/// Adds player's score entry to the leaderboard if it is within the top-10
Expand All @@ -49,44 +49,42 @@ class LeaderboardRepository {
}

Future<List<LeaderboardEntryData>> _fetchLeaderboardSortedByScore() async {
// try {
// final querySnapshot = await _firebaseFirestore
// .collection(_leaderboardCollectionName)
// .orderBy(_scoreFieldName, descending: true)
// .get();
// final documents = querySnapshot.docs;
// return documents.toLeaderboard();
// } on Exception catch (error, stackTrace) {
// throw FetchLeaderboardException(error, stackTrace);
// }
return Future.value(List<LeaderboardEntryData>.empty());
try {
final querySnapshot = await _firebaseFirestore
.collection(_leaderboardCollectionName)
.orderBy(_scoreFieldName, descending: true)
.get();
final documents = querySnapshot.docs;
return documents.toLeaderboard();
} on Exception catch (error, stackTrace) {
throw FetchLeaderboardException(error, stackTrace);
}
}

Future<void> _saveScore(LeaderboardEntryData entry) {
// try {
// return _firebaseFirestore
// .collection(_leaderboardCollectionName)
// .add(entry.toJson());
// } on Exception catch (error, stackTrace) {
// throw AddLeaderboardEntryException(error, stackTrace);
// }
return Future.value();
try {
return _firebaseFirestore
.collection(_leaderboardCollectionName)
.add(entry.toJson());
} on Exception catch (error, stackTrace) {
throw AddLeaderboardEntryException(error, stackTrace);
}
}
}

// extension on List<QueryDocumentSnapshot> {
// List<LeaderboardEntryData> toLeaderboard() {
// final leaderboardEntries = <LeaderboardEntryData>[];
// for (final document in this) {
// final data = document.data() as Map<String, dynamic>?;
// if (data != null) {
// try {
// leaderboardEntries.add(LeaderboardEntryData.fromJson(data));
// } catch (error, stackTrace) {
// throw LeaderboardDeserializationException(error, stackTrace);
// }
// }
// }
// return leaderboardEntries;
// }
//}
extension on List<QueryDocumentSnapshot> {
List<LeaderboardEntryData> toLeaderboard() {
final leaderboardEntries = <LeaderboardEntryData>[];
for (final document in this) {
final data = document.data() as Map<String, dynamic>?;
if (data != null) {
try {
leaderboardEntries.add(LeaderboardEntryData.fromJson(data));
} catch (error, stackTrace) {
throw LeaderboardDeserializationException(error, stackTrace);
}
}
}
return leaderboardEntries;
}
}
Loading

0 comments on commit 42359ee

Please sign in to comment.