diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 856453b..ebac102 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -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 diff --git a/lib/core/constants/my_api.dart b/lib/core/constants/my_api.dart index b1ba034..e22ef53 100644 --- a/lib/core/constants/my_api.dart +++ b/lib/core/constants/my_api.dart @@ -7,5 +7,15 @@ class MyApi { static const String contentType = 'application/json'; static const String defaultError = 'An unexpected error has occurred.'; - static const String baseUrl = 'https://api.BASE_URL.com'; + static const String baseUrl = 'https://shiamind.newhorizonco.uk'; + + /// Backend + static const String backend = '/backend/api'; + + /// Topics + static const String topics = '$backend/topics/'; + + /// Tokens + static const String guestToken = '$backend/player/guest-token/'; + static const String centrifugoToken = '$backend/player/centrifugo-connect/'; } diff --git a/lib/core/network/interceptors/token_interceptor.dart b/lib/core/network/interceptors/token_interceptor.dart index c509284..55d7a1a 100644 --- a/lib/core/network/interceptors/token_interceptor.dart +++ b/lib/core/network/interceptors/token_interceptor.dart @@ -4,7 +4,7 @@ import 'package:shia_game_flutter/core/auth_storage/auth_storage.dart'; class TokenInterceptor extends Interceptor { @override void onRequest(RequestOptions options, RequestInterceptorHandler handler) { - options.headers['Authorization'] = 'Bearer ${AuthStorage.token}'; + options.headers['X-Player-Token'] = AuthStorage.token; handler.next(options); } } diff --git a/lib/core/params/awards_params.dart b/lib/core/params/awards_params.dart index 63bc3a0..9e1761c 100644 --- a/lib/core/params/awards_params.dart +++ b/lib/core/params/awards_params.dart @@ -2,12 +2,4 @@ class AwardsParams { int? id; AwardsParams({this.id}); - - AwardsParams copyWith({ - int? id, - }) { - return AwardsParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/params/bl_question_params.dart b/lib/core/params/bl_question_params.dart index aea905b..83a0165 100644 --- a/lib/core/params/bl_question_params.dart +++ b/lib/core/params/bl_question_params.dart @@ -2,12 +2,4 @@ class BLQuestionParams { int? id; BLQuestionParams({this.id}); - - BLQuestionParams copyWith({ - int? id, - }) { - return BLQuestionParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/params/home_params.dart b/lib/core/params/home_params.dart index 22518f3..18d1bee 100644 --- a/lib/core/params/home_params.dart +++ b/lib/core/params/home_params.dart @@ -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 get toGuestJson => { + if (username != null) 'username': username, + }; } diff --git a/lib/core/params/intro_params.dart b/lib/core/params/intro_params.dart index b3875c8..de39cbb 100644 --- a/lib/core/params/intro_params.dart +++ b/lib/core/params/intro_params.dart @@ -2,12 +2,4 @@ class IntroParams { int? id; IntroParams({this.id}); - - IntroParams copyWith({ - int? id, - }) { - return IntroParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/params/master_params.dart b/lib/core/params/master_params.dart index 62509d2..93bbcc3 100644 --- a/lib/core/params/master_params.dart +++ b/lib/core/params/master_params.dart @@ -2,12 +2,4 @@ class MasterParams { int? id; MasterParams({this.id}); - - MasterParams copyWith({ - int? id, - }) { - return MasterParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/params/profile_params.dart b/lib/core/params/profile_params.dart index 9c62c23..06d6c59 100644 --- a/lib/core/params/profile_params.dart +++ b/lib/core/params/profile_params.dart @@ -2,12 +2,4 @@ class ProfileParams { int? id; ProfileParams({this.id}); - - ProfileParams copyWith({ - int? id, - }) { - return ProfileParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/params/sample_params.dart b/lib/core/params/sample_params.dart index 8a21fab..3a22f0b 100644 --- a/lib/core/params/sample_params.dart +++ b/lib/core/params/sample_params.dart @@ -2,12 +2,4 @@ class SampleParams { int? id; SampleParams({this.id}); - - SampleParams copyWith({ - int? id, - }) { - return SampleParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/params/shop_params.dart b/lib/core/params/shop_params.dart index 6d3537b..011c914 100644 --- a/lib/core/params/shop_params.dart +++ b/lib/core/params/shop_params.dart @@ -2,12 +2,4 @@ class ShopParams { int? id; ShopParams({this.id}); - - ShopParams copyWith({ - int? id, - }) { - return ShopParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/params/topic_params.dart b/lib/core/params/topic_params.dart index edf044f..bf52519 100644 --- a/lib/core/params/topic_params.dart +++ b/lib/core/params/topic_params.dart @@ -2,12 +2,4 @@ class TopicParams { int? id; TopicParams({this.id}); - - TopicParams copyWith({ - int? id, - }) { - return TopicParams( - id: id ?? this.id, - ); - } } diff --git a/lib/core/status/base_status.dart b/lib/core/status/base_status.dart index c44ba27..2055fa4 100644 --- a/lib/core/status/base_status.dart +++ b/lib/core/status/base_status.dart @@ -18,14 +18,10 @@ class BaseNotAuth extends BaseStatus { const BaseNotAuth(); } -class BaseComplete extends BaseStatus { - final T data; - - const BaseComplete(this.data); +class BaseComplete extends BaseStatus { + const BaseComplete(); } class BaseError extends BaseStatus { - final String errorMessage; - - const BaseError(this.errorMessage); + const BaseError(); } diff --git a/lib/core/widgets/container/my_container.dart b/lib/core/widgets/container/my_container.dart index b40dba0..e7b1130 100644 --- a/lib/core/widgets/container/my_container.dart +++ b/lib/core/widgets/container/my_container.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:shia_game_flutter/common_ui/theme/my_theme.dart'; +import 'package:shia_game_flutter/core/widgets/loading/my_loading.dart'; class MyContainer extends StatelessWidget { const MyContainer({ @@ -7,6 +8,7 @@ class MyContainer extends StatelessWidget { this.width, this.height, this.padding, + this.margin, this.boxShape, this.borderGradient, this.borderRadius, @@ -17,12 +19,13 @@ class MyContainer extends StatelessWidget { this.gradient, this.borderColor, this.onTap, - this.inset, + this.loading = false, }); final double? width; final double? height; final EdgeInsetsGeometry? padding; + final EdgeInsetsGeometry? margin; final BoxShape? boxShape; final Gradient? borderGradient; final Gradient? gradient; @@ -33,44 +36,47 @@ class MyContainer extends StatelessWidget { final Widget? child; final DecorationImage? image; final VoidCallback? onTap; - final bool? inset; + final bool loading; @override Widget build(BuildContext context) { - return Material( - color: context.noColor, - borderRadius: boxShape == BoxShape.circle - ? const BorderRadius.all(Radius.circular(100)) - : borderRadius, - shadowColor: boxShadow?.first.color, - elevation: boxShadow?.first.blurRadius ?? 0, - child: InkWell( - onTap: onTap, - customBorder: RoundedRectangleBorder( - borderRadius: boxShape == BoxShape.circle - ? const BorderRadius.all(Radius.circular(100)) - : borderRadius ?? BorderRadius.zero, - ), - child: Ink( - padding: const EdgeInsets.all(1), - width: width, - height: height, - decoration: BoxDecoration( - shape: boxShape ?? BoxShape.rectangle, - gradient: borderGradient, - borderRadius: borderRadius, - color: borderColor, + return Padding( + padding: margin ?? EdgeInsets.zero, + child: Material( + color: context.noColor, + borderRadius: boxShape == BoxShape.circle + ? const BorderRadius.all(Radius.circular(100)) + : borderRadius, + shadowColor: boxShadow?.first.color, + elevation: boxShadow?.first.blurRadius ?? 0, + child: InkWell( + onTap: loading ? null : onTap, + customBorder: RoundedRectangleBorder( + borderRadius: boxShape == BoxShape.circle + ? const BorderRadius.all(Radius.circular(100)) + : borderRadius ?? BorderRadius.zero, ), child: Ink( - padding: padding, + padding: const EdgeInsets.all(1), + width: width, + height: height, decoration: BoxDecoration( shape: boxShape ?? BoxShape.rectangle, - gradient: gradient, + gradient: borderGradient, borderRadius: borderRadius, - color: color, - image: image, + color: borderColor, + ), + child: Ink( + padding: padding, + decoration: BoxDecoration( + shape: boxShape ?? BoxShape.rectangle, + gradient: gradient, + borderRadius: borderRadius, + color: color, + image: image, + ), + child: Center(child: loading ? const MyLoading() : child), ), - child: Center(child: child), ), ), ), diff --git a/lib/core/widgets/input/my_input.dart b/lib/core/widgets/input/my_input.dart index 713fe3c..db78391 100644 --- a/lib/core/widgets/input/my_input.dart +++ b/lib/core/widgets/input/my_input.dart @@ -14,7 +14,7 @@ class MyInput extends StatelessWidget { this.validator, this.onChanged, this.onTap, - this.onEditingComplete, + this.onFieldSubmitted, this.onTapOutside, this.enabled, this.readOnly, @@ -28,11 +28,11 @@ class MyInput extends StatelessWidget { final bool? obscureText; final TextInputType? keyboardType; final TextInputAction? action; - final String? Function(String?)? validator; - final void Function(String)? onChanged; + final String? Function(String? value)? validator; + final void Function(String value)? onChanged; final void Function()? onTap; - final void Function()? onEditingComplete; - final void Function(PointerDownEvent)? onTapOutside; + final void Function(String value)? onFieldSubmitted; + final void Function(PointerDownEvent event)? onTapOutside; final bool? enabled; final bool? readOnly; final int? maxLines; @@ -52,16 +52,16 @@ class MyInput extends StatelessWidget { TextFormField( controller: controller, obscureText: obscureText ?? false, - keyboardType: keyboardType, - textInputAction: action, + keyboardType: keyboardType ?? TextInputType.text, + textInputAction: action ?? TextInputAction.done, validator: validator, onChanged: onChanged, onTap: onTap, - onEditingComplete: onEditingComplete, + onFieldSubmitted: onFieldSubmitted, enabled: enabled, readOnly: readOnly ?? false, - maxLines: maxLines, - minLines: minLines, + maxLines: maxLines ?? 1, + minLines: minLines ?? 1, style: Lexend.extraBold.copyWith(fontSize: 12), cursorColor: context.primaryColor, decoration: InputDecoration( diff --git a/lib/core/widgets/loading/my_loading.dart b/lib/core/widgets/loading/my_loading.dart new file mode 100644 index 0000000..501e66f --- /dev/null +++ b/lib/core/widgets/loading/my_loading.dart @@ -0,0 +1,11 @@ +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 CupertinoActivityIndicator(color: MyColors.white); + } +} diff --git a/lib/features/home/data/datasource/home_datasource.dart b/lib/features/home/data/datasource/home_datasource.dart index 5cb70c4..15811cf 100644 --- a/lib/features/home/data/datasource/home_datasource.dart +++ b/lib/features/home/data/datasource/home_datasource.dart @@ -2,11 +2,11 @@ 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/home_params.dart'; import 'package:shia_game_flutter/core/response/base_response.dart'; -import 'package:shia_game_flutter/features/home/data/model/home_model.dart'; -import 'package:shia_game_flutter/features/home/domain/entity/home_entity.dart'; +import 'package:shia_game_flutter/features/home/data/model/guest_player_model.dart'; +import 'package:shia_game_flutter/features/home/domain/entity/guest_player_entity.dart'; abstract class IHomeDatasource { - Future getData({required HomeParams params}); + Future loginGuest({required HomeParams params}); } class HomeDatasourceImpl implements IHomeDatasource { @@ -15,14 +15,15 @@ class HomeDatasourceImpl implements IHomeDatasource { const HomeDatasourceImpl(this.httpRequest); @override - Future getData({required HomeParams params}) async { - final response = await httpRequest.get( - path: MyApi.baseUrl, + Future loginGuest({required HomeParams params}) async { + final response = await httpRequest.post( + path: MyApi.guestToken, + data: params.toGuestJson, ); - return BaseResponse.getData( - response?['data'], - (json) => HomeModel.fromJson(json), + return BaseResponse.getData( + response, + (json) => GuestPlayerModel.fromJson(json), ); } } diff --git a/lib/features/home/data/model/guest_player_model.dart b/lib/features/home/data/model/guest_player_model.dart new file mode 100644 index 0000000..41a41ce --- /dev/null +++ b/lib/features/home/data/model/guest_player_model.dart @@ -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 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']), + ); + } +} diff --git a/lib/features/home/data/model/home_model.dart b/lib/features/home/data/model/home_model.dart deleted file mode 100644 index b1d2b84..0000000 --- a/lib/features/home/data/model/home_model.dart +++ /dev/null @@ -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 json) { - return HomeModel( - id: json['id'], - ); - } -} diff --git a/lib/features/home/data/repository_impl/home_repository_impl.dart b/lib/features/home/data/repository_impl/home_repository_impl.dart index 203d244..b9d2cf5 100644 --- a/lib/features/home/data/repository_impl/home_repository_impl.dart +++ b/lib/features/home/data/repository_impl/home_repository_impl.dart @@ -3,7 +3,7 @@ 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/data/datasource/home_datasource.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'; import 'package:shia_game_flutter/features/home/domain/repository/home_repository.dart'; class HomeRepositoryImpl implements IHomeRepository { @@ -12,9 +12,13 @@ class HomeRepositoryImpl implements IHomeRepository { const HomeRepositoryImpl(this.datasource); @override - Future> getData({required HomeParams params}) async { + Future> loginGuest({ + required HomeParams params, + }) async { try { - final HomeEntity response = await datasource.getData(params: params); + final GuestPlayerEntity response = await datasource.loginGuest( + params: params, + ); return DataState.success(response); } on MyException catch (e) { return DataState.error(e); diff --git a/lib/features/home/domain/entity/guest_player_entity.dart b/lib/features/home/domain/entity/guest_player_entity.dart new file mode 100644 index 0000000..6c28e70 --- /dev/null +++ b/lib/features/home/domain/entity/guest_player_entity.dart @@ -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 get props => [ + playerID, + playerToken, + username, + isGuest, + createdAt, + ]; +} diff --git a/lib/features/home/domain/entity/home_entity.dart b/lib/features/home/domain/entity/home_entity.dart deleted file mode 100644 index 582723c..0000000 --- a/lib/features/home/domain/entity/home_entity.dart +++ /dev/null @@ -1,14 +0,0 @@ -import 'package:equatable/equatable.dart'; - -class HomeEntity extends Equatable { - final int? id; - - const HomeEntity({ - this.id, - }); - - @override - List get props => [ - id, - ]; -} diff --git a/lib/features/home/domain/repository/home_repository.dart b/lib/features/home/domain/repository/home_repository.dart index 71709c3..0fccd3d 100644 --- a/lib/features/home/domain/repository/home_repository.dart +++ b/lib/features/home/domain/repository/home_repository.dart @@ -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> getData({required HomeParams params}); + Future> loginGuest({required HomeParams params}); } diff --git a/lib/features/home/domain/usecases/get_home_usecase.dart b/lib/features/home/domain/usecases/login_guest_usecase.dart similarity index 54% rename from lib/features/home/domain/usecases/get_home_usecase.dart rename to lib/features/home/domain/usecases/login_guest_usecase.dart index dc2ad83..a8d1c2d 100644 --- a/lib/features/home/domain/usecases/get_home_usecase.dart +++ b/lib/features/home/domain/usecases/login_guest_usecase.dart @@ -2,16 +2,16 @@ 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/usecase/usecase.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'; import 'package:shia_game_flutter/features/home/domain/repository/home_repository.dart'; -class GetHomeUseCase implements UseCase { +class LoginGuestUseCase implements UseCase { final IHomeRepository repository; - const GetHomeUseCase(this.repository); + const LoginGuestUseCase(this.repository); @override - Future> call(HomeParams params) { - return repository.getData(params: params); + Future> call(HomeParams params) { + return repository.loginGuest(params: params); } } diff --git a/lib/features/home/presentation/controller/home_controller.dart b/lib/features/home/presentation/controller/home_controller.dart index f221868..b7ed054 100644 --- a/lib/features/home/presentation/controller/home_controller.dart +++ b/lib/features/home/presentation/controller/home_controller.dart @@ -1,58 +1,75 @@ 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 = Rx(HomeParams()); - final Rx homeEntity = Rx(const HomeEntity()); + final HomeParams homeParams = HomeParams(); + final Rx guestEntity = Rx(const GuestPlayerEntity()); /// ------ Controllers ------ - final TextEditingController textEditingController = TextEditingController(); + final TextEditingController usernameController = TextEditingController(); /// ------ Statuses ------ - final Rx getHomeStatus = Rx(const BaseInit()); + final Rx loginGuestStatus = Rx(const BaseInit()); /// ------ Functions ------ void goToBattleLeaguePage() { Get.toNamed(Routes.battleLeaguePage); } - /// ------ Api Calls ------ - Future 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 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 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 = const BaseError(); + }, + ), + ); + } + } } diff --git a/lib/features/home/presentation/pages/home_page.dart b/lib/features/home/presentation/pages/home_page.dart index 42aab98..dfaf39e 100644 --- a/lib/features/home/presentation/pages/home_page.dart +++ b/lib/features/home/presentation/pages/home_page.dart @@ -21,12 +21,10 @@ class HomePage extends GetView { return MyBackground( child: Column( children: [ - const MyImage(asset: MyAssets.shiaMindGroup), + _image(), 40.h.gapHeight, const HomeMembership(), - HomeBattleLeague( - onTap: controller.goToBattleLeaguePage, - ), + _homeBattleLeague(), 20.h.gapHeight, _customWidgets(context), 20.h.gapHeight, @@ -36,6 +34,16 @@ class HomePage extends GetView { ); } + MyImage _image() { + return const MyImage(asset: MyAssets.shiaMindGroup); + } + + HomeBattleLeague _homeBattleLeague() { + return HomeBattleLeague( + onTap: controller.goToBattleLeaguePage, + ); + } + Widget _customWidgets(BuildContext context) { return Row( spacing: 20, diff --git a/lib/features/home/presentation/pages/widgets/home_username_dialog.dart b/lib/features/home/presentation/pages/widgets/home_username_dialog.dart new file mode 100644 index 0000000..747f8f5 --- /dev/null +++ b/lib/features/home/presentation/pages/widgets/home_username_dialog.dart @@ -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 { + 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), + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/init_bindings.dart b/lib/init_bindings.dart index 8cf4318..113ff8b 100644 --- a/lib/init_bindings.dart +++ b/lib/init_bindings.dart @@ -16,7 +16,7 @@ import 'package:shia_game_flutter/features/battle_league/question_part/bl_questi import 'package:shia_game_flutter/features/home/data/datasource/home_datasource.dart'; import 'package:shia_game_flutter/features/home/data/repository_impl/home_repository_impl.dart'; import 'package:shia_game_flutter/features/home/domain/repository/home_repository.dart'; -import 'package:shia_game_flutter/features/home/domain/usecases/get_home_usecase.dart'; +import 'package:shia_game_flutter/features/home/domain/usecases/login_guest_usecase.dart'; import 'package:shia_game_flutter/features/intro/data/datasource/intro_datasource.dart'; import 'package:shia_game_flutter/features/intro/data/repository_impl/intro_repository_impl.dart'; import 'package:shia_game_flutter/features/intro/domain/repository/intro_repository.dart'; @@ -53,14 +53,14 @@ void initBindings() { Get.lazyPut(() => GetIntroUseCase(Get.find())); /// ----- Master Feature ----- - Get.lazyPut(() => MasterDatasourceImpl(Get.find())); - Get.lazyPut(() => MasterRepositoryImpl(Get.find())); - Get.lazyPut(() => GetMasterUseCase(Get.find())); + Get.lazyPut(() => MasterDatasourceImpl(Get.find()), fenix: true); + Get.lazyPut(() => MasterRepositoryImpl(Get.find()), fenix: true); + Get.lazyPut(() => GetMasterUseCase(Get.find()), fenix: true); /// ----- Home Feature ----- Get.lazyPut(() => HomeDatasourceImpl(Get.find()), fenix: true); Get.lazyPut(() => HomeRepositoryImpl(Get.find()), fenix: true); - Get.lazyPut(() => GetHomeUseCase(Get.find()), fenix: true); + Get.lazyPut(() => LoginGuestUseCase(Get.find()), fenix: true); /// ----- Shop Feature ----- Get.lazyPut(() => ShopDatasourceImpl(Get.find()), fenix: true); diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 13ea525..b6c63ff 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -49,5 +49,7 @@ "quiz_league": "Quiz league", "your_place": "Your place", "finding_player": "Finding player ...", - "find_hint": "The fastest player to answer the question correctly gets the point." + "find_hint": "The fastest player to answer the question correctly gets the point.", + "welcome": "Welcome", + "done": "Done" } \ No newline at end of file diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index ae41b97..7699c75 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -393,6 +393,18 @@ abstract class AppLocalizations { /// In en, this message translates to: /// **'The fastest player to answer the question correctly gets the point.'** String get find_hint; + + /// No description provided for @welcome. + /// + /// In en, this message translates to: + /// **'Welcome'** + String get welcome; + + /// No description provided for @done. + /// + /// In en, this message translates to: + /// **'Done'** + String get done; } class _AppLocalizationsDelegate diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 6af744c..1bf3bc6 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -158,4 +158,10 @@ class AppLocalizationsEn extends AppLocalizations { @override String get find_hint => 'The fastest player to answer the question correctly gets the point.'; + + @override + String get welcome => 'Welcome'; + + @override + String get done => 'Done'; } diff --git a/lib/main.dart b/lib/main.dart index 575b79b..91e7d2f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -31,7 +31,7 @@ class MainApp extends StatelessWidget { fallbackLocale: const Locale('en', 'US'), supportedLocales: const [Locale('en', 'US')], getPages: appPages, - initialRoute: Routes.battleLeagueQuestionPage, + initialRoute: Routes.masterPage, localizationsDelegates: const [ AppLocalizations.delegate, GlobalMaterialLocalizations.delegate,