mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
Merged with DEV
This commit is contained in:
@ -24,8 +24,10 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
String regionSelected = '';
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
final TextEditingController nameController = TextEditingController(text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}');
|
||||
List<TimeZone>? timeZoneList;
|
||||
List<RegionModel>? regionList;
|
||||
|
||||
|
||||
List<RegionModel> allRegions = [];
|
||||
List<TimeZone> allTimeZone = [];
|
||||
|
||||
|
||||
ProfileBloc() : super(InitialState()) {
|
||||
@ -90,9 +92,9 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
Future _fetchTimeZone(TimeZoneInitialEvent event, Emitter<ProfileState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
timeZoneList = await ProfileApi.fetchTimeZone();
|
||||
emit(UpdateState(timeZoneList: timeZoneList!));
|
||||
return timeZoneList;
|
||||
allTimeZone = await ProfileApi.fetchTimeZone();
|
||||
emit(TimeZoneLoadedState(timezone: allTimeZone));
|
||||
return allTimeZone;
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
@ -123,33 +125,36 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future searchRegion(SearchRegionEvent event, Emitter<ProfileState> emit) async {
|
||||
|
||||
Future<void> searchRegion(SearchRegionEvent event, Emitter<ProfileState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
final query = event.query.toLowerCase();
|
||||
if(event.query.isNotEmpty){
|
||||
final filteredRegions = regionList?.where((region) {
|
||||
if (allRegions.isEmpty) {
|
||||
allRegions = await ProfileApi.fetchRegion();
|
||||
}
|
||||
if (query.isNotEmpty) {
|
||||
final filteredRegions = allRegions.where((region) {
|
||||
return region.name.toLowerCase().contains(query);
|
||||
}).toList() ?? [];
|
||||
regionList = filteredRegions;
|
||||
}).toList();
|
||||
emit(RegionsLoadedState(regions: filteredRegions));
|
||||
}else{
|
||||
regionList = await ProfileApi.fetchRegion();
|
||||
emit(RegionsLoadedState(regions: regionList!));
|
||||
} else {
|
||||
emit(RegionsLoadedState(regions: allRegions));
|
||||
}
|
||||
}
|
||||
|
||||
Future searchTimeZone(SearchTimeZoneEvent event, Emitter<ProfileState> emit) async {
|
||||
Future<void> searchTimeZone(SearchTimeZoneEvent event, Emitter<ProfileState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
final query = event.query.toLowerCase();
|
||||
if(event.query.isNotEmpty){
|
||||
final filtered = timeZoneList?.where((region) {
|
||||
if (allTimeZone.isEmpty) {
|
||||
allTimeZone = await ProfileApi.fetchTimeZone();
|
||||
}
|
||||
if (query.isNotEmpty) {
|
||||
final filteredRegions = allTimeZone.where((region) {
|
||||
return region.name.toLowerCase().contains(query);
|
||||
}).toList() ?? [];
|
||||
timeZoneList = filtered;
|
||||
emit(TimeZoneLoadedState(regions: filtered));
|
||||
}else{
|
||||
timeZoneList = await ProfileApi.fetchTimeZone();
|
||||
emit(UpdateState(timeZoneList: timeZoneList!));
|
||||
}).toList();
|
||||
emit(TimeZoneLoadedState(timezone: filteredRegions));
|
||||
} else {
|
||||
emit(TimeZoneLoadedState(timezone: allTimeZone));
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,9 +162,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
void _fetchRegion(RegionInitialEvent event, Emitter<ProfileState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
|
||||
regionList = await ProfileApi.fetchRegion();
|
||||
emit(RegionsLoadedState(regions: regionList!));
|
||||
allRegions = await ProfileApi.fetchRegion();
|
||||
emit(RegionsLoadedState(regions: allRegions));
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class RegionsLoadedState extends ProfileState {
|
||||
}
|
||||
|
||||
class TimeZoneLoadedState extends ProfileState {
|
||||
final List<TimeZone> regions;
|
||||
final List<TimeZone> timezone;
|
||||
|
||||
const TimeZoneLoadedState({required this.regions});
|
||||
const TimeZoneLoadedState({required this.timezone});
|
||||
}
|
@ -9,7 +9,6 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class RegionPage extends StatelessWidget {
|
||||
const RegionPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
@ -29,7 +28,7 @@ class RegionPage extends StatelessWidget {
|
||||
},
|
||||
builder: (context, state) {
|
||||
final profileBloc = BlocProvider.of<ProfileBloc>(context);
|
||||
final regionList = profileBloc.regionList ?? []; // Safeguard against null
|
||||
final regionList = state is RegionsLoadedState ? state.regions : [];
|
||||
return DefaultScaffold(
|
||||
padding: const EdgeInsets.all(0),
|
||||
title: 'Region',
|
||||
|
@ -15,60 +15,60 @@ class TimeZoneScreenPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (BuildContext context) => ProfileBloc()..add(TimeZoneInitialEvent()),
|
||||
child:
|
||||
BlocConsumer<ProfileBloc, ProfileState>(listener: (context, state) {
|
||||
if (state is FailedState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errorMessage),
|
||||
backgroundColor: Colors.red,
|
||||
create: (BuildContext context) => ProfileBloc()..add(TimeZoneInitialEvent()),
|
||||
child: BlocConsumer<ProfileBloc, ProfileState>(listener: (context, state) {
|
||||
if (state is FailedState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errorMessage),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}if (state is SaveState) {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
if (state is SaveState) {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
},
|
||||
builder: (context, state) {
|
||||
final profileBloc = BlocProvider.of<ProfileBloc>(context);
|
||||
final timeZoneList = profileBloc.timeZoneList ?? []; // Safeguard against null
|
||||
return DefaultScaffold(
|
||||
padding: const EdgeInsets.all(0),
|
||||
title: 'Time Zone',
|
||||
child: state is LoadingInitialState
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller:profileBloc.searchController ,
|
||||
onChanged: (value) {
|
||||
profileBloc.add(SearchTimeZoneEvent(query: value));
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.search),
|
||||
hintText: 'Search',
|
||||
fillColor: ColorsManager.textGray,
|
||||
final timeZoneList = state is TimeZoneLoadedState ?state.timezone : [];
|
||||
return DefaultScaffold(
|
||||
padding: const EdgeInsets.all(0),
|
||||
title: 'Time Zone',
|
||||
child: state is LoadingInitialState
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller:profileBloc.searchController ,
|
||||
onChanged: (value) {
|
||||
profileBloc.add(SearchTimeZoneEvent(query: value));
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.search),
|
||||
hintText: 'Search',
|
||||
fillColor: ColorsManager.textGray,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: ColorsManager.onPrimaryColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: ColorsManager.onPrimaryColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10.0,top: 10.0,left: 15,right: 15),
|
||||
child: ListView.builder(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10.0,top: 10.0,left: 15,right: 15),
|
||||
child: ListView.builder(
|
||||
itemCount: timeZoneList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
profileBloc.add(SelectTimeZoneEvent(val: timeZoneList[index].id, context: context));
|
||||
},
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@ -84,7 +84,7 @@ class TimeZoneScreenPage extends StatelessWidget {
|
||||
fontSize: 13,
|
||||
fontColor: ColorsManager.textGray,),
|
||||
leading: BodyMedium(
|
||||
fontSize: 15,
|
||||
fontSize: 13,
|
||||
text: timeZoneList[index].name,),),
|
||||
),
|
||||
),
|
||||
@ -99,7 +99,7 @@ class TimeZoneScreenPage extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
})
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user