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

refactor: improve project #25

Merged
merged 19 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
19 changes: 8 additions & 11 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id "org.jetbrains.kotlin.android"
id 'dev.flutter.flutter-gradle-plugin'
id 'com.google.gms.google-services'
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,11 +14,6 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
Expand All @@ -27,11 +30,6 @@ if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
Expand Down Expand Up @@ -109,6 +107,5 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
}
14 changes: 0 additions & 14 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.4.1'
}
}

allprojects {
repositories {
google()
Expand Down
31 changes: 23 additions & 8 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.4.2" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "com.google.gms.google-services" version "4.4.0" apply false
}

include ":app"
6 changes: 3 additions & 3 deletions lib/app/cubit/app_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AppCubit extends Cubit<AppState> {
required UserRepository userRepository,
}) : _userRepository = userRepository,
super(
userRepository.user.isNone
userRepository.user.isEmpty
? const AppState.unauthenticated()
: AppState.newlyAuthenticated(userRepository.user),
) {
Expand All @@ -32,7 +32,7 @@ class AppCubit extends Cubit<AppState> {
}

void _onUserChanged(User user) {
if (user.isNone) {
if (user.isEmpty) {
emit(const AppState.unauthenticated());
} else if (state.isUnauthenticated) {
emit(AppState.newlyAuthenticated(user));
Expand All @@ -44,7 +44,7 @@ class AppCubit extends Cubit<AppState> {
void _onUserFailed(UserFailure failure) {
final currentState = state;
emit(AppState.failure(failure: failure, user: currentState.user));
if (failure.requiresReauthentication) {
if (failure.needsReauthentication) {
emit(const AppState.unauthenticated());
} else {
emit(currentState);
Expand Down
4 changes: 2 additions & 2 deletions lib/app/cubit/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ extension AppStatusExtensions on AppStatus {
final class AppState extends Equatable {
const AppState._({
required this.status,
this.user = User.none,
this.failure = UserFailure.none,
this.user = User.empty,
this.failure = UserFailure.empty,
});

const AppState.unauthenticated() : this._(status: AppStatus.unauthenticated);
Expand Down
2 changes: 1 addition & 1 deletion lib/login/cubit/login_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class LoginState extends Equatable {
const LoginState._({
this.status = LoginStatus.initial,
this.signInMethod = SignInMethod.none,
this.failure = UserFailure.none,
this.failure = UserFailure.empty,
});

const LoginState.initial() : this._();
Expand Down
2 changes: 1 addition & 1 deletion lib/profile/cubit/profile_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:user_repository/user_repository.dart';
class ProfileCubit extends Cubit<User> {
ProfileCubit({required UserRepository userRepository})
: _userRepository = userRepository,
super(User.none) {
super(User.empty) {
_watchUser();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/quiz/cubit/quiz_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class QuizCubit extends Cubit<QuizState> {
try {
emit(state.fromQuizLoading());
final quiz = await _quizzesRepository.getQuiz(quizId);
if (quiz.isNone) {
if (quiz.isEmpty) {
emit(state.fromQuizEmpty());
return;
}
Expand All @@ -38,7 +38,7 @@ class QuizCubit extends Cubit<QuizState> {
}

void unselectOption() {
emit(state.copyWith(selectedOption: Option.none));
emit(state.copyWith(selectedOption: Option.empty));
}

void validateAnswer() {
Expand Down
8 changes: 4 additions & 4 deletions lib/quiz/cubit/quiz_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ enum QuizStatus { initial, loading, empty, loaded, failure }
final class QuizState extends Equatable {
const QuizState._({
this.status = QuizStatus.initial,
this.quiz = Quiz.none,
this.selectedOption = Option.none,
this.quiz = Quiz.empty,
this.selectedOption = Option.empty,
this.step = 0,
this.failure = QuizzesFailure.none,
this.failure = QuizzesFailure.empty,
});

const QuizState.initial() : this._();
Expand Down Expand Up @@ -57,5 +57,5 @@ extension QuizStateExtensions on QuizState {
double get progress => step / steps;

Question operator [](int step) =>
quiz.questions.isEmpty ? Question.none : quiz.questions[step - 1];
quiz.questions.isEmpty ? Question.empty : quiz.questions[step - 1];
}
4 changes: 2 additions & 2 deletions lib/quiz/view/quiz_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _QuizBodyState extends State<QuizBody> {
listenWhen: (previous, current) =>
previous.quiz.id != current.quiz.id,
listener: (_, state) {
if (state.quiz.isNone) {
if (state.quiz.isEmpty) {
context.read<VoidCallback>()();
}
},
Expand All @@ -110,7 +110,7 @@ class _QuizBodyState extends State<QuizBody> {
listenWhen: (previous, current) =>
previous.selectedOption != current.selectedOption,
listener: (_, state) {
if (state.selectedOption.isNotNone) {
if (state.selectedOption.isNotEmpty) {
context.showScrollControlledBottomSheet<void>(
builder: (_) {
return BlocProvider.value(
Expand Down
4 changes: 2 additions & 2 deletions lib/topics/cubit/topics_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ enum TopicsStatus { initial, loading, empty, loaded, failure }

final class TopicsState extends Equatable {
const TopicsState._({
this.user = User.none,
this.user = User.empty,
this.status = TopicsStatus.initial,
this.topics = const [],
this.failure = TopicsFailure.none,
this.failure = TopicsFailure.empty,
});

const TopicsState.initial() : this._();
Expand Down
4 changes: 2 additions & 2 deletions lib/topics/view/topics_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ List<Page<dynamic>> onGenerateTopicsPages(

class TopicsFlowState extends Equatable {
const TopicsFlowState._({
this.selectedTopic = Topic.none,
this.selectedTopic = Topic.empty,
this.selectedQuizId = '',
});

Expand All @@ -36,7 +36,7 @@ class TopicsFlowState extends Equatable {
final Topic selectedTopic;
final String selectedQuizId;

bool get hasTopicSelected => selectedTopic.isNotNone;
bool get hasTopicSelected => selectedTopic.isNotEmpty;
bool get hasQuizSelected => selectedQuizId.isNotEmpty;

@override
Expand Down
2 changes: 2 additions & 0 deletions packages/app_core/lib/src/failure.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
abstract class Failure implements Exception {
const Failure();

bool get needsReauthentication => false;
}
6 changes: 3 additions & 3 deletions packages/quizzes_repository/lib/src/failures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class QuizzesFailure extends Failure {

factory QuizzesFailure.fromGetQuiz() => const GetQuizFailure();

static const none = QuizzesNoFailure();
static const empty = EmptyQuizzesFailure();
}

class QuizzesNoFailure extends QuizzesFailure {
const QuizzesNoFailure() : super._();
class EmptyQuizzesFailure extends QuizzesFailure {
const EmptyQuizzesFailure() : super._();
}

class GetQuizFailure extends QuizzesFailure {
Expand Down
10 changes: 5 additions & 5 deletions packages/quizzes_repository/lib/src/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Option extends Equatable {
final String detail;
final bool? correct;

static const none = Option(value: '', detail: '', correct: null);
static const empty = Option(value: '', detail: '', correct: null);

@override
List<Object?> get props => [value, detail, correct];
Expand All @@ -26,7 +26,7 @@ class Option extends Equatable {
}

extension OptionExtensions on Option {
bool get isNotNone => this != Option.none;
bool get isNotEmpty => this != Option.empty;
}

@JsonSerializable(createToJson: false)
Expand All @@ -40,7 +40,7 @@ class Question extends Equatable {
@JsonKey(defaultValue: <Option>[])
final List<Option> options;

static const none = Question(text: '', options: []);
static const empty = Question(text: '', options: []);

@override
List<Object?> get props => [text, options];
Expand Down Expand Up @@ -69,7 +69,7 @@ class Quiz extends Equatable {
@JsonKey(defaultValue: <Question>[])
final List<Question> questions;

static const none = Quiz(
static const empty = Quiz(
id: '',
title: '',
description: '',
Expand All @@ -92,5 +92,5 @@ class Quiz extends Equatable {
}

extension QuizExtensions on Quiz {
bool get isNone => this == Quiz.none;
bool get isEmpty => this == Quiz.empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class QuizzesRepository {
if (doc.exists) {
return Quiz.fromJson(doc.data()!);
}
return Quiz.none;
return Quiz.empty;
} on FirebaseException {
throw QuizzesFailure.fromGetQuiz();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/topics_repository/lib/src/failures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class TopicsFailure extends Failure {

factory TopicsFailure.fromGetTopics() => const GetTopicsFailure();

static const none = TopicsNoFailure();
static const empty = EmptyTopicsFailure();
}

class TopicsNoFailure extends TopicsFailure {
const TopicsNoFailure() : super._();
class EmptyTopicsFailure extends TopicsFailure {
const EmptyTopicsFailure() : super._();
}

class GetTopicsFailure extends TopicsFailure {
Expand Down
8 changes: 4 additions & 4 deletions packages/topics_repository/lib/src/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Quiz extends Equatable {
final String title;
final String description;

static const none = Quiz(
static const empty = Quiz(
id: '',
title: '',
description: '',
Expand Down Expand Up @@ -46,7 +46,7 @@ class Topic extends Equatable {
final String imageName;
final List<Quiz> quizzes;

static const none = Topic(
static const empty = Topic(
id: '',
title: '',
description: '',
Expand All @@ -61,8 +61,8 @@ class Topic extends Equatable {
}

extension TopicExtensions on Topic {
bool get isNone => this == Topic.none;
bool get isNotNone => !isNone;
bool get isEmpty => this == Topic.empty;
bool get isNotEmpty => !isEmpty;

int get totalQuizzes => quizzes.length;

Expand Down
13 changes: 6 additions & 7 deletions packages/user_repository/lib/src/failures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ class UserFailure extends Failure {
factory UserFailure.fromSignInWithAppleNotSupported() =>
const AppleSignInNotSupportedFailure();

static const none = UserNoFailure();

bool get requiresReauthentication {
return this is AuthUserChangesFailure;
}
static const empty = EmptyUserFailure();
}

class UserNoFailure extends UserFailure {
const UserNoFailure() : super._();
class EmptyUserFailure extends UserFailure {
const EmptyUserFailure() : super._();
}

class AuthUserChangesFailure extends UserFailure {
const AuthUserChangesFailure() : super._();

@override
bool get needsReauthentication => true;
}

class SignOutFailure extends UserFailure {
Expand Down
Loading
Loading