From 05e48ebbbe0b005c0f7d12a0e20c1dc2f53992a2 Mon Sep 17 00:00:00 2001 From: poojapandeyx Date: Wed, 10 Jul 2024 17:34:49 +0530 Subject: [PATCH] get country api --- .vscode/settings.json | 3 + assets/images/welcome_screen/svg/tanamibg.svg | 64 +++++++++++++++++ lib/Api_Helper/base_manager.dart | 18 +++++ lib/core/styles/app_images.dart | 2 +- lib/domain/model/GetCountry_model.dart | 72 +++++++++++++++++++ .../bloc/GetCountry/GetCountryAPI.dart | 14 ++++ .../bloc/GetCountry/getcountry_bloc.dart | 26 +++++++ .../bloc/GetCountry/getcountryevent_bloc.dart | 14 ++++ .../widgets/country_selection_list.dart | 31 +++++++- .../presentation/pages/splash_layout.dart | 4 +- .../widgets/login_signup_button.dart | 8 ++- lib/main.dart | 6 ++ lib/shared/api/api_endpoints.dart | 5 +- lib/shared/api/commonAPI.dart | 0 lib/shared/api/network_api_services.dart | 16 ++--- 15 files changed, 267 insertions(+), 16 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 assets/images/welcome_screen/svg/tanamibg.svg create mode 100644 lib/Api_Helper/base_manager.dart create mode 100644 lib/domain/model/GetCountry_model.dart create mode 100644 lib/features/countrySelection/presentation/bloc/GetCountry/GetCountryAPI.dart create mode 100644 lib/features/countrySelection/presentation/bloc/GetCountry/getcountry_bloc.dart create mode 100644 lib/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart create mode 100644 lib/shared/api/commonAPI.dart diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..de26301 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dart.flutterSdkPath": "D:\\pooja\\fluttersdk\\flutter_3.22.2\\flutter" +} \ No newline at end of file diff --git a/assets/images/welcome_screen/svg/tanamibg.svg b/assets/images/welcome_screen/svg/tanamibg.svg new file mode 100644 index 0000000..f19115f --- /dev/null +++ b/assets/images/welcome_screen/svg/tanamibg.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/Api_Helper/base_manager.dart b/lib/Api_Helper/base_manager.dart new file mode 100644 index 0000000..a8bae41 --- /dev/null +++ b/lib/Api_Helper/base_manager.dart @@ -0,0 +1,18 @@ +class ResponseData { + ResponseData(this.message, this.status, {this.data}); + + final T? data; + final String message; + final ResponseStatus status; + + @override + String toString() => message; +} + +enum ResponseStatus { + SUCCESS, + + FAILED, + + PRIVATE, +} diff --git a/lib/core/styles/app_images.dart b/lib/core/styles/app_images.dart index a885969..7990c31 100644 --- a/lib/core/styles/app_images.dart +++ b/lib/core/styles/app_images.dart @@ -1,7 +1,7 @@ class AppImages { //Splash static const String splashBg = - "assets/images/welcome_screen/svg/Splash_BG.svg"; + "assets/images/welcome_screen/svg/tanamibg.svg"; static const String splashLogo = "assets/images/welcome_screen/svg/Tanami_Capital_Splash_Logo.svg"; diff --git a/lib/domain/model/GetCountry_model.dart b/lib/domain/model/GetCountry_model.dart new file mode 100644 index 0000000..78638a3 --- /dev/null +++ b/lib/domain/model/GetCountry_model.dart @@ -0,0 +1,72 @@ +class GetCountryModel { + List? data; + + GetCountryModel({ this.data}); + + GetCountryModel.fromJson(Map json) { + if (json['data'] != null) { + data = []; + json['data'].forEach((v) { + data!.add(new Data.fromJson(v)); + }); + } + + } + + Map toJson() { + final Map data = new Map(); + if (this.data != null) { + data['data'] = this.data!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class Data { + String? id; + String? countryName; + String? countryCode; + String? isdCode; + String? flagIcon; + Null? currencyXid; + bool? isActive; + Null? createdBy; + Null? modifiedBy; + + Data( + {this.id, + this.countryName, + this.countryCode, + this.isdCode, + this.flagIcon, + this.currencyXid, + this.isActive, + this.createdBy, + this.modifiedBy}); + + Data.fromJson(Map json) { + id = json['id']; + countryName = json['countryName']; + countryCode = json['countryCode']; + isdCode = json['isdCode']; + flagIcon = json['flagIcon']; + currencyXid = json['currency_xid']; + isActive = json['isActive']; + createdBy = json['createdBy']; + modifiedBy = json['modifiedBy']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['countryName'] = this.countryName; + data['countryCode'] = this.countryCode; + data['isdCode'] = this.isdCode; + data['flagIcon'] = this.flagIcon; + data['currency_xid'] = this.currencyXid; + data['isActive'] = this.isActive; + data['createdBy'] = this.createdBy; + data['modifiedBy'] = this.modifiedBy; + return data; + } +} diff --git a/lib/features/countrySelection/presentation/bloc/GetCountry/GetCountryAPI.dart b/lib/features/countrySelection/presentation/bloc/GetCountry/GetCountryAPI.dart new file mode 100644 index 0000000..d020d42 --- /dev/null +++ b/lib/features/countrySelection/presentation/bloc/GetCountry/GetCountryAPI.dart @@ -0,0 +1,14 @@ + +import '../../../../../Api_Helper/base_manager.dart'; +import '../../../../../shared/api/api_endpoints.dart'; +import '../../../../../shared/api/network_api_services.dart'; + +class GetCountryAPI { + GetCountryAPI(); + Future getcountryAPI() async { + String url=ApiEndpoints.getcountryurl; + final response = await NetworkApiService().get( + url, + ); + } +} \ No newline at end of file diff --git a/lib/features/countrySelection/presentation/bloc/GetCountry/getcountry_bloc.dart b/lib/features/countrySelection/presentation/bloc/GetCountry/getcountry_bloc.dart new file mode 100644 index 0000000..0902469 --- /dev/null +++ b/lib/features/countrySelection/presentation/bloc/GetCountry/getcountry_bloc.dart @@ -0,0 +1,26 @@ +import 'package:bloc/bloc.dart'; +import 'package:tanami_app/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart'; + +import '../../../../../Api_Helper/base_manager.dart'; +import 'GetCountryAPI.dart'; + + +dynamic responseFromApi = []; + +class GetCountryBlock extends Bloc { + GetCountryBlock() : super(GetCountryState.initial) { + on(mapEventToState); + } + Future mapEventToState( + GetCountry event, Emitter emit) async { + if (event is GetCountry) { + emit(GetCountryState.loading); + try { + var resp = await GetCountryAPI().getcountryAPI(); + print("//"); + } catch (e) { + emit(GetCountryState.failure); + } + } + } +} \ No newline at end of file diff --git a/lib/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart b/lib/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart new file mode 100644 index 0000000..dea2a67 --- /dev/null +++ b/lib/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart @@ -0,0 +1,14 @@ +abstract class GetCountryEvent { + const GetCountryEvent(); + + List get props => []; +} + +class GetCountry extends GetCountryEvent { + GetCountry(); + + +} + +// Define states +enum GetCountryState { initial, loading, success, failure, error } \ No newline at end of file diff --git a/lib/features/countrySelection/presentation/widgets/country_selection_list.dart b/lib/features/countrySelection/presentation/widgets/country_selection_list.dart index 4c31feb..2785e44 100644 --- a/lib/features/countrySelection/presentation/widgets/country_selection_list.dart +++ b/lib/features/countrySelection/presentation/widgets/country_selection_list.dart @@ -3,6 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:gap/gap.dart'; import 'package:tanami_app/core/styles/app_color.dart'; import 'package:tanami_app/core/utils/constant/country_flag_data.dart'; +import 'package:tanami_app/features/countrySelection/presentation/bloc/GetCountry/getcountry_bloc.dart'; +import 'package:tanami_app/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart'; import 'package:tanami_app/shared/components/text_widget.dart'; import '../bloc/choose_country_bloc.dart'; @@ -15,7 +17,32 @@ class CountrySelectionList extends StatelessWidget { @override Widget build(BuildContext context) { final radioBloc = context.read(); - return BlocBuilder( + return BlocConsumer( + listener: (context, state) { + if (state == GetCountryState.success) { + const SnackBar(content: Text("Successfully fetch")); + } else if (state == GetCountryState.error) { + const SnackBar(content: Text(" error")); + } else { + const SnackBar(content: Text(" not fetch")); + } + }, builder: (context, state) { + print(state); + if (state == GetCountryState.loading) { + return const Center( + child: SizedBox( + height: 40, + width: 40, + child: // ShimmerCommon(), + CircularProgressIndicator( + color: Color(0xFF0093FF), + ), + ), + ); + } + return Text("wait"); + }); + /* BlocBuilder( builder: (context, state) { int selectedIndex = -1; if (state is RadioSelectionChanged) { @@ -52,6 +79,6 @@ class CountrySelectionList extends StatelessWidget { }), ); }, - ); + ); */ } } diff --git a/lib/features/splash/presentation/pages/splash_layout.dart b/lib/features/splash/presentation/pages/splash_layout.dart index 3b7dd46..d34acf7 100644 --- a/lib/features/splash/presentation/pages/splash_layout.dart +++ b/lib/features/splash/presentation/pages/splash_layout.dart @@ -25,7 +25,7 @@ class SplashLayout extends StatelessWidget { fit: BoxFit.cover, ), ), - Positioned.fill( + /* Positioned.fill( child: Align( alignment: Alignment.center, child: SvgPicture.asset( @@ -39,7 +39,7 @@ class SplashLayout extends StatelessWidget { alignment: Alignment.bottomCenter, child: BottomVersionWidget(), ), - ), + ), */ ], ), ), diff --git a/lib/features/welcome/presentation/widgets/login_signup_button.dart b/lib/features/welcome/presentation/widgets/login_signup_button.dart index 5dbcee5..5dae6ae 100644 --- a/lib/features/welcome/presentation/widgets/login_signup_button.dart +++ b/lib/features/welcome/presentation/widgets/login_signup_button.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:gap/gap.dart'; import 'package:tanami_app/core/routes/route_name.dart'; import 'package:tanami_app/core/routes/routes.dart'; import 'package:tanami_app/core/styles/app_color.dart'; +import 'package:tanami_app/features/countrySelection/presentation/bloc/GetCountry/getcountry_bloc.dart'; +import 'package:tanami_app/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart'; import 'package:tanami_app/shared/components/button_widget.dart'; import '../../../../core/styles/app_text.dart'; @@ -26,9 +29,10 @@ class LoginSignUpButton extends StatelessWidget { height: 56.h, child: ButtonWidget().elevatedBtn( function: () { - goRouter.goNamed(RouteName.registerStepScreen, pathParameters: { + context.read().add(GetCountry()); + /* goRouter.goNamed(RouteName.registerStepScreen, pathParameters: { "fromScreentype": "welcome", - }); + }); */ }, text: AppText.signUpText, txtClr: AppColor.plainWhite, diff --git a/lib/main.dart b/lib/main.dart index 12a357c..df9e4d8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,6 +10,7 @@ import 'core/utils/connectivity/network_connectivity.dart'; import 'core/utils/language/localizations_delegate.dart'; import 'features/biometric/presentation/bloc/biometric_bloc.dart'; import 'features/biometric/presentation/bloc/biometric_event.dart'; +import 'features/countrySelection/presentation/bloc/GetCountry/getcountry_bloc.dart'; import 'features/countrySelection/presentation/bloc/choose_country_bloc.dart'; import 'shared/components/bloc/bottom_nav_bar/bottom_navigation_bloc.dart'; import 'shared/components/bloc/language/lng_bloc.dart'; @@ -54,6 +55,8 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State with WidgetsBindingObserver { + + final NetworkConnectivity _networkConnectivity = NetworkConnectivity(onStatusChange: (_) {}); @override @@ -89,6 +92,9 @@ class _MyAppState extends State with WidgetsBindingObserver { BlocProvider( create: (_) => LocalizationBloc(), ), + BlocProvider( + create: (_) => GetCountryBlock(), + ), ], child: ScreenUtilInit( builder: (BuildContext context, Widget? child) => diff --git a/lib/shared/api/api_endpoints.dart b/lib/shared/api/api_endpoints.dart index 99d024a..800a206 100644 --- a/lib/shared/api/api_endpoints.dart +++ b/lib/shared/api/api_endpoints.dart @@ -1,3 +1,6 @@ class ApiEndpoints { - static const base = ""; //App Base url + static const baseurl = + "https://tanami.betadelivery.com/api/development/v1/"; //App Base url + + static const getcountryurl = baseurl + "country/getAllCountry"; } diff --git a/lib/shared/api/commonAPI.dart b/lib/shared/api/commonAPI.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/shared/api/network_api_services.dart b/lib/shared/api/network_api_services.dart index c8336b6..09f30ed 100644 --- a/lib/shared/api/network_api_services.dart +++ b/lib/shared/api/network_api_services.dart @@ -6,37 +6,37 @@ class NetworkApiService { final Dio _dio = Dio(); // Common function for GET requests - Future get(String endpoint, + Future get(String url, {Map? queryParameters}) async { try { - return await _dio.get(endpoint, queryParameters: queryParameters); + return await _dio.get(url); } catch (e) { throw _handleError(e); } } // Common function for POST requests - Future post(String endpoint, dynamic data) async { + Future post(String url, dynamic data) async { try { - return await _dio.post(endpoint, data: data); + return await _dio.post(url, data: data); } catch (e) { throw _handleError(e); } } // Common function for PUT requests - Future put(String endpoint, dynamic data) async { + Future put(String url, dynamic data) async { try { - return await _dio.put(endpoint, data: data); + return await _dio.put(url, data: data); } catch (e) { throw _handleError(e); } } // Common function for DELETE requests - Future delete(String endpoint) async { + Future delete(String url) async { try { - return await _dio.delete(endpoint); + return await _dio.delete(url); } catch (e) { throw _handleError(e); }