249 lines
8.1 KiB
Dart
249 lines
8.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../app/constant.dart';
|
|
|
|
// login
|
|
class CustomTextFieldLogin extends StatelessWidget {
|
|
final String hintText;
|
|
final String labelText;
|
|
final bool isPassword;
|
|
final bool obscureText;
|
|
final bool isMaxLine;
|
|
final void Function()? onToggle;
|
|
final TextEditingController? ctrl;
|
|
final void Function(String)? onChange;
|
|
final void Function(String)? onSubmitted;
|
|
final void Function()? onTap;
|
|
final void Function()? onEditingComplete;
|
|
final FocusNode? focusNode;
|
|
final bool isPrefix;
|
|
|
|
final bool isError;
|
|
final bool isTextArea;
|
|
final bool isReadOnly;
|
|
|
|
final bool hasFocus;
|
|
|
|
const CustomTextFieldLogin(
|
|
{Key? key,
|
|
required this.hintText,
|
|
required this.labelText,
|
|
this.isPassword = false,
|
|
this.isMaxLine = false,
|
|
this.onToggle,
|
|
this.obscureText = false,
|
|
this.ctrl,
|
|
this.onChange,
|
|
this.onSubmitted,
|
|
this.focusNode,
|
|
this.isPrefix = false,
|
|
this.isTextArea = false,
|
|
this.isError = false,
|
|
this.isReadOnly = false,
|
|
this.hasFocus = false,
|
|
this.onTap,
|
|
this.onEditingComplete})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextField(
|
|
autofocus: false,
|
|
showCursor: (hasFocus) ? true : false,
|
|
readOnly: isReadOnly,
|
|
controller: ctrl,
|
|
enableInteractiveSelection: false,
|
|
style:
|
|
Constant.body1(context: context).copyWith(color: Constant.textBlack),
|
|
obscureText: obscureText,
|
|
onChanged: onChange,
|
|
onSubmitted: onSubmitted,
|
|
onTap: onTap,
|
|
onEditingComplete: onEditingComplete,
|
|
focusNode: focusNode,
|
|
maxLines: (isTextArea) ? 4 : 1,
|
|
cursorColor: Constant.primaryBlue,
|
|
decoration: InputDecoration(
|
|
// fillColor: (hasFocus) ? Constant.primaryMain : Constant.textGrey,
|
|
filled: true,
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(
|
|
color: (hasFocus) ? Constant.primaryMain : Constant.textGrey,
|
|
width: 2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
enabledBorder: (hasFocus)
|
|
? OutlineInputBorder(
|
|
// ignore: prefer_const_constructors
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(
|
|
color: Constant.primaryMain,
|
|
width: 1,
|
|
),
|
|
)
|
|
: OutlineInputBorder(
|
|
// ignore: prefer_const_constructors
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(
|
|
color: Constant.textGrey,
|
|
width: 2,
|
|
),
|
|
),
|
|
// hintStyle: Constant.body1_400(context: context)
|
|
// .copyWith(color: Constant.textBlack),
|
|
// labelStyle: Constant.body3_400(context: context),
|
|
hintStyle: Constant.body1(context: context).copyWith(
|
|
color: (hasFocus) ? Constant.primaryMain : Constant.textGrey),
|
|
// mainkan focus
|
|
labelStyle: Constant.body1(context: context).copyWith(
|
|
color: (hasFocus) ? Constant.primaryMain : Constant.textGrey),
|
|
labelText: labelText,
|
|
hintText: hintText,
|
|
alignLabelWithHint: true,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(30),
|
|
),
|
|
prefixIcon: isPrefix ? const Icon(Icons.search) : null,
|
|
prefixStyle: isPrefix ? Constant.body1(context: context) : null,
|
|
suffixIcon: isPassword
|
|
? IconButton(
|
|
alignment: Alignment.centerRight,
|
|
onPressed: onToggle,
|
|
icon: Icon(
|
|
Icons.remove_red_eye,
|
|
color: (hasFocus) ? Constant.primaryMain : Constant.textGrey,
|
|
),
|
|
iconSize: Constant.getActualY(context: context, y: 24),
|
|
)
|
|
: null,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// selain inputan login
|
|
class CustomTextFieldInputan extends StatelessWidget {
|
|
final String hintText;
|
|
final String labelText;
|
|
final bool isPassword;
|
|
final bool obscureText;
|
|
final bool isMaxLine;
|
|
final void Function()? onToggle;
|
|
final TextEditingController? ctrl;
|
|
final void Function(String)? onChange;
|
|
final void Function(String)? onSubmitted;
|
|
final void Function()? onTap;
|
|
final void Function()? onEditingComplete;
|
|
final FocusNode? focusNode;
|
|
final bool isPrefix;
|
|
|
|
final bool isError;
|
|
final bool isTextArea;
|
|
final bool isReadOnly;
|
|
|
|
final bool hasFocus;
|
|
|
|
const CustomTextFieldInputan(
|
|
{Key? key,
|
|
required this.hintText,
|
|
required this.labelText,
|
|
this.isPassword = false,
|
|
this.isMaxLine = false,
|
|
this.onToggle,
|
|
this.obscureText = false,
|
|
this.ctrl,
|
|
this.onChange,
|
|
this.onSubmitted,
|
|
this.focusNode,
|
|
this.isPrefix = false,
|
|
this.isTextArea = false,
|
|
this.isError = false,
|
|
this.isReadOnly = false,
|
|
this.hasFocus = true,
|
|
this.onTap,
|
|
this.onEditingComplete})
|
|
: super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return TextField(
|
|
enabled: (isReadOnly == true) ? false : true,
|
|
autofocus: false,
|
|
showCursor: (hasFocus) ? true : false,
|
|
readOnly: (isReadOnly == true) ? true : false,
|
|
controller: ctrl,
|
|
enableInteractiveSelection: false,
|
|
style:
|
|
Constant.body1(context: context).copyWith(color: Constant.textBlack),
|
|
obscureText: obscureText,
|
|
onChanged: onChange,
|
|
onSubmitted: onSubmitted,
|
|
onTap: (isReadOnly == true) ? null : onTap,
|
|
onEditingComplete: onEditingComplete,
|
|
focusNode: focusNode,
|
|
maxLines: (isTextArea) ? 4 : 1,
|
|
cursorColor: Constant.primaryBlue,
|
|
decoration: InputDecoration(
|
|
// fillColor: (hasFocus) ? Constant.primaryMain : Constant.textGrey,
|
|
// filled: true,
|
|
disabledBorder: OutlineInputBorder(
|
|
// ignore: prefer_const_constructors
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(
|
|
color: Constant.textGrey,
|
|
width: 1,
|
|
),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderSide: BorderSide(color: Constant.primaryMain, width: 2),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
enabledBorder: (hasFocus)
|
|
? OutlineInputBorder(
|
|
// ignore: prefer_const_constructors
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(
|
|
color: Constant.primaryMain,
|
|
width: 1,
|
|
),
|
|
)
|
|
: OutlineInputBorder(
|
|
// ignore: prefer_const_constructors
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
borderSide: BorderSide(
|
|
color: Constant.textGrey,
|
|
width: 1,
|
|
),
|
|
),
|
|
// hintStyle: Constant.body1_400(context: context)
|
|
// .copyWith(color: Constant.textBlack),
|
|
// labelStyle: Constant.body3_400(context: context),
|
|
hintStyle: Constant.body1(context: context).copyWith(
|
|
color: (hasFocus) ? Constant.primaryMain : Constant.textGrey),
|
|
// mainkan focus
|
|
labelStyle: Constant.body1(context: context).copyWith(
|
|
color: (hasFocus) ? Constant.primaryMain : Constant.textGrey),
|
|
labelText: labelText,
|
|
hintText: hintText,
|
|
alignLabelWithHint: true,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(30),
|
|
),
|
|
prefixIcon: isPrefix ? const Icon(Icons.document_scanner) : null,
|
|
prefixStyle: isPrefix ? Constant.body1(context: context) : null,
|
|
suffixIcon: isPassword
|
|
? IconButton(
|
|
alignment: Alignment.centerRight,
|
|
onPressed: onToggle,
|
|
icon: Icon(
|
|
Icons.remove_red_eye,
|
|
color: (hasFocus) ? Constant.primaryMain : Constant.textGrey,
|
|
),
|
|
iconSize: Constant.getActualY(context: context, y: 24),
|
|
)
|
|
: null,
|
|
),
|
|
);
|
|
}
|
|
}
|