|
@@ -1,85 +1,105 @@
|
|
import 'package:flowy_infra/size.dart';
|
|
import 'package:flowy_infra/size.dart';
|
|
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
|
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
|
-import 'package:flowy_infra_ui/widget/text_field_container.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flowy_infra/time/duration.dart';
|
|
import 'package:flowy_infra/time/duration.dart';
|
|
|
|
|
|
-// ignore: must_be_immutable
|
|
|
|
class RoundedInputField extends StatefulWidget {
|
|
class RoundedInputField extends StatefulWidget {
|
|
final String? hintText;
|
|
final String? hintText;
|
|
- final IconData? icon;
|
|
|
|
final bool obscureText;
|
|
final bool obscureText;
|
|
final Widget? obscureIcon;
|
|
final Widget? obscureIcon;
|
|
final Widget? obscureHideIcon;
|
|
final Widget? obscureHideIcon;
|
|
final Color normalBorderColor;
|
|
final Color normalBorderColor;
|
|
- final Color highlightBorderColor;
|
|
|
|
|
|
+ final Color errorBorderColor;
|
|
final Color cursorColor;
|
|
final Color cursorColor;
|
|
|
|
+ final Color? focusBorderColor;
|
|
final String errorText;
|
|
final String errorText;
|
|
final TextStyle style;
|
|
final TextStyle style;
|
|
final ValueChanged<String>? onChanged;
|
|
final ValueChanged<String>? onChanged;
|
|
final String? initialValue;
|
|
final String? initialValue;
|
|
- late bool enableObscure;
|
|
|
|
- var _text = "";
|
|
|
|
|
|
+ final EdgeInsets margin;
|
|
|
|
+ final EdgeInsets padding;
|
|
|
|
+ final EdgeInsets contentPadding;
|
|
|
|
+ final double height;
|
|
|
|
|
|
- RoundedInputField({
|
|
|
|
|
|
+ const RoundedInputField({
|
|
Key? key,
|
|
Key? key,
|
|
this.hintText,
|
|
this.hintText,
|
|
this.errorText = "",
|
|
this.errorText = "",
|
|
this.initialValue,
|
|
this.initialValue,
|
|
- this.icon,
|
|
|
|
this.obscureText = false,
|
|
this.obscureText = false,
|
|
this.obscureIcon,
|
|
this.obscureIcon,
|
|
this.obscureHideIcon,
|
|
this.obscureHideIcon,
|
|
this.onChanged,
|
|
this.onChanged,
|
|
this.normalBorderColor = Colors.transparent,
|
|
this.normalBorderColor = Colors.transparent,
|
|
- this.highlightBorderColor = Colors.transparent,
|
|
|
|
|
|
+ this.errorBorderColor = Colors.transparent,
|
|
|
|
+ this.focusBorderColor,
|
|
this.cursorColor = Colors.black,
|
|
this.cursorColor = Colors.black,
|
|
this.style = const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
|
this.style = const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
|
- }) : super(key: key) {
|
|
|
|
- enableObscure = obscureText;
|
|
|
|
- }
|
|
|
|
|
|
+ this.margin = EdgeInsets.zero,
|
|
|
|
+ this.padding = EdgeInsets.zero,
|
|
|
|
+ this.contentPadding = const EdgeInsets.symmetric(horizontal: 10),
|
|
|
|
+ this.height = 48,
|
|
|
|
+ }) : super(key: key);
|
|
|
|
|
|
@override
|
|
@override
|
|
State<RoundedInputField> createState() => _RoundedInputFieldState();
|
|
State<RoundedInputField> createState() => _RoundedInputFieldState();
|
|
}
|
|
}
|
|
|
|
|
|
class _RoundedInputFieldState extends State<RoundedInputField> {
|
|
class _RoundedInputFieldState extends State<RoundedInputField> {
|
|
|
|
+ String inputText = "";
|
|
|
|
+ bool obscuteText = false;
|
|
|
|
+
|
|
@override
|
|
@override
|
|
- Widget build(BuildContext context) {
|
|
|
|
- final Icon? newIcon = widget.icon == null
|
|
|
|
- ? null
|
|
|
|
- : Icon(
|
|
|
|
- widget.icon!,
|
|
|
|
- color: const Color(0xFF6F35A5),
|
|
|
|
- );
|
|
|
|
|
|
+ void initState() {
|
|
|
|
+ obscuteText = widget.obscureText;
|
|
|
|
+ super.initState();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ @override
|
|
|
|
+ Widget build(BuildContext context) {
|
|
var borderColor = widget.normalBorderColor;
|
|
var borderColor = widget.normalBorderColor;
|
|
|
|
+ var focusBorderColor = widget.focusBorderColor ?? borderColor;
|
|
|
|
+
|
|
if (widget.errorText.isNotEmpty) {
|
|
if (widget.errorText.isNotEmpty) {
|
|
- borderColor = widget.highlightBorderColor;
|
|
|
|
|
|
+ borderColor = widget.errorBorderColor;
|
|
|
|
+ focusBorderColor = borderColor;
|
|
}
|
|
}
|
|
|
|
|
|
List<Widget> children = [
|
|
List<Widget> children = [
|
|
- TextFieldContainer(
|
|
|
|
- height: 48,
|
|
|
|
- borderRadius: Corners.s10Border,
|
|
|
|
- borderColor: borderColor,
|
|
|
|
|
|
+ Container(
|
|
|
|
+ margin: widget.margin,
|
|
|
|
+ padding: widget.padding,
|
|
|
|
+ height: widget.height,
|
|
child: TextFormField(
|
|
child: TextFormField(
|
|
initialValue: widget.initialValue,
|
|
initialValue: widget.initialValue,
|
|
onChanged: (value) {
|
|
onChanged: (value) {
|
|
- widget._text = value;
|
|
|
|
|
|
+ inputText = value;
|
|
if (widget.onChanged != null) {
|
|
if (widget.onChanged != null) {
|
|
widget.onChanged!(value);
|
|
widget.onChanged!(value);
|
|
}
|
|
}
|
|
setState(() {});
|
|
setState(() {});
|
|
},
|
|
},
|
|
cursorColor: widget.cursorColor,
|
|
cursorColor: widget.cursorColor,
|
|
- obscureText: widget.enableObscure,
|
|
|
|
|
|
+ obscureText: obscuteText,
|
|
decoration: InputDecoration(
|
|
decoration: InputDecoration(
|
|
- icon: newIcon,
|
|
|
|
|
|
+ contentPadding: widget.contentPadding,
|
|
hintText: widget.hintText,
|
|
hintText: widget.hintText,
|
|
hintStyle: TextStyle(color: widget.normalBorderColor),
|
|
hintStyle: TextStyle(color: widget.normalBorderColor),
|
|
- border: InputBorder.none,
|
|
|
|
- suffixIcon: suffixIcon(),
|
|
|
|
|
|
+ border: OutlineInputBorder(
|
|
|
|
+ borderSide: BorderSide(
|
|
|
|
+ color: borderColor,
|
|
|
|
+ width: 1.0,
|
|
|
|
+ ),
|
|
|
|
+ borderRadius: Corners.s10Border,
|
|
|
|
+ ),
|
|
|
|
+ focusedBorder: OutlineInputBorder(
|
|
|
|
+ borderSide: BorderSide(
|
|
|
|
+ color: focusBorderColor,
|
|
|
|
+ width: 1.0,
|
|
|
|
+ ),
|
|
|
|
+ borderRadius: Corners.s10Border,
|
|
|
|
+ ),
|
|
|
|
+ suffixIcon: obscureIcon(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
@@ -100,39 +120,32 @@ class _RoundedInputFieldState extends State<RoundedInputField> {
|
|
return AnimatedSize(
|
|
return AnimatedSize(
|
|
duration: .4.seconds,
|
|
duration: .4.seconds,
|
|
curve: Curves.easeInOut,
|
|
curve: Curves.easeInOut,
|
|
- child: Column(
|
|
|
|
- children: children,
|
|
|
|
- ),
|
|
|
|
|
|
+ child: Column(children: children),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- Widget? suffixIcon() {
|
|
|
|
|
|
+ Widget? obscureIcon() {
|
|
if (widget.obscureText == false) {
|
|
if (widget.obscureText == false) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- if (widget._text.isEmpty) {
|
|
|
|
- return SizedBox.fromSize(size: const Size.square(16));
|
|
|
|
|
|
+ const double iconWidth = 16;
|
|
|
|
+ if (inputText.isEmpty) {
|
|
|
|
+ return SizedBox.fromSize(size: const Size.square(iconWidth));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ assert(widget.obscureIcon != null && widget.obscureHideIcon != null);
|
|
Widget? icon;
|
|
Widget? icon;
|
|
- if (widget.obscureText == true) {
|
|
|
|
- assert(widget.obscureIcon != null && widget.obscureHideIcon != null);
|
|
|
|
- if (widget.enableObscure) {
|
|
|
|
- icon = widget.obscureIcon!;
|
|
|
|
- } else {
|
|
|
|
- icon = widget.obscureHideIcon!;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (icon == null) {
|
|
|
|
- return null;
|
|
|
|
|
|
+ if (obscuteText) {
|
|
|
|
+ icon = widget.obscureIcon!;
|
|
|
|
+ } else {
|
|
|
|
+ icon = widget.obscureHideIcon!;
|
|
}
|
|
}
|
|
|
|
|
|
return RoundedImageButton(
|
|
return RoundedImageButton(
|
|
- size: 16,
|
|
|
|
|
|
+ size: iconWidth,
|
|
press: () {
|
|
press: () {
|
|
- widget.enableObscure = !widget.enableObscure;
|
|
|
|
|
|
+ obscuteText = !obscuteText;
|
|
setState(() {});
|
|
setState(() {});
|
|
},
|
|
},
|
|
child: icon,
|
|
child: icon,
|