Skip to content

Commit

Permalink
rfac: abstracts TextField to AppTextField and AppFormField
Browse files Browse the repository at this point in the history
  • Loading branch information
am-casper committed Jan 10, 2024
1 parent a2002b5 commit 781871f
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 159 deletions.
69 changes: 69 additions & 0 deletions lib/presentation/components/app_formfield.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/components/app_textfield.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class AppFormField extends StatelessWidget {
const AppFormField({
Key? key,
required this.hintText,
this.controller,
this.onChanged,
this.obscureText,
this.suffix,
this.border,
required this.title,
this.maxLength,
this.maxLines,
this.titleStyle,
}) : assert(
obscureText == null || suffix != null,
'Suffix should be provided if obscureText is provided',
),
assert(
controller != null || onChanged != null,
'Either controller or onChanged should be provided',
),
super(key: key);

final String hintText;
final TextEditingController? controller;
final Function(String)? onChanged;
final bool? obscureText;
final Widget? suffix;
final InputBorder? border;
final String title;
final int? maxLength;
final int? maxLines;
final TextStyle? titleStyle;

@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: titleStyle ??
GoogleFonts.notoSans(
fontSize: 18.toAutoScaledFont,
fontWeight: FontWeight.w600,
),
),
SizedBox(
height: title == "Description" ? 0 : 20.toAutoScaledHeight,
),
AppTextField(
controller: controller,
onChanged: onChanged,
obscureText: obscureText,
hintText: hintText,
suffix: suffix,
border: border,
maxLength: maxLength,
maxLines: maxLines,
),
],
);
}
}
77 changes: 46 additions & 31 deletions lib/presentation/components/app_textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,60 @@ import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class AppTextField extends StatelessWidget {
final TextEditingController controller;
final String hintText;
final bool obscureText;
final Function() suffixIconOnPressed;
final bool showSuffixIcon;

const AppTextField({
Key? key,
required this.controller,
required this.hintText,
required this.obscureText,
required this.suffixIconOnPressed,
required this.showSuffixIcon,
}) : super(key: key);
this.controller,
this.onChanged,
this.obscureText,
this.suffix,
this.border,
this.maxLength,
this.maxLines,
}) : assert(
obscureText == null || suffix != null,
'Suffix should be provided if obscureText is provided',
),
assert(
controller != null || onChanged != null,
'Either controller or onChanged should be provided',
),
super(key: key);

final String hintText;
final TextEditingController? controller;
final Function(String)? onChanged;
final bool? obscureText;
final Widget? suffix;
final InputBorder? border;
final int? maxLength;
final int? maxLines;

@override
Widget build(BuildContext context) {
return TextField(
controller: controller,
obscureText: obscureText,
onChanged: onChanged,
obscureText: obscureText ?? false,
decoration: InputDecoration(
hintText: hintText,
hintStyle: GoogleFonts.lato(
fontSize: 12.toAutoScaledFont,
color: const Color(0xFF111111),
fontWeight: FontWeight.w600,
),
border: OutlineInputBorder(
borderSide:
BorderSide(color: const Color(0xFF111111).withOpacity(0.25)),
borderRadius: BorderRadius.circular(5),
),
contentPadding: EdgeInsets.symmetric(horizontal: 20.toAutoScaledWidth),
suffixIcon: IconButton(
onPressed: suffixIconOnPressed,
icon: showSuffixIcon
? const Icon(Icons.visibility, color: Color(0xFF757575))
: const Icon(Icons.visibility_off, color: Color(0xFF757575)),
),
),
hintText: hintText,
hintStyle: GoogleFonts.lato(
fontSize: 12.toAutoScaledFont,
color: const Color(0xFF111111),
fontWeight: FontWeight.w600,
),
border: border ??
OutlineInputBorder(
borderSide: BorderSide(
color: const Color(0xFF111111).withOpacity(0.25)),
borderRadius: BorderRadius.circular(5),
),
contentPadding: EdgeInsets.symmetric(
horizontal: 20.toAutoScaledWidth,
vertical: 15.toAutoScaledHeight),
suffixIcon: suffix),
maxLength: maxLength,
maxLines: maxLines ?? 1,
);
}
}
22 changes: 10 additions & 12 deletions lib/presentation/feedback/feedback_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appetizer/app_theme.dart';
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/domain/repositories/feedback_repository.dart';
import 'package:appetizer/presentation/components/app_formfield.dart';
import 'package:appetizer/presentation/components/black_button.dart';
import 'package:appetizer/presentation/feedback/bloc/feedback_page_bloc.dart';
import 'package:appetizer/presentation/feedback/components/FeedbackTile/feedback_tile.dart';
Expand Down Expand Up @@ -72,29 +73,26 @@ class FeedbackScreen extends StatelessWidget {
fontWeight: FontWeight.w400,
),
),
Text(
'Description',
style: TextStyle(
AppFormField(
hintText: "",
title: "Description",
controller: textController,
titleStyle: TextStyle(
color: Colors.black.withOpacity(0.5400000214576721),
fontSize: 12.toAutoScaledFont,
fontFamily: 'Open Sans',
fontWeight: FontWeight.w400,
),
),
TextField(
controller: textController,
onChanged: (value) => context
.read<FeedbackPageBloc>()
.add(FeedbackPageDescriptionChangedEvent(
description: value)),
maxLength: 200,
maxLines: 5,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
width: 0.5.toAutoScaledWidth,
color: const Color.fromARGB(37, 0, 0, 0),
),
border: OutlineInputBorder(
borderSide: BorderSide(
width: 0.5.toAutoScaledWidth,
color: const Color.fromARGB(37, 0, 0, 0),
),
),
),
Expand Down
40 changes: 0 additions & 40 deletions lib/presentation/login/components/login_textfield.dart

This file was deleted.

72 changes: 36 additions & 36 deletions lib/presentation/login/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/app/bloc/app_bloc.dart';
import 'package:appetizer/presentation/components/app_formfield.dart';
import 'package:appetizer/presentation/components/app_textfield.dart';
import 'package:appetizer/presentation/components/loading_indicator.dart';
import 'package:appetizer/presentation/components/made_by_mdg.dart';
import 'package:appetizer/presentation/components/raise_query_button.dart';
import 'package:appetizer/presentation/login/components/channeli_button.dart';
import 'package:appetizer/presentation/login/components/login_button.dart';
import 'package:appetizer/presentation/login/bloc/login_bloc.dart';
import 'package:appetizer/presentation/login/components/login_textfield.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -94,19 +94,12 @@ class LoginScreen extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Set Password',
style: GoogleFonts.notoSans(
fontSize: 18.toAutoScaledFont,
fontWeight: FontWeight.w600,
),
),
20.toVerticalSizedBox,
AppTextField(
controller: _controller,
hintText: 'Create Password',
obscureText: !state.showPassword,
suffixIconOnPressed: () {
AppFormField(
controller: _controller,
hintText: 'Create Password',
obscureText: !state.showPassword,
suffix: IconButton(
onPressed: () {
BlocProvider.of<LoginBloc>(context).add(
ToggleObscureCreatePassword(
showPassword: !state.showPassword,
Expand All @@ -115,13 +108,21 @@ class LoginScreen extends StatelessWidget {
),
);
},
showSuffixIcon: state.showPassword),
icon: state.showPassword
? const Icon(Icons.visibility,
color: Color(0xFF757575))
: const Icon(Icons.visibility_off,
color: Color(0xFF757575)),
),
title: 'Set Password',
),
10.toVerticalSizedBox,
AppTextField(
controller: _controller2,
hintText: 'Confirm Password',
obscureText: !state.showConfirmPassword,
suffixIconOnPressed: () {
controller: _controller2,
hintText: 'Confirm Password',
obscureText: !state.showConfirmPassword,
suffix: IconButton(
onPressed: () {
BlocProvider.of<LoginBloc>(context).add(
ToggleObscureCreatePassword(
showPassword: state.showPassword,
Expand All @@ -130,7 +131,13 @@ class LoginScreen extends StatelessWidget {
),
);
},
showSuffixIcon: state.showConfirmPassword),
icon: state.showConfirmPassword
? const Icon(Icons.visibility,
color: Color(0xFF757575))
: const Icon(Icons.visibility_off,
color: Color(0xFF757575)),
),
),
SizedBox(
height: 30.toAutoScaledHeight,
child: Text(
Expand Down Expand Up @@ -164,27 +171,20 @@ class LoginScreen extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
state is ForgotPasswordState
AppFormField(
hintText: state is EnterPassword
? "Password"
: state is ForgotPasswordState
? "Email id"
: 'Enrollment No.',
title: state is ForgotPasswordState
? 'Forgot Password'
: 'Login/SignUp',
style: GoogleFonts.notoSans(
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
20.toVerticalSizedBox,
LoginTextField(
controller: _controller,
obscureText: state is EnterPassword
? !state.showPassword
: false,
hintText: state is EnterPassword
? "Password"
: state is ForgotPasswordState
? "Email id"
: 'Enrollment No.',
suffixIcon: state is EnterPassword
suffix: state is EnterPassword
? IconButton(
onPressed: () {
BlocProvider.of<LoginBloc>(context).add(
Expand All @@ -196,7 +196,7 @@ class LoginScreen extends StatelessWidget {
color: Color(0xFF757575))
: const Icon(Icons.visibility_off,
color: Color(0xFF757575)))
: null,
: const SizedBox(),
),
state is EnterPassword
? SizedBox(
Expand Down
Loading

0 comments on commit 781871f

Please sign in to comment.