Fakultas Ilmu Komputer UI

Commit 0d8f75b1 authored by Tsamara Esperanti Erwin's avatar Tsamara Esperanti Erwin 🦄
Browse files

Merge branch 'bugfixing' into 'staging'

Bugfixing

See merge request !100
parents 2c0a38c2 2bce63d6
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class CustomTextInputForm extends StatelessWidget {
class CustomTextInputForm extends StatefulWidget {
final String label;
final bool isPassword;
final Function onSave;
......@@ -30,37 +30,50 @@ class CustomTextInputForm extends StatelessWidget {
assert(prefixIcon != null),
super(key: key);
@override
_CustomTextInputFormState createState() => _CustomTextInputFormState();
}
class _CustomTextInputFormState extends State<CustomTextInputForm> {
bool _obscureText = true;
void togglePassword() {
setState(() {
_obscureText = !_obscureText;
});
}
@override
Widget build(BuildContext context) {
return TextFormField(
initialValue: initialValue,
initialValue: widget.initialValue,
decoration:
customInputDecorationForm(context, label, prefixText, prefixIcon),
obscureText: isPassword,
onFieldSubmitted: onSubmit,
onSaved: onSave,
maxLength: maxLength,
textInputAction: textInputAction,
keyboardType: isNumberOnly ? TextInputType.number : null,
inputFormatters: isNumberOnly
customInputDecorationForm(context, widget.label, widget.prefixText, widget.prefixIcon),
obscureText: widget.isPassword == true ? _obscureText : false,
onFieldSubmitted: widget.onSubmit,
onSaved: widget.onSave,
maxLength: widget.maxLength,
textInputAction: widget.textInputAction,
keyboardType: widget.isNumberOnly ? TextInputType.number : null,
inputFormatters: widget.isNumberOnly
? <TextInputFormatter>[WhitelistingTextInputFormatter.digitsOnly]
: null,
validator: (value) {
if (value.isEmpty) {
return 'Masukkan ${label.toLowerCase()}';
} else if (isPassword && value.length < 8) {
return 'Masukkan ${widget.label.toLowerCase()}';
} else if (widget.isPassword && value.length < 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 null;
},
);
}
}
InputDecoration customInputDecorationForm(
InputDecoration customInputDecorationForm(
BuildContext context, String label, String prefix, IconData prefixIcon) {
return InputDecoration(
prefixText: prefix,
labelText: label,
......@@ -68,5 +81,13 @@ InputDecoration customInputDecorationForm(
prefixIcon,
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';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:home_industry/Component/blue_button.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/router.dart';
import 'package:home_industry/Pages/Cart/model/cart_entity.dart';
......@@ -461,7 +460,7 @@ class _Donation extends StatelessWidget {
padding: const EdgeInsets.only(top: 10, left: 10),
child: TextField(
controller: textEditingController,
decoration: customInputDecorationForm(
decoration: CustomInputDecoForm(
context, 'Donasi', null, Icons.people_outline),
scrollPadding: const EdgeInsets.only(bottom: 80),
scrollPhysics: const BouncingScrollPhysics(),
......@@ -616,13 +615,22 @@ class _ItemCart extends StatelessWidget {
overflow: TextOverflow.ellipsis,
text: TextSpan(
text: cartItem.product.name,
style: Theme.of(context).textTheme.headline6.copyWith(
fontSize: 18, color: Theme.of(context).primaryColor),
style: Theme
.of(context)
.textTheme
.headline6
.copyWith(
fontSize: 18, color: Theme
.of(context)
.primaryColor),
children: <TextSpan>[
if (cartItem.product.preOrder)
TextSpan(
text: ' - preorder',
style: Theme.of(context).textTheme.subtitle1)
style: Theme
.of(context)
.textTheme
.subtitle1)
])),
trailing: PriceTextFormatter(
price: '${cartItem.quantity * double.parse(cartItem.product.price)}',
......@@ -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