mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-23 10:57:54 +00:00
profile changes
This commit is contained in:
@@ -7,6 +7,8 @@ class MenuCubit extends Cubit<MenuState> {
|
||||
|
||||
static MenuCubit of(context) => BlocProvider.of<MenuCubit>(context);
|
||||
|
||||
String name = '';
|
||||
|
||||
// List<MenuListModel> menuLists = [
|
||||
// MenuListModel(
|
||||
// label: 'Home Management',
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_event.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_state.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/region_model.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/time_zone_model.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
final String userId;
|
||||
bool isSaving = false;
|
||||
bool editName = false;
|
||||
final FocusNode focusNode = FocusNode();
|
||||
File? image;
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
String timeZoneSelected = '';
|
||||
String regionSelected = '';
|
||||
final TextEditingController searchController = TextEditingController();
|
||||
final TextEditingController nameController = TextEditingController(text: 'asd alsdkasdd ');
|
||||
List<TimeZone>? timeZoneList;
|
||||
List<RegionModel>? regionList;
|
||||
|
||||
ProfileBloc({required this.userId}) : super(InitialState()) {
|
||||
on<InitialEvent>(_fetchUserInfo);
|
||||
on<TimeZoneInitialEvent>(_fetchTimeZone);
|
||||
on<RegionInitialEvent>(_fetchRegion);
|
||||
on<SaveNameEvent>(saveName);
|
||||
on<SelectImageEvent>(_selectImage);
|
||||
on<ChangeNameEvent>(_changeName);
|
||||
on<SelectTimeZoneEvent>(selectTimeZone);
|
||||
on<SearchRegionEvent>(searchRegion);
|
||||
}
|
||||
|
||||
|
||||
List<Map<String, String>> timeZone=
|
||||
[
|
||||
{"name": "GMT-12:00", "offset": "-12:00","id":'1'},
|
||||
|
||||
{"name": "GMT-11:00", "offset": "-11:00","id":'2'},
|
||||
|
||||
{"name": "GMT-10:00", "offset": "-10:00","id":'3'},
|
||||
|
||||
{"name": "GMT-09:00", "offset": "-09:00","id":'4'},
|
||||
|
||||
{"name": "GMT-08:00", "offset": "-08:00","id":'5'},
|
||||
|
||||
{"name": "GMT-07:00", "offset": "-07:00","id":'6'},
|
||||
|
||||
{"name": "GMT-06:00", "offset": "-06:00","id":'7'},
|
||||
|
||||
{"name": "GMT-05:00", "offset": "-05:00","id":'8'},
|
||||
|
||||
{"name": "GMT-04:00", "offset": "-04:00","id":'9'},
|
||||
|
||||
];
|
||||
|
||||
|
||||
List<Map<String, String>> region=
|
||||
[
|
||||
{"name": "region 1", "id":'1'},
|
||||
{"name": "region 2", "id":'2'},
|
||||
{"name": "region 3","id":'3'},
|
||||
{"name": "region 4", "id":'4'},
|
||||
{"name": "region 5","id":'5'},
|
||||
{"name": "region 6","id":'6'},
|
||||
{"name": "region 7","id":'7'},
|
||||
{"name": "region 8", "id":'8'},
|
||||
];
|
||||
|
||||
|
||||
|
||||
void _changeName(ChangeNameEvent event, Emitter<ProfileState> emit) {
|
||||
emit(LoadingInitialState());
|
||||
editName = event.value!;
|
||||
if (editName) {
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
}else {
|
||||
focusNode.unfocus();
|
||||
}
|
||||
emit(NameEditingState(editName: editName));
|
||||
}
|
||||
|
||||
void _fetchUserInfo(InitialEvent event, Emitter<ProfileState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
// var response = await ProfileApi.fetchUserInfo(userId);
|
||||
// List<StatusModel> statusModelList = [];
|
||||
// for (var status in response['status']) {
|
||||
// statusModelList.add(StatusModel.fromJson(status));
|
||||
// }
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future _fetchTimeZone(
|
||||
TimeZoneInitialEvent event, Emitter<ProfileState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
timeZoneList = timeZone.map((zone) => TimeZone.fromJson(zone)).toList();
|
||||
// List<StatusModel> statusModelList = [];
|
||||
// for (var status in response['status']) {
|
||||
// statusModelList.add(StatusModel.fromJson(status));
|
||||
// }
|
||||
emit(UpdateState(timeZoneList: timeZoneList!)); // Make sure UpdateState accepts the list
|
||||
return timeZoneList;
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future selectTimeZone(SelectTimeZoneEvent event, Emitter<ProfileState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
timeZoneSelected= event.val;
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
Navigator.pop(event.context);
|
||||
return timeZoneList;
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future selectRegion(SelectRegionEvent event, Emitter<ProfileState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
regionSelected= event.val;
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
Navigator.pop(event.context);
|
||||
return timeZoneList;
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future searchRegion(SearchRegionEvent event, Emitter<ProfileState> emit) async {
|
||||
final query = event.query.toLowerCase();
|
||||
if(event.query.isEmpty){
|
||||
regionList = region.map((zone) => RegionModel.fromJson(zone)).toList();
|
||||
}else{
|
||||
final filteredRegions = regionList?.where((region) {
|
||||
return region.name.toLowerCase().contains(query);
|
||||
}).toList() ?? [];
|
||||
regionList = filteredRegions;// Assume this fetches the regions
|
||||
emit(RegionsLoadedState(regions: filteredRegions));
|
||||
}
|
||||
}
|
||||
|
||||
void _fetchRegion(RegionInitialEvent event, Emitter<ProfileState> emit) async {
|
||||
try {
|
||||
emit(LoadingInitialState());
|
||||
regionList = region.map((zone) => RegionModel.fromJson(zone)).toList();
|
||||
emit(UpdateState(timeZoneList: timeZoneList!));
|
||||
} catch (e) {
|
||||
emit(FailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectImage(SelectImageEvent event, Emitter<ProfileState> emit) async {
|
||||
if (await _requestPermission()) {
|
||||
emit(ChangeImageState());
|
||||
final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
|
||||
if (pickedFile != null) {
|
||||
image = File(pickedFile.path);
|
||||
final bytes = image!.readAsBytesSync().lengthInBytes;
|
||||
final kb = bytes / 1024;
|
||||
final mb = kb / 1024;
|
||||
if(mb>1){
|
||||
image=null;
|
||||
CustomSnackBar.displaySnackBar('Image size must be 1 MB or less');
|
||||
}else{
|
||||
await saveImage();
|
||||
}
|
||||
} else {
|
||||
print('No image selected.');
|
||||
}
|
||||
emit(ImageSelectedState());
|
||||
} else {
|
||||
_showPermissionDeniedDialog(event.context);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveImage() async {
|
||||
emit(ChangeImageState());
|
||||
List<int> imageBytes = image!.readAsBytesSync();
|
||||
String base64Image = base64Encode(imageBytes);
|
||||
print(base64Image);
|
||||
emit(ImageSelectedState());
|
||||
}
|
||||
|
||||
Future<bool> _requestPermission() async {
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
if (Platform.isAndroid ) {
|
||||
PermissionStatus status = await Permission.photos.status;
|
||||
if(androidInfo.version.sdkInt<= 33){
|
||||
if (status.isDenied) {
|
||||
PermissionStatus status = await Permission.storage.request();
|
||||
if (status.isGranted) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if (status.isGranted) {
|
||||
return true;
|
||||
} else if (status.isDenied) {
|
||||
PermissionStatus status = await Permission.photos.request();
|
||||
if (status.isGranted) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
SharedPreferences sharedPreferences =
|
||||
await SharedPreferences.getInstance();
|
||||
bool firstClick = sharedPreferences.getBool('firstPermission') ?? true;
|
||||
await sharedPreferences.setBool('firstPermission', false);
|
||||
if (firstClick == false) {
|
||||
var status = await Permission.photos.status;
|
||||
return status.isGranted;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showPermissionDeniedDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Permission Denied'),
|
||||
content: const Text(
|
||||
'Photo access is required to select an image. Please allow photo access in the app settings.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
openAppSettings();
|
||||
},
|
||||
child: const Text('Settings'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> saveName(SaveNameEvent event, Emitter<ProfileState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
try {
|
||||
isSaving = true;
|
||||
emit(LoadingSaveState());
|
||||
Navigator.of(event.context).pop(true);
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (_) {
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool _validateInputs() {
|
||||
if (nameController.text.length < 7) {
|
||||
CustomSnackBar.displaySnackBar('Password less than 7');
|
||||
return true;
|
||||
}
|
||||
if (nameController.text.isEmpty) {
|
||||
CustomSnackBar.displaySnackBar('Password required');
|
||||
return true;
|
||||
}
|
||||
if (nameController.text.isEmpty) {
|
||||
CustomSnackBar.displaySnackBar('Password name required');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void showRenameDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 200,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 25,
|
||||
),
|
||||
child: Text(
|
||||
'Change Name',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
const Spacer(),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
right: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 0.5,
|
||||
),
|
||||
top: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text(
|
||||
'Cancel',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const VerticalDivider(
|
||||
thickness: 1,
|
||||
width: 1,
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
right: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 0.5,
|
||||
),
|
||||
top: BorderSide(
|
||||
color: Colors.grey,
|
||||
width: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
// Handle save action
|
||||
},
|
||||
child: const Text(
|
||||
'Save',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
abstract class ProfileEvent extends Equatable {
|
||||
const ProfileEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class InitialEvent extends ProfileEvent {}
|
||||
|
||||
class TimeZoneInitialEvent extends ProfileEvent {}
|
||||
|
||||
class ChangeNameEvent extends ProfileEvent {
|
||||
final bool? value;
|
||||
const ChangeNameEvent({ this.value});
|
||||
}
|
||||
|
||||
class RegionInitialEvent extends ProfileEvent {}
|
||||
|
||||
|
||||
class UpdateLockEvent extends ProfileEvent {
|
||||
final bool value;
|
||||
const UpdateLockEvent({required this.value});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class SaveNameEvent extends ProfileEvent {
|
||||
final BuildContext context;
|
||||
const SaveNameEvent({required this.context});
|
||||
@override
|
||||
List<Object> get props => [context];
|
||||
}
|
||||
|
||||
|
||||
class SelectImageEvent extends ProfileEvent {
|
||||
final BuildContext context;
|
||||
final bool isSelected;
|
||||
const SelectImageEvent({required this.context,required this.isSelected});
|
||||
@override
|
||||
List<Object> get props => [context,isSelected];
|
||||
}
|
||||
|
||||
|
||||
class ToggleRepeatEvent extends ProfileEvent {}
|
||||
|
||||
class SelectTimeZoneEvent extends ProfileEvent {
|
||||
final String val;
|
||||
final BuildContext context;
|
||||
const SelectTimeZoneEvent({required this.val,required this.context});
|
||||
@override
|
||||
List<Object> get props => [val];
|
||||
}
|
||||
|
||||
class SelectRegionEvent extends ProfileEvent {
|
||||
final String val;
|
||||
final BuildContext context;
|
||||
const SelectRegionEvent({required this.val,required this.context});
|
||||
@override
|
||||
List<Object> get props => [val,context];
|
||||
}
|
||||
|
||||
|
||||
class SearchRegionEvent extends ProfileEvent {
|
||||
final String query;
|
||||
|
||||
const SearchRegionEvent({required this.query});
|
||||
@override
|
||||
List<Object> get props => [query];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/smart_door_model.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/region_model.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/time_zone_model.dart';
|
||||
|
||||
class ProfileState extends Equatable {
|
||||
const ProfileState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class InitialState extends ProfileState {}
|
||||
|
||||
class LoadingInitialState extends ProfileState {}
|
||||
|
||||
class UpdateState extends ProfileState {
|
||||
final List<TimeZone> timeZoneList;
|
||||
|
||||
UpdateState({required this.timeZoneList});
|
||||
}
|
||||
|
||||
class NameEditingState extends ProfileState {
|
||||
final bool editName;
|
||||
|
||||
NameEditingState({required this.editName});
|
||||
}
|
||||
|
||||
class LoadingNewSate extends ProfileState {
|
||||
final SmartDoorModel smartDoorModel;
|
||||
const LoadingNewSate({required this.smartDoorModel});
|
||||
|
||||
@override
|
||||
List<Object> get props => [smartDoorModel];
|
||||
}
|
||||
|
||||
class FailedState extends ProfileState {
|
||||
final String errorMessage;
|
||||
|
||||
const FailedState({required this.errorMessage});
|
||||
|
||||
@override
|
||||
List<Object> get props => [errorMessage];
|
||||
}
|
||||
|
||||
class GeneratePasswordState extends ProfileState {}
|
||||
|
||||
class ImageSelectedState extends ProfileState {}
|
||||
|
||||
class ImageTooLargeState extends ProfileState {}
|
||||
|
||||
class IsRepeatState extends ProfileState {}
|
||||
|
||||
class IsStartEndState extends ProfileState {}
|
||||
|
||||
class ChangeStartTimeState extends ProfileState {}
|
||||
|
||||
class ChangeEndTimeState extends ProfileState {}
|
||||
|
||||
class ChangeImageState extends ProfileState {}
|
||||
|
||||
class SaveState extends ProfileState {}
|
||||
|
||||
class LoadingSaveState extends ProfileState {}
|
||||
class RegionsLoadedState extends ProfileState {
|
||||
final List<RegionModel> regions;
|
||||
|
||||
const RegionsLoadedState({required this.regions});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
class RegionModel {
|
||||
final String name;
|
||||
final String id;
|
||||
|
||||
RegionModel({
|
||||
required this.name,
|
||||
required this.id,
|
||||
});
|
||||
|
||||
factory RegionModel.fromJson(Map<String, dynamic> json) {
|
||||
return RegionModel(
|
||||
name: json['name'],
|
||||
id: json['id'].toString(), // Ensure id is a String
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': name,
|
||||
'id': id,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
class TimeZone {
|
||||
final String name;
|
||||
final String offset;
|
||||
final String id;
|
||||
|
||||
TimeZone({
|
||||
required this.name,
|
||||
required this.offset,
|
||||
required this.id,
|
||||
});
|
||||
|
||||
factory TimeZone.fromJson(Map<String, dynamic> json) {
|
||||
return TimeZone(
|
||||
name: json['name'],
|
||||
offset: json['offset'],
|
||||
id: json['id'].toString(), // Ensure id is a String
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': name,
|
||||
'offset': offset,
|
||||
'id': id,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,12 @@ class MenuView extends StatelessWidget {
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<AuthCubit, AuthState>(
|
||||
builder: (context, state) {
|
||||
final profileBloc = BlocProvider.of<MenuCubit>(context);
|
||||
return SingleChildScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
const ProfileTab(),
|
||||
ProfileTab(name:profileBloc.name),
|
||||
for (var section in menuSections)
|
||||
MenuList(
|
||||
section: section,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_event.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_state.dart';
|
||||
@@ -11,8 +10,6 @@ import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/navigation/navigation_service.dart';
|
||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
@@ -6,9 +6,8 @@ import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dar
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
|
||||
class ProfileTab extends StatelessWidget {
|
||||
const ProfileTab({
|
||||
super.key,
|
||||
});
|
||||
final String? name;
|
||||
const ProfileTab({super.key,this.name});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -22,18 +21,18 @@ class ProfileTab extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Stack(
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(height: 20),
|
||||
const SizedBox(height: 20),
|
||||
DefaultContainer(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BodyMedium(
|
||||
text: "Karim",
|
||||
text: name!,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
BodySmall(text: "Syncrow Account")
|
||||
|
||||
@@ -1,129 +1,186 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_event.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_state.dart';
|
||||
import 'package:syncrow_app/features/menu/view/widgets/profile/region_page.dart';
|
||||
import 'package:syncrow_app/features/menu/view/widgets/profile/time_zone_screen_page.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/title_medium.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class ProfileView extends StatelessWidget {
|
||||
const ProfileView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultScaffold(
|
||||
title: 'Profile Page',
|
||||
child: Column(
|
||||
children: [
|
||||
//profile pic
|
||||
const SizedBox.square(
|
||||
dimension: 120,
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Colors.white,
|
||||
child: SizedBox.square(
|
||||
dimension: 115,
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Colors.grey,
|
||||
child: FlutterLogo(),
|
||||
),
|
||||
return BlocProvider(
|
||||
create: (BuildContext context) => ProfileBloc(userId: ''),
|
||||
child: BlocConsumer<ProfileBloc, ProfileState>(listener: (context, state) {
|
||||
if (state is FailedState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errorMessage),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
final profileBloc = BlocProvider.of<ProfileBloc>(context);
|
||||
return DefaultScaffold(
|
||||
title: 'Syncrow Account',
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: MediaQuery.of(context).size.height*0.05,),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
profileBloc.add(SelectImageEvent(context: context, isSelected: false));
|
||||
},
|
||||
child: SizedBox.square(
|
||||
dimension: 125,
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Colors.white,
|
||||
child: SizedBox.square(
|
||||
dimension: 120,
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Colors.grey,
|
||||
backgroundImage: profileBloc.image == null
|
||||
? null
|
||||
: FileImage(profileBloc.image!),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
IntrinsicWidth(
|
||||
child: TextFormField(
|
||||
maxLength: 30,
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
focusNode: profileBloc.focusNode,
|
||||
controller: profileBloc.nameController,
|
||||
enabled: profileBloc.editName,
|
||||
onEditingComplete: () {
|
||||
profileBloc.add(const ChangeNameEvent(value: false));
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Your Name",
|
||||
border: InputBorder.none,
|
||||
fillColor: Colors.white10,
|
||||
counterText: '', // Hides the character count
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
profileBloc.add(const ChangeNameEvent(value: true));
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Icon(
|
||||
Icons.edit_outlined,
|
||||
size: 20,
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
//Info
|
||||
DefaultContainer(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 25,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// children: [
|
||||
// const BodyMedium(text: 'Email '),
|
||||
// Flexible(
|
||||
// child: TextField(
|
||||
// textAlign: TextAlign.end,
|
||||
// decoration: InputDecoration(
|
||||
// hintText: ' [email protected]',
|
||||
// hintStyle:
|
||||
// context.bodyMedium.copyWith(color: Colors.grey),
|
||||
// border: InputBorder.none,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// Container(
|
||||
// height: 1,
|
||||
// color: ColorsManager.greyColor,
|
||||
// ),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const RegionPage(),
|
||||
));
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(top: 20, bottom: 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
BodyMedium(text: 'Region '),
|
||||
Flexible(
|
||||
child: BodyMedium(text: 'United Arab Emirates')
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
Container(
|
||||
height: 1,
|
||||
color: ColorsManager.greyColor,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const TimeZoneScreenPage(),
|
||||
));
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(top: 15, bottom: 15),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
BodyMedium(text: 'Time Zone '),
|
||||
Flexible(
|
||||
child: BodyMedium(text: 'GMT +4')
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
//name
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const TitleMedium(text: 'Karim'),
|
||||
const SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
//TODO: Implement edit name
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.edit_outlined,
|
||||
size: 20,
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
//Info
|
||||
DefaultContainer(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 25,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const BodyMedium(text: 'Email '),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
textAlign: TextAlign.end,
|
||||
decoration: InputDecoration(
|
||||
hintText: ' [email protected]',
|
||||
hintStyle:
|
||||
context.bodyMedium.copyWith(color: Colors.grey),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
height: 1,
|
||||
color: ColorsManager.greyColor,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const BodyMedium(text: 'Region '),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
textAlign: TextAlign.end,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'United Arab Emirates',
|
||||
hintStyle:
|
||||
context.bodyMedium.copyWith(color: Colors.grey),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
height: 1,
|
||||
color: ColorsManager.greyColor,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const BodyMedium(text: 'Time Zone '),
|
||||
Flexible(
|
||||
child: TextField(
|
||||
textAlign: TextAlign.end,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'GMT +4',
|
||||
hintStyle:
|
||||
context.bodyMedium.copyWith(color: Colors.grey),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_event.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_state.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
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(
|
||||
create: (BuildContext context) => ProfileBloc(userId: '')..add(RegionInitialEvent()),
|
||||
child: BlocConsumer<ProfileBloc, ProfileState>(listener: (context, state) {
|
||||
if (state is FailedState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errorMessage),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
final profileBloc = BlocProvider.of<ProfileBloc>(context);
|
||||
final regionList = profileBloc.regionList ?? []; // Safeguard against null
|
||||
return DefaultScaffold(
|
||||
padding: const EdgeInsets.all(0),
|
||||
title: 'Region',
|
||||
child: state is LoadingInitialState
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller:profileBloc.searchController ,
|
||||
onChanged: (value) {
|
||||
profileBloc.add(SearchRegionEvent(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),
|
||||
),
|
||||
),
|
||||
child: ListView.builder(
|
||||
itemCount: regionList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
profileBloc.add(SelectRegionEvent(
|
||||
val: regionList[index].id,
|
||||
context: context));
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: SizedBox(
|
||||
height: 45,
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
// trailing: BodyMedium(
|
||||
// text: regionList[index].offset,
|
||||
// fontSize: 13,
|
||||
// fontColor: ColorsManager.textGray,),
|
||||
leading: BodyMedium(
|
||||
fontSize: 15,
|
||||
text: regionList[index].name,),),
|
||||
),
|
||||
),
|
||||
const Divider(color: ColorsManager.textGray), // Divider between items
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_bloc.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_event.dart';
|
||||
import 'package:syncrow_app/features/menu/bloc/profile_bloc/profile_state.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class TimeZoneScreenPage extends StatelessWidget {
|
||||
const TimeZoneScreenPage({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (BuildContext context) => ProfileBloc(userId: '')..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,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
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(
|
||||
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),
|
||||
),
|
||||
),
|
||||
child: ListView.builder(
|
||||
itemCount: timeZoneList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
|
||||
profileBloc.add(SelectTimeZoneEvent(
|
||||
val: timeZoneList[index].id,
|
||||
context: context));
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: SizedBox(
|
||||
height: 45,
|
||||
child: ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
trailing: BodyMedium(
|
||||
text: timeZoneList[index].offset,
|
||||
fontSize: 13,
|
||||
fontColor: ColorsManager.textGray,),
|
||||
leading: BodyMedium(
|
||||
fontSize: 15,
|
||||
text: timeZoneList[index].name,),),
|
||||
),
|
||||
),
|
||||
const Divider(color: ColorsManager.textGray), // Divider between items
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||
import 'package:syncrow_app/services/api/http_service.dart';
|
||||
|
||||
import '../../features/devices/model/create_temporary_password_model.dart';
|
||||
|
||||
class ProfileApi {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
static Future<Map<String, dynamic>> saveName(
|
||||
String newName, String userId) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', userId),
|
||||
body: newName,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> saveImage(
|
||||
File newName, String userId) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', userId),
|
||||
body: newName,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
static Future fetchUserInfo(String userId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.groupBySpace.replaceAll('{unitUuid}', userId),
|
||||
// queryParameters: params,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => DevicesCategoryModel.fromJsonList(json),
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user