Skip to content

Commit

Permalink
update feature proof reading & create feature check version apps
Browse files Browse the repository at this point in the history
  • Loading branch information
1234iqbal committed Feb 19, 2024
1 parent c2ece8e commit c1f96fe
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 16 deletions.
5 changes: 5 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ init:
make build_runner
@echo "╠ Initialize successed!"

release:
make init
@flutter pub run flutter_launcher_icons
@flutter build appbundle

dev:
@flutter run lib/main.dart

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';

import '../../../onboarding/model/version_model.dart';
import '../model/registered_user.dart';

@Injectable()
Expand Down Expand Up @@ -111,4 +112,32 @@ class RegisterUserRepository {
}
return null;
}

Future<VersionModel?> getVersionApps(String version) async {
try {
final result = await FirebaseFirestore.instance
.collection('configuration')
.doc('version')
.get();

final allVersion = result.data()?['version'] as List<dynamic>;

for (final element in allVersion) {
if (element == version) {
final storedVersion = element.toString();
return VersionModel(version: storedVersion);
}
}
return null;
} on FirebaseException catch (e) {
if (kDebugMode) {
print("Failed with error '${e.code}': '${e.message}'");
}
return null;
} catch (e) {
throw Exception(e.toString());
}
}


}
9 changes: 8 additions & 1 deletion app/lib/features/main/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class _HomePageState extends State<HomePage> {
text: 'Pengaturan',
),
SizedBox(
height: MediaQuery.of(context).size.height - 620,
height: MediaQuery.of(context).size.height - 640,
),
InkWell(
onTap: () async {
Expand All @@ -122,6 +122,13 @@ class _HomePageState extends State<HomePage> {
),
),
),
Center(
child: Text(
'V 1.0.0',
textAlign: TextAlign.center,
style: FontTheme.greyNormal14(),
),
),
],
),
),
Expand Down
13 changes: 13 additions & 0 deletions app/lib/features/onboarding/model/version_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class VersionModel {
final String version;

VersionModel({
required this.version,
});

factory VersionModel.fromJson(Map<String, dynamic> json) {
return VersionModel(
version: json['version'].toString(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:equatable/equatable.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import 'package:package_info_plus/package_info_plus.dart';

import '../../../authentication/register/repositories/register_user_repo.dart';

Expand All @@ -14,14 +15,15 @@ part 'user_initialization_state.dart';
@singleton
class UserInitializationBloc
extends Bloc<UserInitializationEvent, UserInitializationState> {

final RegisterUserRepository registerUserRepository;
// final GoogleSignIn _googleSignIn = GoogleSignIn();

UserInitializationBloc(this.registerUserRepository)
: super(UserInitializationInitial()) {
on<OnboardingAuthEvent>(_auth);
}

FutureOr<void> _auth(
OnboardingAuthEvent state,
Emitter<UserInitializationState> emit,
Expand All @@ -31,20 +33,31 @@ class UserInitializationBloc
if (creds != null) {
emit(UserAuthenticated());
final userId = creds.uid;

final packageInfo = await PackageInfo.fromPlatform();

final checkVersionApps = await registerUserRepository.getVersionApps(
packageInfo.version
);

if (checkVersionApps == null) {
return emit(UpdateAvailable());
}

try {
final data = await registerUserRepository.getById(userId);

print(data);
if (data == null) {
emit(UserUnregistered());
return emit(UserUnregistered());
} else {
emit(UserRegistered());
return emit(UserRegistered());
}
} catch (e) {
emit(UserError(e.toString()));
return emit(UserError(e.toString()));
}
} else {
emit(UserUnauthenticated());
return emit(UserUnauthenticated());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class UserRegistered extends UserInitializationState {
List<Object> get props => [];
}

class UpdateAvailable extends UserInitializationState {
@override
List<Object> get props => [];
}

class UserGetDataLoading extends UserInitializationState {
@override
List<Object> get props => [];
Expand Down
2 changes: 2 additions & 0 deletions app/lib/features/onboarding/presentation/pages/_pages.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../../core/constants/assets.dart';
import '../bloc/user_initialization_bloc.dart';

part 'splash_screen.dart';
part 'onboarding_page.dart';
part 'update_dialog.dart';
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of '_pages.dart';


class SplashScreen extends StatelessWidget {
const SplashScreen({super.key});

Expand All @@ -8,7 +9,9 @@ class SplashScreen extends StatelessWidget {
final size = MediaQuery.of(context).size;
return BlocListener<UserInitializationBloc, UserInitializationState>(
listener: (context, state) {
if (state is UserUnauthenticated) {
if (state is UpdateAvailable) {
showUpdateDialog(context);
} else if (state is UserUnauthenticated) {
context.go('/onboarding');
} else if (state is UserUnregistered) {
context.go('/register');
Expand All @@ -35,3 +38,12 @@ class SplashScreen extends StatelessWidget {
);
}
}

void showUpdateDialog(BuildContext context) {
showDialog<Widget>(
context: context,
builder: (BuildContext context) {
return const UpdateDialog();
},
);
}
39 changes: 39 additions & 0 deletions app/lib/features/onboarding/presentation/pages/update_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
part of '_pages.dart';

class UpdateDialog extends StatelessWidget {
const UpdateDialog({super.key});

@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Versi Baru Tersedia'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('Sebuah versi baru dari aplikasi tersedia.'),
Text(
'Silakan perbarui ke versi terbaru untuk '
'menikmati fitur dan perbaikan baru.'
),
],
),
),
actions: <Widget>[
Center(
child: TextButton(
child: const Text('Update Sekarang'),
onPressed: () async {
// Navigator.of(context).pop();
final url = Uri.parse(
'https://play.google.com/store/apps/details?id=com.toki.bebras_pandai&hl=en-US&ah=i6XiDj6PnW-iPzIlbXBXM-jTYjA',
);
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
},
),
)
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class QuizExerciseBase {

factory QuizExerciseBase.fromJson(Map<String, dynamic> json) {
return QuizExerciseBase(
id: json['id'] as String,
id: json['doc_id'] as String,
challengeGroup: json['challenge_group'] as String,
title: json['title'] as String,
status: json['status'] as String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ class QuizExerciseRepository {
final globalResult =
await db.collection('configuration').doc('global_variables').get();

final taskSet = globalResult.get('task_set_doc_index') as List<dynamic>;
final taskSet = globalResult.get('task_set_doc_$group') as List<dynamic>;
for (final element in taskSet) {
final challengeGroup = element['challenge_group'] as String;
if (challengeGroup == group) {
quizExerciseBaseList
.add(QuizExerciseBase.fromJson(element as Map<String, dynamic>));
}
}

return quizExerciseBaseList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,24 @@ class _TaskListPageState extends State<TaskListPage> {

return GestureDetector(
onTap: () {
String cleanedTaskId;
if (task.id.startsWith('penegak_')) {
cleanedTaskId = task.id.replaceFirst('penegak_', '');
} else if (task.id.startsWith('sikecil_')) {
cleanedTaskId = task.id.replaceFirst('sikecil_', '');
} else if (task.id.startsWith('penggalang_')) {
cleanedTaskId = task.id.replaceFirst('penggalang_', '');
} else if (task.id.startsWith('siaga_')) {
cleanedTaskId = task.id.replaceFirst('siaga_', '');
} else {
cleanedTaskId = task.id;
}

context.push(
Uri(
path: '/task_detail',
queryParameters: {
'task_id': task.id,
'task_id': cleanedTaskId,
},
).toString(),
);
Expand Down
2 changes: 2 additions & 0 deletions app/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import firebase_messaging
import firebase_storage
import flutter_local_notifications
import geolocator_apple
import package_info_plus
import path_provider_foundation
import printing
import shared_preferences_foundation
Expand All @@ -26,6 +27,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
Expand Down
18 changes: 17 additions & 1 deletion app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
package_info_plus:
dependency: "direct main"
description:
name: package_info_plus
sha256: "88bc797f44a94814f2213db1c9bd5badebafdfb8290ca9f78d4b9ee2a3db4d79"
url: "https://pub.dev"
source: hosted
version: "5.0.1"
package_info_plus_platform_interface:
dependency: transitive
description:
name: package_info_plus_platform_interface
sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -1558,5 +1574,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0-194.0.dev <4.0.0"
dart: ">=3.2.0 <4.0.0"
flutter: ">=3.13.0"
5 changes: 3 additions & 2 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bebras_pandai
description: Bebras description
description: Aplikasi belajar Computational Thinking oleh bebras.org
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
Expand All @@ -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: 1.0.0+1
version: 1.0.0+13

environment:
sdk: '>=3.0.5 <4.0.0'
Expand Down Expand Up @@ -67,6 +67,7 @@ dependencies:
firebase_messaging: ^14.7.3
cached_network_svg_image: ^0.0.7
flutter_html_svg: ^3.0.0-beta.2
package_info_plus: ^5.0.1

dev_dependencies:
build_runner: null
Expand Down

0 comments on commit c1f96fe

Please sign in to comment.