Refactored code
This commit is contained in:
parent
cc26ef085b
commit
991b52d07a
|
@ -139,20 +139,7 @@ class _TextInputWidgetState extends State<TextInputWidget> {
|
|||
borderSide: BorderSide(color: colorScheme.strokeFaint),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
suffixIcon: widget.cancellable
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
_textController.clear();
|
||||
if (widget.shouldUnfocusOnCancelOrSubmit) {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
Icons.cancel_rounded,
|
||||
color: colorScheme.strokeMuted,
|
||||
),
|
||||
)
|
||||
: Padding(
|
||||
suffixIcon: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 175),
|
||||
|
@ -165,6 +152,10 @@ class _TextInputWidgetState extends State<TextInputWidget> {
|
|||
widget.shouldSurfaceExecutionStates,
|
||||
obscureTextNotifier: _obscureTextNotifier,
|
||||
isPasswordInput: widget.isPasswordInput,
|
||||
textController: _textController,
|
||||
isCancellable: widget.cancellable,
|
||||
shouldUnfocusOnCancelOrSubmit:
|
||||
widget.shouldUnfocusOnCancelOrSubmit,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -319,13 +310,20 @@ class _TextInputWidgetState extends State<TextInputWidget> {
|
|||
class SuffixIconWidget extends StatelessWidget {
|
||||
final ExecutionState executionState;
|
||||
final bool shouldSurfaceExecutionStates;
|
||||
final TextEditingController textController;
|
||||
final ValueNotifier? obscureTextNotifier;
|
||||
final bool isPasswordInput;
|
||||
final bool isCancellable;
|
||||
final bool shouldUnfocusOnCancelOrSubmit;
|
||||
|
||||
const SuffixIconWidget({
|
||||
required this.executionState,
|
||||
required this.shouldSurfaceExecutionStates,
|
||||
required this.textController,
|
||||
this.obscureTextNotifier,
|
||||
this.isPasswordInput = false,
|
||||
this.isCancellable = false,
|
||||
this.shouldUnfocusOnCancelOrSubmit = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
@ -335,7 +333,20 @@ class SuffixIconWidget extends StatelessWidget {
|
|||
final colorScheme = getEnteColorScheme(context);
|
||||
if (executionState == ExecutionState.idle ||
|
||||
!shouldSurfaceExecutionStates) {
|
||||
if (isPasswordInput) {
|
||||
if (isCancellable) {
|
||||
trailingWidget = GestureDetector(
|
||||
onTap: () {
|
||||
textController.clear();
|
||||
if (shouldUnfocusOnCancelOrSubmit) {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
Icons.cancel_rounded,
|
||||
color: colorScheme.strokeMuted,
|
||||
),
|
||||
);
|
||||
} else if (isPasswordInput) {
|
||||
assert(obscureTextNotifier != null);
|
||||
trailingWidget = GestureDetector(
|
||||
onTap: () {
|
||||
|
|
Loading…
Reference in a new issue