Fakultas Ilmu Komputer UI

Commit 2bce63d6 authored by Tsamara Esperanti Erwin's avatar Tsamara Esperanti Erwin
Browse files

[REFACTOR] View password

parent cbdf1d53
Pipeline #61980 passed with stages
in 7 minutes and 8 seconds
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
class CustomTextInputForm extends StatelessWidget { class CustomTextInputForm extends StatefulWidget {
final String label; final String label;
final bool isPassword; final bool isPassword;
final Function onSave; final Function onSave;
...@@ -30,37 +30,50 @@ class CustomTextInputForm extends StatelessWidget { ...@@ -30,37 +30,50 @@ class CustomTextInputForm extends StatelessWidget {
assert(prefixIcon != null), assert(prefixIcon != null),
super(key: key); super(key: key);
@override
_CustomTextInputFormState createState() => _CustomTextInputFormState();
}
class _CustomTextInputFormState extends State<CustomTextInputForm> {
bool _obscureText = true;
void togglePassword() {
setState(() {
_obscureText = !_obscureText;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextFormField( return TextFormField(
initialValue: initialValue, initialValue: widget.initialValue,
decoration: decoration:
customInputDecorationForm(context, label, prefixText, prefixIcon), customInputDecorationForm(context, widget.label, widget.prefixText, widget.prefixIcon),
obscureText: isPassword, obscureText: widget.isPassword == true ? _obscureText : false,
onFieldSubmitted: onSubmit, onFieldSubmitted: widget.onSubmit,
onSaved: onSave, onSaved: widget.onSave,
maxLength: maxLength, maxLength: widget.maxLength,
textInputAction: textInputAction, textInputAction: widget.textInputAction,
keyboardType: isNumberOnly ? TextInputType.number : null, keyboardType: widget.isNumberOnly ? TextInputType.number : null,
inputFormatters: isNumberOnly inputFormatters: widget.isNumberOnly
? <TextInputFormatter>[WhitelistingTextInputFormatter.digitsOnly] ? <TextInputFormatter>[WhitelistingTextInputFormatter.digitsOnly]
: null, : null,
validator: (value) { validator: (value) {
if (value.isEmpty) { if (value.isEmpty) {
return 'Masukkan ${label.toLowerCase()}'; return 'Masukkan ${widget.label.toLowerCase()}';
} else if (isPassword && value.length < 8) { } else if (widget.isPassword && value.length < 8) {
return 'Panjang password minimal 8'; return 'Panjang password minimal 8';
} else if (prefixText == '+62' && value.length <= 8) { } else if (widget.prefixText == '+62' && value.length <= 8) {
return 'Masukkan nomor telepon yang benar'; return 'Masukkan nomor telepon yang benar';
} }
return null; return null;
}, },
); );
} }
}
InputDecoration customInputDecorationForm( InputDecoration customInputDecorationForm(
BuildContext context, String label, String prefix, IconData prefixIcon) { BuildContext context, String label, String prefix, IconData prefixIcon) {
return InputDecoration( return InputDecoration(
prefixText: prefix, prefixText: prefix,
labelText: label, labelText: label,
...@@ -68,5 +81,13 @@ InputDecoration customInputDecorationForm( ...@@ -68,5 +81,13 @@ InputDecoration customInputDecorationForm(
prefixIcon, prefixIcon,
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
), ),
suffixIcon: label == 'Password' ? GestureDetector(
onTap: togglePassword,
child: Icon(
Icons.remove_red_eye,
color: Theme.of(context).primaryColor,
),
) : null,
); );
}
} }
...@@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; ...@@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:home_industry/Component/blue_button.dart'; import 'package:home_industry/Component/blue_button.dart';
import 'package:home_industry/Component/custom_circular.dart'; import 'package:home_industry/Component/custom_circular.dart';
import 'package:home_industry/Component/custom_input_form.dart';
import 'package:home_industry/Component/price_text_formatter.dart'; import 'package:home_industry/Component/price_text_formatter.dart';
import 'package:home_industry/Component/router.dart'; import 'package:home_industry/Component/router.dart';
import 'package:home_industry/Pages/Cart/model/cart_entity.dart'; import 'package:home_industry/Pages/Cart/model/cart_entity.dart';
...@@ -461,7 +460,7 @@ class _Donation extends StatelessWidget { ...@@ -461,7 +460,7 @@ class _Donation extends StatelessWidget {
padding: const EdgeInsets.only(top: 10, left: 10), padding: const EdgeInsets.only(top: 10, left: 10),
child: TextField( child: TextField(
controller: textEditingController, controller: textEditingController,
decoration: customInputDecorationForm( decoration: CustomInputDecoForm(
context, 'Donasi', null, Icons.people_outline), context, 'Donasi', null, Icons.people_outline),
scrollPadding: const EdgeInsets.only(bottom: 80), scrollPadding: const EdgeInsets.only(bottom: 80),
scrollPhysics: const BouncingScrollPhysics(), scrollPhysics: const BouncingScrollPhysics(),
...@@ -616,13 +615,22 @@ class _ItemCart extends StatelessWidget { ...@@ -616,13 +615,22 @@ class _ItemCart extends StatelessWidget {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
text: TextSpan( text: TextSpan(
text: cartItem.product.name, text: cartItem.product.name,
style: Theme.of(context).textTheme.headline6.copyWith( style: Theme
fontSize: 18, color: Theme.of(context).primaryColor), .of(context)
.textTheme
.headline6
.copyWith(
fontSize: 18, color: Theme
.of(context)
.primaryColor),
children: <TextSpan>[ children: <TextSpan>[
if (cartItem.product.preOrder) if (cartItem.product.preOrder)
TextSpan( TextSpan(
text: ' - preorder', text: ' - preorder',
style: Theme.of(context).textTheme.subtitle1) style: Theme
.of(context)
.textTheme
.subtitle1)
])), ])),
trailing: PriceTextFormatter( trailing: PriceTextFormatter(
price: '${cartItem.quantity * double.parse(cartItem.product.price)}', price: '${cartItem.quantity * double.parse(cartItem.product.price)}',
...@@ -649,3 +657,17 @@ class _ItemCart extends StatelessWidget { ...@@ -649,3 +657,17 @@ class _ItemCart extends StatelessWidget {
); );
} }
} }
InputDecoration CustomInputDecoForm(BuildContext context, String label,
String prefix, IconData prefixIcon) {
return InputDecoration(
prefixText: prefix,
labelText: label,
prefixIcon: Icon(
prefixIcon,
color: Theme
.of(context)
.primaryColor,
),
);
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment