mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-17 02:25:16 +00:00
Refactor email and password validation logic in LoginForm widget
Update email and password validation logic in the LoginForm widget to only perform validation when the state is not AuthTokenError. This ensures that validation is skipped when there is an authentication token error.
This commit is contained in:
@ -18,17 +18,18 @@ part 'home_state.dart';
|
|||||||
|
|
||||||
class HomeCubit extends Cubit<HomeState> {
|
class HomeCubit extends Cubit<HomeState> {
|
||||||
// Create a private static instance variable
|
// Create a private static instance variable
|
||||||
static HomeCubit? _instance;
|
|
||||||
HomeCubit._() : super(HomeInitial()) {
|
HomeCubit._() : super(HomeInitial()) {
|
||||||
if (selectedSpace == null) {
|
if (selectedSpace == null) {
|
||||||
fetchSpaces().then((value) {
|
fetchSpaces().then((value) {
|
||||||
if (selectedSpace != null) {
|
if (selectedSpace != null) {
|
||||||
print('selectedSpace: ${selectedSpace!.name}');
|
|
||||||
fetchRooms(selectedSpace!);
|
fetchRooms(selectedSpace!);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HomeCubit? _instance;
|
||||||
static HomeCubit getInstance() {
|
static HomeCubit getInstance() {
|
||||||
// If an instance already exists, return it
|
// If an instance already exists, return it
|
||||||
_instance ??= HomeCubit._();
|
_instance ??= HomeCubit._();
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
@ -7,7 +6,6 @@ import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
|||||||
import 'package:syncrow_app/features/app_layout/view/widgets/app_body.dart';
|
import 'package:syncrow_app/features/app_layout/view/widgets/app_body.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart';
|
import 'package:syncrow_app/features/app_layout/view/widgets/default_app_bar.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart';
|
import 'package:syncrow_app/features/app_layout/view/widgets/default_nav_bar.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
||||||
import 'package:syncrow_app/navigation/routing_constants.dart';
|
import 'package:syncrow_app/navigation/routing_constants.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||||
|
|
||||||
@ -16,15 +14,8 @@ class AppLayout extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return BlocProvider(
|
||||||
providers: [
|
create: (context) => HomeCubit.getInstance(),
|
||||||
BlocProvider(
|
|
||||||
create: (context) => HomeCubit.getInstance(),
|
|
||||||
),
|
|
||||||
BlocProvider(
|
|
||||||
create: (context) => DevicesCubit(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
child: BlocConsumer<HomeCubit, HomeState>(
|
child: BlocConsumer<HomeCubit, HomeState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is GetSpacesError) {
|
if (state is GetSpacesError) {
|
||||||
|
@ -23,7 +23,7 @@ class DefaultNavBar extends StatelessWidget {
|
|||||||
onTap: (int index) {
|
onTap: (int index) {
|
||||||
cubit.updatePageIndex(index);
|
cubit.updatePageIndex(index);
|
||||||
if (DevicesCubit.get(context).chosenCategoryView != null) {
|
if (DevicesCubit.get(context).chosenCategoryView != null) {
|
||||||
DevicesCubit().clearCategoriesSelection(context);
|
DevicesCubit.getInstance().clearCategoriesSelection(context);
|
||||||
}
|
}
|
||||||
if (HomeCubit.getInstance().selectedRoom != null) {
|
if (HomeCubit.getInstance().selectedRoom != null) {
|
||||||
HomeCubit.getInstance().unselectRoom();
|
HomeCubit.getInstance().unselectRoom();
|
||||||
|
@ -30,15 +30,17 @@ class LoginForm extends StatelessWidget {
|
|||||||
TextFormField(
|
TextFormField(
|
||||||
controller: AuthCubit.get(context).emailController,
|
controller: AuthCubit.get(context).emailController,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value != null) {
|
if (state is! AuthTokenError) {
|
||||||
if (value.isEmpty) {
|
if (value != null) {
|
||||||
return 'Please enter your email';
|
if (value.isEmpty) {
|
||||||
}
|
return 'Please enter your email';
|
||||||
//Regex for email validation
|
}
|
||||||
if (!RegExp(
|
//Regex for email validation
|
||||||
r'^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$')
|
if (!RegExp(
|
||||||
.hasMatch(value)) {
|
r'^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$')
|
||||||
return 'Please enter a valid email';
|
.hasMatch(value)) {
|
||||||
|
return 'Please enter a valid email';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -57,13 +59,15 @@ class LoginForm extends StatelessWidget {
|
|||||||
TextFormField(
|
TextFormField(
|
||||||
controller: AuthCubit.get(context).passwordController,
|
controller: AuthCubit.get(context).passwordController,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value != null) {
|
if (state is! AuthTokenError) {
|
||||||
if (value.isNotEmpty) {
|
if (value != null) {
|
||||||
if (value.length < 6) {
|
if (value.isNotEmpty) {
|
||||||
return 'Password must be at least 8 characters';
|
if (value.length < 6) {
|
||||||
|
return 'Password must be at least 8 characters';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 'Please enter your password';
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return 'Please enter your password';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -22,7 +22,7 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|||||||
part 'devices_state.dart';
|
part 'devices_state.dart';
|
||||||
|
|
||||||
class DevicesCubit extends Cubit<DevicesState> {
|
class DevicesCubit extends Cubit<DevicesState> {
|
||||||
DevicesCubit() : super(DevicesInitial()) {
|
DevicesCubit._() : super(DevicesInitial()) {
|
||||||
if (HomeCubit.getInstance().selectedSpace != null) {
|
if (HomeCubit.getInstance().selectedSpace != null) {
|
||||||
fetchGroups(HomeCubit.getInstance().selectedSpace!.id!);
|
fetchGroups(HomeCubit.getInstance().selectedSpace!.id!);
|
||||||
for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) {
|
for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) {
|
||||||
@ -32,6 +32,13 @@ class DevicesCubit extends Cubit<DevicesState> {
|
|||||||
}
|
}
|
||||||
bool _isClosed = false;
|
bool _isClosed = false;
|
||||||
|
|
||||||
|
static DevicesCubit? _instance;
|
||||||
|
static DevicesCubit getInstance() {
|
||||||
|
// If an instance already exists, return it
|
||||||
|
_instance ??= DevicesCubit._();
|
||||||
|
return _instance!;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() {
|
Future<void> close() {
|
||||||
_isClosed = true;
|
_isClosed = true;
|
||||||
|
@ -57,9 +57,6 @@ class DeviceModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
factory DeviceModel.fromJson(Map<String, dynamic> json) {
|
||||||
print(
|
|
||||||
'type : ${json['productId']} => ${devicesTypesMap[json['productId']]}');
|
|
||||||
|
|
||||||
String icon = '';
|
String icon = '';
|
||||||
DeviceType type = devicesTypesMap[json['productId']] ?? DeviceType.Other;
|
DeviceType type = devicesTypesMap[json['productId']] ?? DeviceType.Other;
|
||||||
|
|
||||||
@ -104,7 +101,8 @@ class DeviceModel {
|
|||||||
timeZone: json['timeZone'],
|
timeZone: json['timeZone'],
|
||||||
updateTime: json['updateTime'],
|
updateTime: json['updateTime'],
|
||||||
uuid: json['uuid'],
|
uuid: json['uuid'],
|
||||||
productType: devicesTypesMap[json['productName']] ?? DeviceType.Other,
|
productType: type,
|
||||||
|
// devicesTypesMap[json['productName']] ?? DeviceType.Other,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
|
|
||||||
class RoomModel {
|
class RoomModel {
|
||||||
|
@ -4,15 +4,15 @@ import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|||||||
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/devices_view_body.dart';
|
||||||
|
|
||||||
class DevicesView extends StatelessWidget {
|
class DevicesView extends StatelessWidget {
|
||||||
const DevicesView({super.key});
|
const DevicesView({super.key}); // Fixing the syntax for super.key
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||||
builder: (context, state) => Container(
|
builder: (_, state) => Container(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
width: MediaQuery.sizeOf(context).width,
|
width: MediaQuery.of(context).size.width,
|
||||||
height: MediaQuery.sizeOf(context).height,
|
height: MediaQuery.of(context).size.height,
|
||||||
child: const DevicesViewBody(),
|
child: const DevicesViewBody(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
|
||||||
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/widgets/room_page_switch.dart';
|
import 'package:syncrow_app/features/devices/view/widgets/room_page_switch.dart';
|
||||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import 'dart:js_util';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||||
@ -25,23 +23,18 @@ class RoomPageSwitch extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// if (device.productType == DeviceType.AC) {
|
|
||||||
// Navigator.push(
|
|
||||||
// context,
|
|
||||||
// CustomPageRoute(
|
|
||||||
// builder: (context) => AcInterface(deviceModel: device),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
switch (device.productType) {
|
switch (device.productType) {
|
||||||
case DeviceType.AC:
|
case DeviceType.AC:
|
||||||
Navigator.push(
|
{
|
||||||
context,
|
print("AC");
|
||||||
CustomPageRoute(
|
Navigator.push(
|
||||||
builder: (context) => AcInterface(deviceModel: device),
|
context,
|
||||||
),
|
CustomPageRoute(
|
||||||
);
|
builder: (context) => AcInterface(deviceModel: device),
|
||||||
break;
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DeviceType.WallSensor:
|
case DeviceType.WallSensor:
|
||||||
break;
|
break;
|
||||||
case DeviceType.CeilingSensor:
|
case DeviceType.CeilingSensor:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart';
|
|
||||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||||
import 'package:syncrow_app/utils/context_extension.dart';
|
import 'package:syncrow_app/utils/context_extension.dart';
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
import 'package:syncrow_app/features/app_layout/view/app_layout.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/widgets/didnt_get_code/didnt_get_code_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/didnt_get_code/didnt_get_code_view.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/widgets/login/login_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/login/login_view.dart';
|
||||||
@ -7,6 +8,7 @@ import 'package:syncrow_app/features/auth/view/widgets/privacy_policy/privacy_po
|
|||||||
import 'package:syncrow_app/features/auth/view/widgets/sign_up/sign_up_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/sign_up/sign_up_view.dart';
|
||||||
import 'package:syncrow_app/features/auth/view/widgets/user_agreement/user_agreement_view.dart';
|
import 'package:syncrow_app/features/auth/view/widgets/user_agreement/user_agreement_view.dart';
|
||||||
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart';
|
||||||
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||||
import 'package:syncrow_app/features/devices/view/devices_view.dart';
|
import 'package:syncrow_app/features/devices/view/devices_view.dart';
|
||||||
import 'package:syncrow_app/features/layout/view/layout_view.dart';
|
import 'package:syncrow_app/features/layout/view/layout_view.dart';
|
||||||
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
import 'package:syncrow_app/features/menu/view/menu_view.dart';
|
||||||
@ -25,7 +27,11 @@ class Router {
|
|||||||
|
|
||||||
case Routes.devicesRoute:
|
case Routes.devicesRoute:
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
builder: (_) => const DevicesView(), settings: settings);
|
builder: (_) => BlocProvider(
|
||||||
|
create: (_) => DevicesCubit.getInstance(),
|
||||||
|
child: const DevicesView(),
|
||||||
|
),
|
||||||
|
settings: settings);
|
||||||
|
|
||||||
case Routes.profileRoute:
|
case Routes.profileRoute:
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
|
@ -23,7 +23,7 @@ class MyBlocObserver extends BlocObserver {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose(BlocBase bloc) {
|
void onClose(BlocBase bloc) {
|
||||||
super.onClose(bloc);
|
|
||||||
print('onClose -- ${bloc.runtimeType}');
|
print('onClose -- ${bloc.runtimeType}');
|
||||||
|
super.onClose(bloc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user