Browse Source
Merge pull request 'feature/centrifugo' (#17) from feature/centrifugo into develop
Merge pull request 'feature/centrifugo' (#17) from feature/centrifugo into develop
Reviewed-on: #17pull/18/head
48 changed files with 678 additions and 341 deletions
-
10ios/Podfile.lock
-
9lib/core/constants/my_api.dart
-
19lib/core/error_handler/error_handler.dart
-
1lib/core/network/http_request_impl.dart
-
4lib/core/network/interceptors/logging_interceptor.dart
-
2lib/core/network/interceptors/token_interceptor.dart
-
8lib/core/params/awards_params.dart
-
5lib/core/params/battle_league_params.dart
-
8lib/core/params/bl_question_params.dart
-
14lib/core/params/home_params.dart
-
8lib/core/params/intro_params.dart
-
8lib/core/params/master_params.dart
-
8lib/core/params/profile_params.dart
-
8lib/core/params/sample_params.dart
-
8lib/core/params/shop_params.dart
-
13lib/core/params/topic_params.dart
-
9lib/core/status/base_status.dart
-
16lib/core/utils/local_storage.dart
-
66lib/core/widgets/container/my_container.dart
-
20lib/core/widgets/input/my_input.dart
-
13lib/core/widgets/loading/my_loading.dart
-
23lib/features/battle_league/first_part/data/datasource/battle_league_datasource.dart
-
41lib/features/battle_league/first_part/data/model/topics_model.dart
-
13lib/features/battle_league/first_part/data/repository_impl/battle_league_repository_impl.dart
-
50lib/features/battle_league/first_part/domain/entity/topics_entity.dart
-
9lib/features/battle_league/first_part/domain/repository/battle_league_repository.dart
-
14lib/features/battle_league/first_part/domain/usecases/get_topics_usecase.dart
-
39lib/features/battle_league/first_part/presentation/controller/battle_league_controller.dart
-
63lib/features/battle_league/first_part/presentation/ui/battle_league_topic_page.dart
-
11lib/features/battle_league/first_part/presentation/ui/widgets/topic_page/topic_widget.dart
-
19lib/features/home/data/datasource/home_datasource.dart
-
23lib/features/home/data/model/guest_player_model.dart
-
13lib/features/home/data/model/home_model.dart
-
10lib/features/home/data/repository_impl/home_repository_impl.dart
-
26lib/features/home/domain/entity/guest_player_entity.dart
-
14lib/features/home/domain/entity/home_entity.dart
-
4lib/features/home/domain/repository/home_repository.dart
-
10lib/features/home/domain/usecases/login_guest_usecase.dart
-
66lib/features/home/presentation/controller/home_controller.dart
-
16lib/features/home/presentation/pages/home_page.dart
-
80lib/features/home/presentation/pages/widgets/home_username_dialog.dart
-
14lib/init_bindings.dart
-
5lib/l10n/app_en.arb
-
18lib/l10n/app_localizations.dart
-
10lib/l10n/app_localizations_en.dart
-
6lib/main.dart
-
159pubspec.lock
-
4pubspec.yaml
@ -1,22 +1,22 @@ |
|||
PODS: |
|||
- Flutter (1.0.0) |
|||
- path_provider_foundation (0.0.1): |
|||
- shared_preferences_foundation (0.0.1): |
|||
- Flutter |
|||
- FlutterMacOS |
|||
|
|||
DEPENDENCIES: |
|||
- Flutter (from `Flutter`) |
|||
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) |
|||
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) |
|||
|
|||
EXTERNAL SOURCES: |
|||
Flutter: |
|||
:path: Flutter |
|||
path_provider_foundation: |
|||
:path: ".symlinks/plugins/path_provider_foundation/darwin" |
|||
shared_preferences_foundation: |
|||
:path: ".symlinks/plugins/shared_preferences_foundation/darwin" |
|||
|
|||
SPEC CHECKSUMS: |
|||
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467 |
|||
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564 |
|||
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb |
|||
|
|||
PODFILE CHECKSUM: 3c63482e143d1b91d2d2560aee9fb04ecc74ac7e |
|||
|
|||
|
|||
@ -0,0 +1,5 @@ |
|||
class BattleLeagueParams { |
|||
int? id; |
|||
|
|||
BattleLeagueParams({this.id}); |
|||
} |
|||
@ -1,13 +1,9 @@ |
|||
class HomeParams { |
|||
int? id; |
|||
String? username; |
|||
|
|||
HomeParams({this.id}); |
|||
HomeParams({this.username}); |
|||
|
|||
HomeParams copyWith({ |
|||
int? id, |
|||
}) { |
|||
return HomeParams( |
|||
id: id ?? this.id, |
|||
); |
|||
} |
|||
Map<String, dynamic> get toGuestJson => { |
|||
if (username != null) 'username': username, |
|||
}; |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
class TopicParams { |
|||
int? id; |
|||
|
|||
TopicParams({this.id}); |
|||
|
|||
TopicParams copyWith({ |
|||
int? id, |
|||
}) { |
|||
return TopicParams( |
|||
id: id ?? this.id, |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
import 'package:flutter/cupertino.dart'; |
|||
import 'package:shia_game_flutter/common_ui/resources/my_colors.dart'; |
|||
|
|||
class MyLoading extends StatelessWidget { |
|||
const MyLoading({super.key}); |
|||
|
|||
@override |
|||
Widget build(BuildContext context) { |
|||
return const Center( |
|||
child: CupertinoActivityIndicator(color: MyColors.white), |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
import 'package:shia_game_flutter/features/battle_league/first_part/domain/entity/topics_entity.dart'; |
|||
|
|||
class TopicsModel extends TopicsEntity { |
|||
const TopicsModel({ |
|||
super.id, |
|||
super.slug, |
|||
super.title, |
|||
super.description, |
|||
super.icon, |
|||
super.iconUrl, |
|||
super.order, |
|||
super.isActive, |
|||
super.difficultyLevel, |
|||
super.difficultyDisplay, |
|||
super.questionsCount, |
|||
super.createdAt, |
|||
super.updatedAt, |
|||
}); |
|||
|
|||
factory TopicsModel.fromJson(Map<String, dynamic> json) { |
|||
return TopicsModel( |
|||
id: json['id'], |
|||
slug: json['slug'], |
|||
title: json['title'], |
|||
description: json['description'], |
|||
icon: json['icon'], |
|||
iconUrl: json['icon_url'], |
|||
order: json['order'], |
|||
isActive: json['is_active'], |
|||
difficultyLevel: json['difficulty_level'], |
|||
difficultyDisplay: json['difficulty_display'], |
|||
questionsCount: json['questions_count'], |
|||
createdAt: json['created_at'] == null |
|||
? null |
|||
: DateTime.parse(json['created_at']), |
|||
updatedAt: json['updated_at'] == null |
|||
? null |
|||
: DateTime.parse(json['updated_at']), |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
import 'package:equatable/equatable.dart'; |
|||
|
|||
class TopicsEntity extends Equatable { |
|||
final int? id; |
|||
final String? slug; |
|||
final String? title; |
|||
final String? description; |
|||
final String? icon; |
|||
final String? iconUrl; |
|||
final int? order; |
|||
final bool? isActive; |
|||
final String? difficultyLevel; |
|||
final String? difficultyDisplay; |
|||
final int? questionsCount; |
|||
final DateTime? createdAt; |
|||
final DateTime? updatedAt; |
|||
|
|||
const TopicsEntity({ |
|||
this.id, |
|||
this.slug, |
|||
this.title, |
|||
this.description, |
|||
this.icon, |
|||
this.iconUrl, |
|||
this.order, |
|||
this.isActive, |
|||
this.difficultyLevel, |
|||
this.difficultyDisplay, |
|||
this.questionsCount, |
|||
this.createdAt, |
|||
this.updatedAt, |
|||
}); |
|||
|
|||
@override |
|||
List<Object?> get props => [ |
|||
id, |
|||
slug, |
|||
title, |
|||
description, |
|||
icon, |
|||
iconUrl, |
|||
order, |
|||
isActive, |
|||
difficultyLevel, |
|||
difficultyDisplay, |
|||
questionsCount, |
|||
createdAt, |
|||
updatedAt, |
|||
]; |
|||
} |
|||
@ -1,9 +1,10 @@ |
|||
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
|||
import 'package:shia_game_flutter/core/params/sample_params.dart'; |
|||
import 'package:shia_game_flutter/core/params/battle_league_params.dart'; |
|||
import 'package:shia_game_flutter/core/utils/data_state.dart'; |
|||
import 'package:shia_game_flutter/features/battle_league/first_part/domain/entity/battle_league_entity.dart'; |
|||
import 'package:shia_game_flutter/features/battle_league/first_part/domain/entity/topics_entity.dart'; |
|||
|
|||
abstract class IBattleLeagueRepository { |
|||
Future<DataState<BattleLeagueEntity, MyException>> getData({required SampleParams params}); |
|||
Future<DataState<List<TopicsEntity>, MyException>> getTopics({ |
|||
required BattleLeagueParams params, |
|||
}); |
|||
} |
|||
|
|||
@ -1,18 +1,18 @@ |
|||
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
|||
import 'package:shia_game_flutter/core/params/sample_params.dart'; |
|||
import 'package:shia_game_flutter/core/params/battle_league_params.dart'; |
|||
import 'package:shia_game_flutter/core/usecase/usecase.dart'; |
|||
import 'package:shia_game_flutter/core/utils/data_state.dart'; |
|||
import 'package:shia_game_flutter/features/battle_league/first_part/domain/entity/battle_league_entity.dart'; |
|||
import 'package:shia_game_flutter/features/battle_league/first_part/domain/entity/topics_entity.dart'; |
|||
import 'package:shia_game_flutter/features/battle_league/first_part/domain/repository/battle_league_repository.dart'; |
|||
|
|||
class GetBattleLeagueUseCase implements UseCase<BattleLeagueEntity, SampleParams> { |
|||
class GetTopicsUseCase |
|||
implements UseCase<List<TopicsEntity>, BattleLeagueParams> { |
|||
final IBattleLeagueRepository repository; |
|||
|
|||
const GetBattleLeagueUseCase(this.repository); |
|||
const GetTopicsUseCase(this.repository); |
|||
|
|||
@override |
|||
Future<DataState<BattleLeagueEntity, MyException>> call(SampleParams params) { |
|||
return repository.getData(params: params); |
|||
Future<DataState<List<TopicsEntity>, MyException>> call(BattleLeagueParams params,) { |
|||
return repository.getTopics(params: params); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,23 @@ |
|||
import 'package:shia_game_flutter/features/home/domain/entity/guest_player_entity.dart'; |
|||
|
|||
class GuestPlayerModel extends GuestPlayerEntity { |
|||
const GuestPlayerModel({ |
|||
super.playerID, |
|||
super.playerToken, |
|||
super.username, |
|||
super.isGuest, |
|||
super.createdAt, |
|||
}); |
|||
|
|||
factory GuestPlayerModel.fromJson(Map<String, dynamic> json) { |
|||
return GuestPlayerModel( |
|||
playerID: json['player_id'], |
|||
playerToken: json['player_token'], |
|||
username: json['username'], |
|||
isGuest: json['is_guest'], |
|||
createdAt: json['created_at'] == null |
|||
? null |
|||
: DateTime.parse(json['created_at']), |
|||
); |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
import 'package:shia_game_flutter/features/home/domain/entity/home_entity.dart'; |
|||
|
|||
class HomeModel extends HomeEntity { |
|||
const HomeModel({ |
|||
super.id, |
|||
}); |
|||
|
|||
factory HomeModel.fromJson(Map<String, dynamic> json) { |
|||
return HomeModel( |
|||
id: json['id'], |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
import 'package:equatable/equatable.dart'; |
|||
|
|||
class GuestPlayerEntity extends Equatable { |
|||
final String? playerID; |
|||
final String? playerToken; |
|||
final String? username; |
|||
final bool? isGuest; |
|||
final DateTime? createdAt; |
|||
|
|||
const GuestPlayerEntity({ |
|||
this.playerID, |
|||
this.playerToken, |
|||
this.username, |
|||
this.isGuest, |
|||
this.createdAt, |
|||
}); |
|||
|
|||
@override |
|||
List<Object?> get props => [ |
|||
playerID, |
|||
playerToken, |
|||
username, |
|||
isGuest, |
|||
createdAt, |
|||
]; |
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
import 'package:equatable/equatable.dart'; |
|||
|
|||
class HomeEntity extends Equatable { |
|||
final int? id; |
|||
|
|||
const HomeEntity({ |
|||
this.id, |
|||
}); |
|||
|
|||
@override |
|||
List<Object?> get props => [ |
|||
id, |
|||
]; |
|||
} |
|||
@ -1,8 +1,8 @@ |
|||
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
|||
import 'package:shia_game_flutter/core/params/home_params.dart'; |
|||
import 'package:shia_game_flutter/core/utils/data_state.dart'; |
|||
import 'package:shia_game_flutter/features/home/domain/entity/home_entity.dart'; |
|||
import 'package:shia_game_flutter/features/home/domain/entity/guest_player_entity.dart'; |
|||
|
|||
abstract class IHomeRepository { |
|||
Future<DataState<HomeEntity, MyException>> getData({required HomeParams params}); |
|||
Future<DataState<GuestPlayerEntity, MyException>> loginGuest({required HomeParams params}); |
|||
} |
|||
@ -1,58 +1,76 @@ |
|||
import 'package:flutter/cupertino.dart'; |
|||
import 'package:get/get.dart'; |
|||
import 'package:shia_game_flutter/common_ui/resources/my_colors.dart'; |
|||
import 'package:shia_game_flutter/core/auth_storage/auth_storage.dart'; |
|||
import 'package:shia_game_flutter/core/params/home_params.dart'; |
|||
import 'package:shia_game_flutter/core/routers/my_routes.dart'; |
|||
import 'package:shia_game_flutter/core/status/base_status.dart'; |
|||
import 'package:shia_game_flutter/features/home/domain/entity/home_entity.dart'; |
|||
import 'package:shia_game_flutter/features/home/domain/usecases/get_home_usecase.dart'; |
|||
import 'package:shia_game_flutter/features/home/presentation/pages/widgets/home_username_dialog.dart'; |
|||
import 'package:shia_game_flutter/features/home/domain/entity/guest_player_entity.dart'; |
|||
import 'package:shia_game_flutter/features/home/domain/usecases/login_guest_usecase.dart'; |
|||
|
|||
class HomeController extends GetxController with StateMixin { |
|||
class HomeController extends GetxController { |
|||
/// ----- Constructor ----- |
|||
HomeController(this.getHomeUseCase); |
|||
HomeController(this._loginGuestUseCase); |
|||
|
|||
@override |
|||
void onInit() { |
|||
super.onInit(); |
|||
change('', status: RxStatus.success()); |
|||
showUsernameDialog(); |
|||
} |
|||
|
|||
@override |
|||
void onClose() { |
|||
textEditingController.dispose(); |
|||
usernameController.dispose(); |
|||
super.onClose(); |
|||
} |
|||
|
|||
/// ----- UseCases ----- |
|||
final GetHomeUseCase getHomeUseCase; |
|||
final LoginGuestUseCase _loginGuestUseCase; |
|||
|
|||
/// ----- Variables ----- |
|||
final Rx<HomeParams> homeParams = Rx(HomeParams()); |
|||
final Rx<HomeEntity> homeEntity = Rx(const HomeEntity()); |
|||
final HomeParams homeParams = HomeParams(); |
|||
final Rx<GuestPlayerEntity> guestEntity = Rx(const GuestPlayerEntity()); |
|||
|
|||
/// ------ Controllers ------ |
|||
final TextEditingController textEditingController = TextEditingController(); |
|||
final TextEditingController usernameController = TextEditingController(); |
|||
|
|||
/// ------ Statuses ------ |
|||
final Rx<BaseStatus> getHomeStatus = Rx(const BaseInit()); |
|||
final Rx<BaseStatus> loginGuestStatus = Rx(const BaseInit()); |
|||
|
|||
/// ------ Functions ------ |
|||
void goToBattleLeaguePage() { |
|||
Get.toNamed(Routes.battleLeaguePage); |
|||
} |
|||
|
|||
/// ------ Api Calls ------ |
|||
Future<void> getHome() async { |
|||
change('', status: RxStatus.loading()); |
|||
await getHomeUseCase(homeParams.value).then( |
|||
(value) => value.fold( |
|||
(data) { |
|||
homeEntity.value = data; |
|||
change('', status: RxStatus.success()); |
|||
}, |
|||
(error) { |
|||
change('', status: RxStatus.error(error.errorMessage)); |
|||
}, |
|||
), |
|||
Future<void> showUsernameDialog() async { |
|||
await Future.delayed(const Duration(seconds: 1)); |
|||
Get.dialog( |
|||
const UsernameDialog(), |
|||
useSafeArea: false, |
|||
barrierColor: MyColors.black.withValues(alpha: 0.7), |
|||
barrierDismissible: false, |
|||
); |
|||
} |
|||
|
|||
/// ------ Api Calls ------ |
|||
Future<void> loginGuest() async { |
|||
if (homeParams.username?.isNotEmpty ?? false) { |
|||
loginGuestStatus.value = const BaseLoading(); |
|||
await _loginGuestUseCase(homeParams).then( |
|||
(value) => value.fold( |
|||
(data) async { |
|||
guestEntity.value = data; |
|||
await AuthStorage.saveData(newTokenParams: data.playerToken ?? ''); |
|||
Get.back(); |
|||
loginGuestStatus.value = const BaseComplete(); |
|||
}, |
|||
(error) { |
|||
loginGuestStatus.value = |
|||
BaseError(errorMessage: error.errorMessage); |
|||
}, |
|||
), |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
import 'package:flutter/cupertino.dart'; |
|||
import 'package:flutter/material.dart'; |
|||
import 'package:get/get.dart'; |
|||
import 'package:shia_game_flutter/common_ui/resources/my_text_style.dart'; |
|||
import 'package:shia_game_flutter/core/status/base_status.dart'; |
|||
import 'package:shia_game_flutter/core/utils/my_localization.dart'; |
|||
import 'package:shia_game_flutter/core/utils/screen_size.dart'; |
|||
import 'package:shia_game_flutter/core/widgets/container/my_container.dart'; |
|||
import 'package:shia_game_flutter/core/widgets/input/my_input.dart'; |
|||
import 'package:shia_game_flutter/core/widgets/text/gradient_text.dart'; |
|||
import 'package:shia_game_flutter/features/home/presentation/controller/home_controller.dart'; |
|||
|
|||
class UsernameDialog extends GetView<HomeController> { |
|||
const UsernameDialog({super.key}); |
|||
|
|||
@override |
|||
Widget build(BuildContext context) { |
|||
return MyContainer( |
|||
padding: const EdgeInsets.only(left: 30, right: 30, bottom: 30, top: 13), |
|||
margin: EdgeInsets.symmetric(horizontal: 30.w, vertical: 290.h), |
|||
borderGradient: const LinearGradient( |
|||
begin: Alignment.topCenter, |
|||
end: Alignment.bottomCenter, |
|||
colors: [Color(0XFF6013DA), Color(0XFF4908B0)], |
|||
), |
|||
gradient: const RadialGradient( |
|||
radius: 1, |
|||
colors: [Color(0XFF4F09BF), Color(0XFF350D73)], |
|||
), |
|||
borderRadius: const BorderRadius.all(Radius.circular(40)), |
|||
child: Column( |
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|||
children: [ |
|||
Text( |
|||
context.translate.welcome, |
|||
style: Lexend.extraBold.copyWith( |
|||
fontSize: 18, |
|||
color: const Color(0XFFBAA3DD), |
|||
), |
|||
), |
|||
MyInput( |
|||
controller: controller.usernameController, |
|||
labelText: context.translate.username, |
|||
onFieldSubmitted: (value) { |
|||
controller.loginGuest(); |
|||
}, |
|||
onChanged: (value) { |
|||
controller.homeParams.username = value; |
|||
}, |
|||
), |
|||
Obx( |
|||
() => MyContainer( |
|||
onTap: controller.loginGuest, |
|||
height: 41.h, |
|||
loading: controller.loginGuestStatus.value is BaseLoading, |
|||
borderRadius: const BorderRadius.all(Radius.circular(12)), |
|||
gradient: const RadialGradient( |
|||
radius: 4, |
|||
center: Alignment(-0.3, 0), |
|||
colors: [Color(0XFF6A36BF), Color(0XFF562A9E)], |
|||
), |
|||
borderGradient: LinearGradient( |
|||
begin: AlignmentDirectional.topStart, |
|||
end: AlignmentDirectional.bottomEnd, |
|||
colors: [ |
|||
const Color(0XFF7F4CD4), |
|||
const Color(0XFF7F4CD4).withValues(alpha: 0), |
|||
], |
|||
), |
|||
child: GradientText( |
|||
text: context.translate.done, |
|||
color: const Color(0XFFB69CDE), |
|||
), |
|||
), |
|||
), |
|||
], |
|||
), |
|||
); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue