Skip to content

Commit 973efd4

Browse files
authored
refactor: improve project (#25)
* chore: update gradle * chore: set android:exported on `AndroidManifest` * chore: update deps * style: fix formatting * refactor: replace `WillPopScope` with `PopScope` * refactor: rename `requiresReauthentication` to `needsReauthentication` * refactor: move `needsReauthentication` on base `Failure` * refactor: rename `UserFailure.none` to `UserFailure.empty` * refactor: rename `TopicsFailure.none` to `TopicsFailure.empty` * refactor: rename `QuizzesFailure.none` to `QuizzesFailure.empty` * refactor: rename `User.none` to `User.empty` * refactor: rename `Option.none` to `Option.empty` * refactor: rename `Question.none` to `Question.empty` * refactor: rename `Quiz.none` to `Quiz.empty` * refactor: rename `Topic.none` to `Topic.empty` * refactor: rename `Quiz.none` to `Quiz.empty` * docs(user_repository): improve comments * chore: apply flutter grade plugins declaratively
1 parent 0add19c commit 973efd4

File tree

21 files changed

+89
-90
lines changed

21 files changed

+89
-90
lines changed

android/app/build.gradle

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
id "org.jetbrains.kotlin.android"
5+
id 'dev.flutter.flutter-gradle-plugin'
6+
id 'com.google.gms.google-services'
7+
}
8+
19
def localProperties = new Properties()
210
def localPropertiesFile = rootProject.file('local.properties')
311
if (localPropertiesFile.exists()) {
@@ -6,11 +14,6 @@ if (localPropertiesFile.exists()) {
614
}
715
}
816

9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
1417
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
1518
if (flutterVersionCode == null) {
1619
flutterVersionCode = '1'
@@ -27,11 +30,6 @@ if (keystorePropertiesFile.exists()) {
2730
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
2831
}
2932

30-
apply plugin: 'com.android.application'
31-
apply plugin: 'com.google.gms.google-services'
32-
apply plugin: 'kotlin-android'
33-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
34-
3533
android {
3634
compileSdkVersion flutter.compileSdkVersion
3735
ndkVersion flutter.ndkVersion
@@ -109,6 +107,5 @@ flutter {
109107
}
110108

111109
dependencies {
112-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
113110
implementation 'com.android.support:multidex:1.0.3'
114111
}

android/build.gradle

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
buildscript {
2-
ext.kotlin_version = '1.7.10'
3-
repositories {
4-
google()
5-
mavenCentral()
6-
}
7-
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:7.4.2'
10-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
classpath 'com.google.gms:google-services:4.4.1'
12-
}
13-
}
14-
151
allprojects {
162
repositories {
173
google()

android/settings.gradle

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
include ':app'
1+
pluginManagement {
2+
def flutterSdkPath = {
3+
def properties = new Properties()
4+
file("local.properties").withInputStream { properties.load(it) }
5+
def flutterSdkPath = properties.getProperty("flutter.sdk")
6+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7+
return flutterSdkPath
8+
}()
29

3-
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4-
def properties = new Properties()
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
511

6-
assert localPropertiesFile.exists()
7-
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
17+
}
818

9-
def flutterSdkPath = properties.getProperty("flutter.sdk")
10-
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11-
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "7.4.2" apply false
22+
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
23+
id "com.google.gms.google-services" version "4.4.0" apply false
24+
}
25+
26+
include ":app"

lib/app/cubit/app_cubit.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class AppCubit extends Cubit<AppState> {
88
required UserRepository userRepository,
99
}) : _userRepository = userRepository,
1010
super(
11-
userRepository.user.isNone
11+
userRepository.user.isEmpty
1212
? const AppState.unauthenticated()
1313
: AppState.newlyAuthenticated(userRepository.user),
1414
) {
@@ -32,7 +32,7 @@ class AppCubit extends Cubit<AppState> {
3232
}
3333

3434
void _onUserChanged(User user) {
35-
if (user.isNone) {
35+
if (user.isEmpty) {
3636
emit(const AppState.unauthenticated());
3737
} else if (state.isUnauthenticated) {
3838
emit(AppState.newlyAuthenticated(user));
@@ -44,7 +44,7 @@ class AppCubit extends Cubit<AppState> {
4444
void _onUserFailed(UserFailure failure) {
4545
final currentState = state;
4646
emit(AppState.failure(failure: failure, user: currentState.user));
47-
if (failure.requiresReauthentication) {
47+
if (failure.needsReauthentication) {
4848
emit(const AppState.unauthenticated());
4949
} else {
5050
emit(currentState);

lib/app/cubit/app_state.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ extension AppStatusExtensions on AppStatus {
1717
final class AppState extends Equatable {
1818
const AppState._({
1919
required this.status,
20-
this.user = User.none,
21-
this.failure = UserFailure.none,
20+
this.user = User.empty,
21+
this.failure = UserFailure.empty,
2222
});
2323

2424
const AppState.unauthenticated() : this._(status: AppStatus.unauthenticated);

lib/login/cubit/login_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class LoginState extends Equatable {
1818
const LoginState._({
1919
this.status = LoginStatus.initial,
2020
this.signInMethod = SignInMethod.none,
21-
this.failure = UserFailure.none,
21+
this.failure = UserFailure.empty,
2222
});
2323

2424
const LoginState.initial() : this._();

lib/profile/cubit/profile_cubit.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:user_repository/user_repository.dart';
44
class ProfileCubit extends Cubit<User> {
55
ProfileCubit({required UserRepository userRepository})
66
: _userRepository = userRepository,
7-
super(User.none) {
7+
super(User.empty) {
88
_watchUser();
99
}
1010

lib/quiz/cubit/quiz_cubit.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class QuizCubit extends Cubit<QuizState> {
1919
try {
2020
emit(state.fromQuizLoading());
2121
final quiz = await _quizzesRepository.getQuiz(quizId);
22-
if (quiz.isNone) {
22+
if (quiz.isEmpty) {
2323
emit(state.fromQuizEmpty());
2424
return;
2525
}
@@ -38,7 +38,7 @@ class QuizCubit extends Cubit<QuizState> {
3838
}
3939

4040
void unselectOption() {
41-
emit(state.copyWith(selectedOption: Option.none));
41+
emit(state.copyWith(selectedOption: Option.empty));
4242
}
4343

4444
void validateAnswer() {

lib/quiz/cubit/quiz_state.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ enum QuizStatus { initial, loading, empty, loaded, failure }
55
final class QuizState extends Equatable {
66
const QuizState._({
77
this.status = QuizStatus.initial,
8-
this.quiz = Quiz.none,
9-
this.selectedOption = Option.none,
8+
this.quiz = Quiz.empty,
9+
this.selectedOption = Option.empty,
1010
this.step = 0,
11-
this.failure = QuizzesFailure.none,
11+
this.failure = QuizzesFailure.empty,
1212
});
1313

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

5959
Question operator [](int step) =>
60-
quiz.questions.isEmpty ? Question.none : quiz.questions[step - 1];
60+
quiz.questions.isEmpty ? Question.empty : quiz.questions[step - 1];
6161
}

lib/quiz/view/quiz_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class _QuizBodyState extends State<QuizBody> {
9191
listenWhen: (previous, current) =>
9292
previous.quiz.id != current.quiz.id,
9393
listener: (_, state) {
94-
if (state.quiz.isNone) {
94+
if (state.quiz.isEmpty) {
9595
context.read<VoidCallback>()();
9696
}
9797
},
@@ -110,7 +110,7 @@ class _QuizBodyState extends State<QuizBody> {
110110
listenWhen: (previous, current) =>
111111
previous.selectedOption != current.selectedOption,
112112
listener: (_, state) {
113-
if (state.selectedOption.isNotNone) {
113+
if (state.selectedOption.isNotEmpty) {
114114
context.showScrollControlledBottomSheet<void>(
115115
builder: (_) {
116116
return BlocProvider.value(

0 commit comments

Comments
 (0)