19 changed files with 160 additions and 249 deletions
-
27lib/core/routers/my_routes.dart
-
9lib/features/battle_league/presentation/controller/battle_league_controller.dart
-
45lib/features/battle_league/presentation/ui/battle_league_finding_page.dart
-
67lib/features/battle_league/presentation/ui/battle_league_founded_page.dart
-
4lib/features/battle_league/presentation/ui/battle_league_page.dart
-
17lib/features/battle_league/presentation/ui/battle_league_topic_page.dart
-
4lib/features/battle_league/presentation/ui/widgets/button/battle_golden_button.dart
-
0lib/features/battle_league/presentation/ui/widgets/button/battle_grey_button.dart
-
42lib/features/battle_league/presentation/ui/widgets/button/battle_purple_button.dart
-
0lib/features/battle_league/presentation/ui/widgets/topic_widget.dart
-
28lib/features/topic/data/datasource/topic_datasource.dart
-
13lib/features/topic/data/model/topic_model.dart
-
29lib/features/topic/data/repository_impl/topic_repository_impl.dart
-
14lib/features/topic/domain/entity/topic_entity.dart
-
8lib/features/topic/domain/repository/topic_repository.dart
-
19lib/features/topic/domain/usecases/get_topic_usecase.dart
-
20lib/features/topic/presentation/binding/topic_binding.dart
-
54lib/features/topic/presentation/controller/topic_controller.dart
-
9lib/init_bindings.dart
@ -0,0 +1,67 @@ |
|||||
|
import 'package:flutter/material.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
import 'package:shia_game_flutter/common_ui/resources/my_assets.dart'; |
||||
|
import 'package:shia_game_flutter/common_ui/resources/my_colors.dart'; |
||||
|
import 'package:shia_game_flutter/common_ui/resources/my_text_style.dart'; |
||||
|
import 'package:shia_game_flutter/core/utils/gap.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/image/my_image.dart'; |
||||
|
import 'package:shia_game_flutter/features/battle_league/presentation/controller/battle_league_controller.dart'; |
||||
|
import 'package:shia_game_flutter/features/intro/presentation/ui/widgets/intro_loading.dart'; |
||||
|
|
||||
|
class BattleLeagueFoundedPage extends GetView<BattleLeagueController> { |
||||
|
const BattleLeagueFoundedPage({super.key}); |
||||
|
|
||||
|
@override |
||||
|
Widget build(BuildContext context) { |
||||
|
return Scaffold( |
||||
|
backgroundColor: MyColors.battleLeagueBackgroundColor, |
||||
|
body: SafeArea( |
||||
|
child: Padding( |
||||
|
padding: const EdgeInsets.symmetric(horizontal: 30), |
||||
|
child: Column( |
||||
|
children: [ |
||||
|
20.h.gapHeight, |
||||
|
_rankTitle(context), |
||||
|
const Spacer(), |
||||
|
const IntroLoading(), |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
Container _rankTitle(BuildContext context) { |
||||
|
return Container( |
||||
|
height: 42.h, |
||||
|
width: context.widthScreen, |
||||
|
alignment: Alignment.center, |
||||
|
padding: const EdgeInsets.symmetric(horizontal: 17), |
||||
|
decoration: const ShapeDecoration( |
||||
|
shape: StadiumBorder(), |
||||
|
color: Color(0XFF2E0869), |
||||
|
), |
||||
|
child: Row( |
||||
|
mainAxisAlignment: MainAxisAlignment.center, |
||||
|
children: [ |
||||
|
Expanded( |
||||
|
child: FittedBox( |
||||
|
child: Text( |
||||
|
'${context.translate.quiz_league} (june) | ${context.translate.your_place} (1,569)', |
||||
|
textAlign: TextAlign.center, |
||||
|
maxLines: 1, |
||||
|
style: Lexend.semiBold.copyWith(fontSize: 12.sp), |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
15.w.gapWidth, |
||||
|
const MyImage(asset: MyAssets.iconRank), |
||||
|
4.w.gapWidth, |
||||
|
Text('265', style: Lexend.bold.copyWith(fontSize: 12.sp)), |
||||
|
], |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
import 'package:flutter/material.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/text/gradient_text.dart'; |
||||
|
|
||||
|
class BattlePurpleButton extends StatelessWidget { |
||||
|
const BattlePurpleButton({super.key, this.onTap, this.label}); |
||||
|
|
||||
|
final VoidCallback? onTap; |
||||
|
final String? label; |
||||
|
|
||||
|
@override |
||||
|
Widget build(BuildContext context) { |
||||
|
return MyContainer( |
||||
|
onTap: onTap, |
||||
|
width: context.widthScreen, |
||||
|
height: 64.h, |
||||
|
borderRadius: const BorderRadius.all(Radius.circular(20)), |
||||
|
borderGradient: LinearGradient( |
||||
|
begin: AlignmentDirectional.topStart, |
||||
|
end: AlignmentDirectional.bottomEnd, |
||||
|
colors: [ |
||||
|
const Color(0XFF7F4CD4), |
||||
|
const Color(0XFF7F4CD4).withValues(alpha: 0), |
||||
|
], |
||||
|
), |
||||
|
gradient: const RadialGradient( |
||||
|
radius: 5, |
||||
|
center: Alignment(-0.5, 0), |
||||
|
colors: [Color(0xFF6A36BF), Color(0xFF562A9E)], |
||||
|
), |
||||
|
child: GradientText( |
||||
|
text: label, |
||||
|
fontSize: 22.sp, |
||||
|
color: const Color(0xFFE1E1E1), |
||||
|
offset: const Offset(0, 1.04), |
||||
|
blurRadius: 1.9, |
||||
|
shadowColor: const Color(0xFF898989), |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
} |
||||
@ -1,28 +0,0 @@ |
|||||
import 'package:shia_game_flutter/core/constants/my_api.dart'; |
|
||||
import 'package:shia_game_flutter/core/network/http_request.dart'; |
|
||||
import 'package:shia_game_flutter/core/params/topic_params.dart'; |
|
||||
import 'package:shia_game_flutter/core/response/base_response.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/data/model/topic_model.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/domain/entity/topic_entity.dart'; |
|
||||
|
|
||||
abstract class ITopicDatasource { |
|
||||
Future<TopicEntity> getData({required TopicParams params}); |
|
||||
} |
|
||||
|
|
||||
class TopicDatasourceImpl implements ITopicDatasource { |
|
||||
final IHttpRequest httpRequest; |
|
||||
|
|
||||
const TopicDatasourceImpl(this.httpRequest); |
|
||||
|
|
||||
@override |
|
||||
Future<TopicEntity> getData({required TopicParams params}) async { |
|
||||
final response = await httpRequest.get( |
|
||||
path: MyApi.baseUrl, |
|
||||
); |
|
||||
|
|
||||
return BaseResponse.getData<TopicEntity>( |
|
||||
response?['data'], |
|
||||
(json) => TopicModel.fromJson(json), |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
@ -1,13 +0,0 @@ |
|||||
import 'package:shia_game_flutter/features/topic/domain/entity/topic_entity.dart'; |
|
||||
|
|
||||
class TopicModel extends TopicEntity { |
|
||||
const TopicModel({ |
|
||||
super.id, |
|
||||
}); |
|
||||
|
|
||||
factory TopicModel.fromJson(Map<String, dynamic> json) { |
|
||||
return TopicModel( |
|
||||
id: json['id'], |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
@ -1,29 +0,0 @@ |
|||||
import 'package:flutter/foundation.dart'; |
|
||||
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
|
||||
import 'package:shia_game_flutter/core/params/topic_params.dart'; |
|
||||
import 'package:shia_game_flutter/core/utils/data_state.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/data/datasource/topic_datasource.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/domain/entity/topic_entity.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/domain/repository/topic_repository.dart'; |
|
||||
|
|
||||
class TopicRepositoryImpl implements ITopicRepository { |
|
||||
final ITopicDatasource datasource; |
|
||||
|
|
||||
const TopicRepositoryImpl(this.datasource); |
|
||||
|
|
||||
@override |
|
||||
Future<DataState<TopicEntity, MyException>> getData({required TopicParams params}) async { |
|
||||
try { |
|
||||
final TopicEntity response = await datasource.getData(params: params); |
|
||||
return DataState.success(response); |
|
||||
} on MyException catch (e) { |
|
||||
return DataState.error(e); |
|
||||
} catch (e) { |
|
||||
if (kDebugMode) { |
|
||||
rethrow; |
|
||||
} else { |
|
||||
return DataState.error(MyException(errorMessage: '$e')); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +0,0 @@ |
|||||
import 'package:equatable/equatable.dart'; |
|
||||
|
|
||||
class TopicEntity extends Equatable { |
|
||||
final int? id; |
|
||||
|
|
||||
const TopicEntity({ |
|
||||
this.id, |
|
||||
}); |
|
||||
|
|
||||
@override |
|
||||
List<Object?> get props => [ |
|
||||
id, |
|
||||
]; |
|
||||
} |
|
||||
@ -1,8 +0,0 @@ |
|||||
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
|
||||
import 'package:shia_game_flutter/core/params/topic_params.dart'; |
|
||||
import 'package:shia_game_flutter/core/utils/data_state.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/domain/entity/topic_entity.dart'; |
|
||||
|
|
||||
abstract class ITopicRepository { |
|
||||
Future<DataState<TopicEntity, MyException>> getData({required TopicParams params}); |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
import 'package:shia_game_flutter/core/error_handler/my_exception.dart'; |
|
||||
import 'package:shia_game_flutter/core/params/topic_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/topic/domain/entity/topic_entity.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/domain/repository/topic_repository.dart'; |
|
||||
|
|
||||
class GetTopicUseCase implements UseCase<TopicEntity, TopicParams> { |
|
||||
final ITopicRepository repository; |
|
||||
|
|
||||
const GetTopicUseCase(this.repository); |
|
||||
|
|
||||
@override |
|
||||
Future<DataState<TopicEntity, MyException>> call(TopicParams params) { |
|
||||
return repository.getData(params: params); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
@ -1,20 +0,0 @@ |
|||||
import 'package:shia_game_flutter/features/topic/presentation/controller/topic_controller.dart'; |
|
||||
import 'package:get/get.dart'; |
|
||||
|
|
||||
class TopicBinding extends Bindings { |
|
||||
@override |
|
||||
void dependencies() { |
|
||||
Get.put<TopicController>(TopicController(Get.find())); |
|
||||
} |
|
||||
|
|
||||
Future<void> deleteBindings() async { |
|
||||
await Future.wait([ |
|
||||
Get.delete<TopicController>(), |
|
||||
]); |
|
||||
} |
|
||||
|
|
||||
Future<void> refreshBinding() async { |
|
||||
await deleteBindings(); |
|
||||
dependencies(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,54 +0,0 @@ |
|||||
import 'package:flutter/cupertino.dart'; |
|
||||
import 'package:shia_game_flutter/core/params/topic_params.dart'; |
|
||||
import 'package:shia_game_flutter/core/status/base_status.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/domain/entity/topic_entity.dart'; |
|
||||
import 'package:shia_game_flutter/features/topic/domain/usecases/get_topic_usecase.dart'; |
|
||||
import 'package:get/get.dart'; |
|
||||
|
|
||||
class TopicController extends GetxController with StateMixin { |
|
||||
/// ----- Constructor ----- |
|
||||
TopicController(this.getTopicUseCase); |
|
||||
|
|
||||
@override |
|
||||
void onInit() { |
|
||||
super.onInit(); |
|
||||
change('', status: RxStatus.success()); |
|
||||
} |
|
||||
|
|
||||
@override |
|
||||
void onClose() { |
|
||||
textEditingController.dispose(); |
|
||||
super.onClose(); |
|
||||
} |
|
||||
|
|
||||
/// ----- UseCases ----- |
|
||||
final GetTopicUseCase getTopicUseCase; |
|
||||
|
|
||||
/// ----- Variables ----- |
|
||||
final Rx<TopicParams> topicParams = Rx(TopicParams()); |
|
||||
final Rx<TopicEntity> topicEntity = Rx(const TopicEntity()); |
|
||||
|
|
||||
/// ------ Controllers ------ |
|
||||
final TextEditingController textEditingController = TextEditingController(); |
|
||||
|
|
||||
/// ------ Statuses ------ |
|
||||
final Rx<BaseStatus> getTopicStatus = Rx(const BaseInit()); |
|
||||
|
|
||||
/// ------ Functions ------ |
|
||||
|
|
||||
/// ------ Api Calls ------ |
|
||||
Future<void> getTopic() async { |
|
||||
change('', status: RxStatus.loading()); |
|
||||
await getTopicUseCase(topicParams.value).then( |
|
||||
(value) => value.fold( |
|
||||
(data) { |
|
||||
topicEntity.value = data; |
|
||||
change('', status: RxStatus.success()); |
|
||||
}, |
|
||||
(error) { |
|
||||
change('', status: RxStatus.error(error.errorMessage)); |
|
||||
}, |
|
||||
), |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue