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