Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

REFACTOR(AUTH-CROSS): simplify the sign-up screen code #4

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 89 additions & 109 deletions lib/features/auth/view/screens/sign_up_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import 'package:flutter_shakemywidget/flutter_shakemywidget.dart';
import 'package:telware_cross_platform/core/theme/palette.dart';
import 'package:flutter/material.dart';
import 'package:telware_cross_platform/core/utils.dart';
import 'package:telware_cross_platform/features/auth/view/widget/auth_input_field.dart';
import 'package:telware_cross_platform/features/auth/view/widget/shake_my_auth_input.dart';
import 'package:telware_cross_platform/features/auth/view/widget/title_element.dart';
import 'package:telware_cross_platform/features/auth/view/widget/circular_button.dart';
import 'package:telware_cross_platform/core/theme/dimensions.dart';
import 'package:telware_cross_platform/core/theme/sizes.dart';
import 'package:vibration/vibration.dart';

Expand Down Expand Up @@ -104,115 +103,96 @@ class #ScreenState extends State<#Screen> {
body: Padding(
padding: const EdgeInsets.only(top: 40),
child: Form(
key: formKey,
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: isKeyboardOpen(context) ? 150 : 0,
),
const TitleElement(
name: 'Your email address',
color: Palette.primaryText,
fontSize: Sizes.primaryText,
fontWeight: FontWeight.bold,
paddingBottom: 10.0),
const TitleElement(
name:
'Please confirm your email address and enter your password.',
color: Palette.accentText,
fontSize: Sizes.secondaryText,
paddingBottom: 30.0,
width: 250.0),
ShakeMe(
key: emailShakeKey,
shakeCount: 3,
shakeOffset: 10,
shakeDuration: const Duration(milliseconds: 500),
child: AuthInputField(
name: 'Email',
paddingBottom: Dimensions.inputPaddingBottom,
paddingLeft: Dimensions.inputPaddingLeft,
paddingRight: Dimensions.inputPaddingRight,
isFocused: isEmailFocused,
focusNode: emailFocusNode,
validator: emailValidator,
controller: emailController,
key: formKey,
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: isKeyboardOpen(context) ? 150 : 0,
),
const TitleElement(
name: 'Your email address',
color: Palette.primaryText,
fontSize: Sizes.primaryText,
fontWeight: FontWeight.bold,
paddingBottom: 10.0,
),
const TitleElement(
name:
'Please confirm your email address and enter your password.',
color: Palette.accentText,
fontSize: Sizes.secondaryText,
paddingBottom: 30.0,
width: 250.0),
ShakeMyAuthInput(
name: 'Email',
shakeKey: emailShakeKey,
isFocused: isEmailFocused,
focusNode: emailFocusNode,
controller: emailController,
validator: emailValidator,
),
ShakeMyAuthInput(
name: 'Password',
shakeKey: passwordShakeKey,
isFocused: isPasswordFocused,
focusNode: passwordFocusNode,
controller: passwordController,
obscure: true,
),
ShakeMyAuthInput(
name: 'Confirm Password',
shakeKey: confirmPasswordShakeKey,
isFocused: isConfirmPasswordFocused,
focusNode: confirmPasswordFocusNode,
controller: confirmPasswordController,
obscure: true,
validator: customValidation,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const TitleElement(
name: 'Already have an account? ',
color: Palette.primaryText,
fontSize: Sizes.infoText),
TextButton(
onPressed: () => {},
style: TextButton.styleFrom(
minimumSize: Size.zero,
padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: const TitleElement(
name: 'Log in',
color: Palette.accent,
fontSize: Sizes.infoText,
fontWeight: FontWeight.bold,
),
),
),
ShakeMe(
key: passwordShakeKey,
shakeCount: 3,
shakeOffset: 10,
shakeDuration: const Duration(milliseconds: 500),
child: AuthInputField(
name: 'Password',
paddingBottom: Dimensions.inputPaddingBottom,
paddingLeft: Dimensions.inputPaddingLeft,
paddingRight: Dimensions.inputPaddingRight,
isFocused: isPasswordFocused,
focusNode: passwordFocusNode,
obscure: true,
controller: passwordController,
)),
ShakeMe(
key: confirmPasswordShakeKey,
shakeCount: 3,
shakeOffset: 10,
shakeDuration: const Duration(milliseconds: 500),
child: AuthInputField(
name: 'Confirm Password',
paddingBottom: Dimensions.inputPaddingBottom,
paddingLeft: Dimensions.inputPaddingLeft,
paddingRight: Dimensions.inputPaddingRight,
isFocused: isConfirmPasswordFocused,
focusNode: confirmPasswordFocusNode,
obscure: true,
controller: confirmPasswordController,
validator: customValidation,
)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const TitleElement(
name: 'Already have an account? ',
color: Palette.primaryText,
fontSize: Sizes.infoText),
TextButton(
onPressed: () => {},
style: TextButton.styleFrom(
minimumSize: Size.zero,
padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: const TitleElement(
name: 'Log in',
color: Palette.accent,
fontSize: Sizes.infoText,
fontWeight: FontWeight.bold,
)),
],
),
],
),
AnimatedPositioned(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
right: 20,
bottom: isKeyboardOpen(context) ? 10 : 150,
child: CircularButton(
icon: Icons.arrow_forward,
iconSize: Sizes.iconSize,
radius: Sizes.circleButtonRadius,
formKey: formKey,
handelSubmit: handelSubmit,
],
),
)
],
)),
],
),
AnimatedPositioned(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
right: 20,
bottom: isKeyboardOpen(context) ? 10 : 150,
child: CircularButton(
icon: Icons.arrow_forward,
iconSize: Sizes.iconSize,
radius: Sizes.circleButtonRadius,
formKey: formKey,
handelSubmit: handelSubmit,
),
),
],
),
),
),
);
}
Expand Down
46 changes: 46 additions & 0 deletions lib/features/auth/view/widget/shake_my_auth_input.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_shakemywidget/flutter_shakemywidget.dart';
import 'package:telware_cross_platform/core/theme/dimensions.dart';
import 'package:telware_cross_platform/features/auth/view/widget/auth_input_field.dart';

class ShakeMyAuthInput extends StatelessWidget {
const ShakeMyAuthInput({
super.key,
required this.name,
required this.shakeKey,
required this.isFocused,
required this.focusNode,
this.obscure = false,
required this.controller,
this.validator,
});

final GlobalKey<ShakeWidgetState> shakeKey;
final String name;
final bool obscure;
final bool isFocused;
final FocusNode focusNode;
final TextEditingController controller;
final FormFieldValidator<String>? validator;

@override
Widget build(BuildContext context) {
return ShakeMe(
key: shakeKey,
shakeCount: 3,
shakeOffset: 10,
shakeDuration: const Duration(milliseconds: 500),
child: AuthInputField(
name: name,
paddingBottom: Dimensions.inputPaddingBottom,
paddingLeft: Dimensions.inputPaddingLeft,
paddingRight: Dimensions.inputPaddingRight,
isFocused: isFocused,
focusNode: focusNode,
validator: validator,
controller: controller,
obscure: obscure,
),
);
}
}
7 changes: 3 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class TelWare extends ConsumerStatefulWidget {
}

class _TelWareState extends ConsumerState<TelWare> {

@override
void initState() {
super.initState();
Expand All @@ -43,6 +42,6 @@ class _TelWareState extends ConsumerState<TelWare> {
#Screen.route: (context) => const #Screen(),
},
home: const SplashScreen(),
    );
  }
}
);
}
}