get country api

This commit is contained in:
poojapandeyx
2024-07-10 17:34:49 +05:30
parent 0ab7bb6df0
commit 05e48ebbbe
15 changed files with 267 additions and 16 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"dart.flutterSdkPath": "D:\\pooja\\fluttersdk\\flutter_3.22.2\\flutter"
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -0,0 +1,18 @@
class ResponseData<T> {
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,
}

View File

@@ -1,7 +1,7 @@
class AppImages { class AppImages {
//Splash //Splash
static const String splashBg = static const String splashBg =
"assets/images/welcome_screen/svg/Splash_BG.svg"; "assets/images/welcome_screen/svg/tanamibg.svg";
static const String splashLogo = static const String splashLogo =
"assets/images/welcome_screen/svg/Tanami_Capital_Splash_Logo.svg"; "assets/images/welcome_screen/svg/Tanami_Capital_Splash_Logo.svg";

View File

@@ -0,0 +1,72 @@
class GetCountryModel {
List<Data>? data;
GetCountryModel({ this.data});
GetCountryModel.fromJson(Map<String, dynamic> json) {
if (json['data'] != null) {
data = <Data>[];
json['data'].forEach((v) {
data!.add(new Data.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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;
}
}

View File

@@ -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<void> getcountryAPI() async {
String url=ApiEndpoints.getcountryurl;
final response = await NetworkApiService().get(
url,
);
}
}

View File

@@ -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<GetCountryEvent, GetCountryState> {
GetCountryBlock() : super(GetCountryState.initial) {
on<GetCountry>(mapEventToState);
}
Future<void> mapEventToState(
GetCountry event, Emitter<GetCountryState> emit) async {
if (event is GetCountry) {
emit(GetCountryState.loading);
try {
var resp = await GetCountryAPI().getcountryAPI();
print("//");
} catch (e) {
emit(GetCountryState.failure);
}
}
}
}

View File

@@ -0,0 +1,14 @@
abstract class GetCountryEvent {
const GetCountryEvent();
List<Object> get props => [];
}
class GetCountry extends GetCountryEvent {
GetCountry();
}
// Define states
enum GetCountryState { initial, loading, success, failure, error }

View File

@@ -3,6 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
import 'package:tanami_app/core/styles/app_color.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/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 'package:tanami_app/shared/components/text_widget.dart';
import '../bloc/choose_country_bloc.dart'; import '../bloc/choose_country_bloc.dart';
@@ -15,7 +17,32 @@ class CountrySelectionList extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final radioBloc = context.read<RadioBloc>(); final radioBloc = context.read<RadioBloc>();
return BlocBuilder<RadioBloc, RadioState>( return BlocConsumer<GetCountryBlock, GetCountryState>(
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<RadioBloc, RadioState>(
builder: (context, state) { builder: (context, state) {
int selectedIndex = -1; int selectedIndex = -1;
if (state is RadioSelectionChanged) { if (state is RadioSelectionChanged) {
@@ -52,6 +79,6 @@ class CountrySelectionList extends StatelessWidget {
}), }),
); );
}, },
); ); */
} }
} }

View File

@@ -25,7 +25,7 @@ class SplashLayout extends StatelessWidget {
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),
Positioned.fill( /* Positioned.fill(
child: Align( child: Align(
alignment: Alignment.center, alignment: Alignment.center,
child: SvgPicture.asset( child: SvgPicture.asset(
@@ -39,7 +39,7 @@ class SplashLayout extends StatelessWidget {
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
child: BottomVersionWidget(), child: BottomVersionWidget(),
), ),
), ), */
], ],
), ),
), ),

View File

@@ -1,9 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
import 'package:tanami_app/core/routes/route_name.dart'; import 'package:tanami_app/core/routes/route_name.dart';
import 'package:tanami_app/core/routes/routes.dart'; import 'package:tanami_app/core/routes/routes.dart';
import 'package:tanami_app/core/styles/app_color.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 'package:tanami_app/shared/components/button_widget.dart';
import '../../../../core/styles/app_text.dart'; import '../../../../core/styles/app_text.dart';
@@ -26,9 +29,10 @@ class LoginSignUpButton extends StatelessWidget {
height: 56.h, height: 56.h,
child: ButtonWidget().elevatedBtn( child: ButtonWidget().elevatedBtn(
function: () { function: () {
goRouter.goNamed(RouteName.registerStepScreen, pathParameters: { context.read<GetCountryBlock>().add(GetCountry());
/* goRouter.goNamed(RouteName.registerStepScreen, pathParameters: {
"fromScreentype": "welcome", "fromScreentype": "welcome",
}); }); */
}, },
text: AppText.signUpText, text: AppText.signUpText,
txtClr: AppColor.plainWhite, txtClr: AppColor.plainWhite,

View File

@@ -10,6 +10,7 @@ import 'core/utils/connectivity/network_connectivity.dart';
import 'core/utils/language/localizations_delegate.dart'; import 'core/utils/language/localizations_delegate.dart';
import 'features/biometric/presentation/bloc/biometric_bloc.dart'; import 'features/biometric/presentation/bloc/biometric_bloc.dart';
import 'features/biometric/presentation/bloc/biometric_event.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 'features/countrySelection/presentation/bloc/choose_country_bloc.dart';
import 'shared/components/bloc/bottom_nav_bar/bottom_navigation_bloc.dart'; import 'shared/components/bloc/bottom_nav_bar/bottom_navigation_bloc.dart';
import 'shared/components/bloc/language/lng_bloc.dart'; import 'shared/components/bloc/language/lng_bloc.dart';
@@ -54,6 +55,8 @@ class MyApp extends StatefulWidget {
} }
class _MyAppState extends State<MyApp> with WidgetsBindingObserver { class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
final NetworkConnectivity _networkConnectivity = final NetworkConnectivity _networkConnectivity =
NetworkConnectivity(onStatusChange: (_) {}); NetworkConnectivity(onStatusChange: (_) {});
@override @override
@@ -89,6 +92,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
BlocProvider( BlocProvider(
create: (_) => LocalizationBloc(), create: (_) => LocalizationBloc(),
), ),
BlocProvider(
create: (_) => GetCountryBlock(),
),
], ],
child: ScreenUtilInit( child: ScreenUtilInit(
builder: (BuildContext context, Widget? child) => builder: (BuildContext context, Widget? child) =>

View File

@@ -1,3 +1,6 @@
class ApiEndpoints { 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";
} }

View File

View File

@@ -6,37 +6,37 @@ class NetworkApiService {
final Dio _dio = Dio(); final Dio _dio = Dio();
// Common function for GET requests // Common function for GET requests
Future<Response> get(String endpoint, Future<Response> get(String url,
{Map<String, dynamic>? queryParameters}) async { {Map<String, dynamic>? queryParameters}) async {
try { try {
return await _dio.get(endpoint, queryParameters: queryParameters); return await _dio.get(url);
} catch (e) { } catch (e) {
throw _handleError(e); throw _handleError(e);
} }
} }
// Common function for POST requests // Common function for POST requests
Future<Response> post(String endpoint, dynamic data) async { Future<Response> post(String url, dynamic data) async {
try { try {
return await _dio.post(endpoint, data: data); return await _dio.post(url, data: data);
} catch (e) { } catch (e) {
throw _handleError(e); throw _handleError(e);
} }
} }
// Common function for PUT requests // Common function for PUT requests
Future<Response> put(String endpoint, dynamic data) async { Future<Response> put(String url, dynamic data) async {
try { try {
return await _dio.put(endpoint, data: data); return await _dio.put(url, data: data);
} catch (e) { } catch (e) {
throw _handleError(e); throw _handleError(e);
} }
} }
// Common function for DELETE requests // Common function for DELETE requests
Future<Response> delete(String endpoint) async { Future<Response> delete(String url) async {
try { try {
return await _dio.delete(endpoint); return await _dio.delete(url);
} catch (e) { } catch (e) {
throw _handleError(e); throw _handleError(e);
} }