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

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: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<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) {
int selectedIndex = -1;
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,
),
),
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(),
),
),
), */
],
),
),

View File

@@ -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<GetCountryBlock>().add(GetCountry());
/* goRouter.goNamed(RouteName.registerStepScreen, pathParameters: {
"fromScreentype": "welcome",
});
}); */
},
text: AppText.signUpText,
txtClr: AppColor.plainWhite,