Merge pull request #92 from WDI-Ideas/pooja

Pooja
This commit is contained in:
poojapandeyx
2024-07-11 10:52:18 +05:30
committed by GitHub
15 changed files with 385 additions and 40 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 {
//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";

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,15 @@
import '../../../../../Api_Helper/base_manager.dart';
import '../../../../../shared/api/api_endpoints.dart';
import '../../../../../shared/api/network_api_services.dart';
class GetCountryAPI {
GetCountryAPI();
Future<ResponseData> getcountryAPI() async {
String url=ApiEndpoints.getcountryurl;
final response = await NetworkApiService().get(
url,
);
return response;
}
}

View File

@@ -0,0 +1,30 @@
import 'package:bloc/bloc.dart';
import 'package:tanami_app/features/countrySelection/presentation/bloc/GetCountry/getcountryevent_bloc.dart';
import '../../../../../Api_Helper/base_manager.dart';
import '../../../../../domain/model/GetCountry_model.dart';
import 'GetCountryAPI.dart';
class GetCountryBlock extends Bloc<GetCountryEvent, GetCountryState> {
GetCountryBlock() : super(CountryInitial()) {
on<GetCountry>(mapEventToState);
}
Future<void> mapEventToState(
GetCountry event, Emitter<GetCountryState> emit) async {
if (event is GetCountry) {
emit(CountryLoading());
try {
ResponseData response = await GetCountryAPI().getcountryAPI();
if (response.status == ResponseStatus.SUCCESS) {
GetCountryModel countryModel =
GetCountryModel.fromJson(response.data);
emit(CountryLoaded(countryModel));
}
print("//");
} catch (e) {
emit(CountryError("Oops Something went wrong"));
}
}
}
}

View File

@@ -0,0 +1,31 @@
import '../../../../../domain/model/GetCountry_model.dart';
abstract class GetCountryEvent {
const GetCountryEvent();
get props => [];
}
class GetCountry extends GetCountryEvent {
GetCountry();
}
abstract class GetCountryState{}
// Define states
//enum GetCountryState { initial, loading, success, failure, error }
class CountryInitial extends GetCountryState {}
class CountryLoading extends GetCountryState {}
class CountryLoaded extends GetCountryState {
final GetCountryModel countryModel;
CountryLoaded(this.countryModel);
}
class CountryError extends GetCountryState {
final String message;
CountryError(this.message);
}

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,6 +17,56 @@ class CountrySelectionList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final radioBloc = context.read<RadioBloc>();
/* 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 is CountryLoading) {
return Center(child: CircularProgressIndicator());
} else if (state is CountryLoaded) {
return ListView.builder(
itemCount: state.countryModel.data?.length ?? 0,
itemBuilder: (context, index) {
var country = state.countryModel.data![index];
return ListTile(
title: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Adjust according to how you handle flags
Image.asset(
countryFlag[index],
width: 24,
height: 24,
),
const SizedBox(width: 10),
Text(country.countryName ?? ''),
],
),
leading: Radio<int>(
activeColor: Colors.blue,
value: index,
groupValue: -1, // You can update this to manage selected index
onChanged: (int? value) {
// Handle radio button change
},
),
);
},
);
} else if (state is CountryError) {
return Center(child: Text(state.message));
} else {
return Center(child: Text('Press button to fetch country data'));
}
}); */
return BlocBuilder<RadioBloc, RadioState>(
builder: (context, state) {
int selectedIndex = -1;
@@ -22,35 +74,60 @@ class CountrySelectionList extends StatelessWidget {
selectedIndex = state.selectedIndex;
}
return Column(
children: List<Widget>.generate(countryFlag.length, (int index) {
return ListTile(
title: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
countryFlag[index],
width: 24,
height: 24,
return BlocConsumer<GetCountryBlock, GetCountryState>(
listener: (context, state) {
if (state == CountryLoaded) {
const SnackBar(content: Text("Successfully fetch"));
} else if (state == CountryError) {
const SnackBar(content: Text("error while fetching data"));
Future.delayed(Duration(milliseconds: 3), () {
context.read<GetCountryBlock>().add(GetCountry());
});
} else {
const SnackBar(content: Text(" not fetch"));
}
}, builder: (context, state) {
print(state);
if (state is CountryLoading) {
return Center(child: CircularProgressIndicator());
} else if (state is CountryLoaded) {
return ListView.builder(
itemCount: state.countryModel.data?.length ?? 0,
itemBuilder: (context, index) {
var country = state.countryModel.data![index];
return ListTile(
title: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
countryFlag[index],
width: 24,
height: 24,
),
const Gap(10),
TextWidget().text14W500(country.countryName.toString(),
clr: AppColor.charcoalColor),
],
),
const Gap(10),
TextWidget().text14W500(countryName[index],
clr: AppColor.charcoalColor),
],
),
leading: Radio<int>(
activeColor: AppColor.radioActiveColor,
value: index,
groupValue: selectedIndex,
onChanged: (int? value) {
if (value != null) {
radioBloc.add(RadioSelected(value));
}
},
),
leading: Radio<int>(
activeColor: AppColor.radioActiveColor,
value: index,
groupValue: selectedIndex,
onChanged: (int? value) {
if (value != null) {
radioBloc.add(RadioSelected(value));
}
},
),
);
},
);
}),
);
} else if (state is CountryError) {
return Center(child: Text(state.message));
} else {
return Center(child: Text('Press button to fetch country data'));
}
});
},
);
}

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';
@@ -28,6 +31,7 @@ class LoginSignUpButton extends StatelessWidget {
height: 56.h,
child: ButtonWidget().elevatedBtn(
function: () {
context.read<GetCountryBlock>().add(GetCountry());
goRouter.goNamed(RouteName.registerStepScreen, pathParameters: {
"fromScreentype": "welcome",
});

View File

@@ -11,6 +11,7 @@ import 'core/utils/language/localizations_delegate.dart';
import 'core/utils/secure/secure_storage_service.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';
@@ -98,6 +99,12 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
create: (_) =>
BiometricBloc(LocalAuthentication())..add(CheckBiometricEvent()),
),
BlocProvider(
create: (_) => LocalizationBloc(),
),
BlocProvider(
create: (_) => GetCountryBlock(),
),
],
child: ScreenUtilInit(
builder: (BuildContext context, Widget? child) =>

View File

@@ -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";
}

View File

View File

@@ -1,42 +1,63 @@
// common_api.dart
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import '../../Api_Helper/base_manager.dart';
class NetworkApiService {
final Dio _dio = Dio();
// Common function for GET requests
Future<Response> get(String endpoint,
Future<ResponseData> get(String url,
{Map<String, dynamic>? queryParameters}) async {
if (kDebugMode) {
print("api url is >>> $url");
}
Response response;
try {
return await _dio.get(endpoint, queryParameters: queryParameters);
response = await _dio.get(url);
if (response.statusCode == 201 || response.statusCode == 200) {
return ResponseData<dynamic>("success", ResponseStatus.SUCCESS,
data: response.data);
} else {
try {
return ResponseData<dynamic>(
response.data['message'].toString(), ResponseStatus.FAILED);
} catch (_) {
return ResponseData<dynamic>(
data: response.data,
response.statusMessage!,
ResponseStatus.FAILED);
}}
} catch (e) {
throw _handleError(e);
return ResponseData<dynamic>(
"Something went wrong", ResponseStatus.FAILED);
}
}
// Common function for POST requests
Future<Response> post(String endpoint, dynamic data) async {
Future<Response> 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<Response> put(String endpoint, dynamic data) async {
Future<Response> 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<Response> delete(String endpoint) async {
Future<Response> delete(String url) async {
try {
return await _dio.delete(endpoint);
return await _dio.delete(url);
} catch (e) {
throw _handleError(e);
}