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