mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-29 12:22:52 +03:00
173 lines
4.6 KiB
Dart
173 lines
4.6 KiB
Dart
/*
|
|
* Copyright (C) 2023 Yubico.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class AppInputDecoration extends InputDecoration {
|
|
final List<Widget>? suffixIcons;
|
|
|
|
const AppInputDecoration({
|
|
// allow multiple suffixIcons
|
|
this.suffixIcons,
|
|
// forward other TextField parameters
|
|
super.icon,
|
|
super.iconColor,
|
|
super.label,
|
|
super.labelText,
|
|
super.labelStyle,
|
|
super.floatingLabelStyle,
|
|
super.helperText,
|
|
super.helperStyle,
|
|
super.helperMaxLines,
|
|
super.hintText,
|
|
super.hintStyle,
|
|
super.hintTextDirection,
|
|
super.hintMaxLines,
|
|
super.hintFadeDuration,
|
|
super.error,
|
|
super.errorText,
|
|
super.errorStyle,
|
|
super.errorMaxLines,
|
|
super.floatingLabelBehavior,
|
|
super.floatingLabelAlignment,
|
|
super.isCollapsed,
|
|
super.isDense,
|
|
super.contentPadding,
|
|
super.prefixIcon,
|
|
super.prefixIconConstraints,
|
|
super.prefix,
|
|
super.prefixText,
|
|
super.prefixStyle,
|
|
super.prefixIconColor,
|
|
super.suffixIcon,
|
|
super.suffix,
|
|
super.suffixText,
|
|
super.suffixStyle,
|
|
super.suffixIconColor,
|
|
super.suffixIconConstraints,
|
|
super.counter,
|
|
super.counterText,
|
|
super.counterStyle,
|
|
super.filled,
|
|
super.fillColor,
|
|
super.focusColor,
|
|
super.hoverColor,
|
|
super.errorBorder,
|
|
super.focusedBorder,
|
|
super.focusedErrorBorder,
|
|
super.disabledBorder,
|
|
super.enabledBorder,
|
|
super.border,
|
|
super.enabled = true,
|
|
super.semanticCounterText,
|
|
super.alignLabelWithHint,
|
|
super.constraints,
|
|
}) : assert(!(suffixIcon != null && suffixIcons != null),
|
|
'Declaring both suffixIcon and suffixIcons is not supported.');
|
|
|
|
@override
|
|
Widget? get suffixIcon {
|
|
final hasError = errorText != null;
|
|
|
|
if (hasError || suffixIcons != null) {
|
|
final errorIcon = hasError ? const Icon(Icons.error_outlined) : null;
|
|
|
|
final existingSuffixIcon = super.suffixIcon;
|
|
|
|
return Wrap(
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: [
|
|
if (suffixIcons != null) ...suffixIcons!,
|
|
if (existingSuffixIcon != null) existingSuffixIcon,
|
|
if (errorIcon != null) ...[errorIcon, const SizedBox(width: 8.0)],
|
|
],
|
|
);
|
|
}
|
|
|
|
return super.suffixIcon;
|
|
}
|
|
}
|
|
|
|
/// TextField without autocorrect and suggestions
|
|
class AppTextField extends TextField {
|
|
const AppTextField({
|
|
// default settings to turn off autocorrect
|
|
super.autocorrect = false,
|
|
super.enableSuggestions = false,
|
|
super.keyboardType = TextInputType.text,
|
|
// forward other TextField parameters
|
|
super.key,
|
|
super.controller,
|
|
super.focusNode,
|
|
super.undoController,
|
|
AppInputDecoration? decoration,
|
|
super.textInputAction,
|
|
super.textCapitalization,
|
|
super.style,
|
|
super.strutStyle,
|
|
super.textAlign,
|
|
super.textAlignVertical,
|
|
super.textDirection,
|
|
super.readOnly,
|
|
super.toolbarOptions,
|
|
super.showCursor,
|
|
super.autofocus,
|
|
super.obscuringCharacter,
|
|
super.obscureText,
|
|
super.smartDashesType,
|
|
super.smartQuotesType,
|
|
super.maxLines,
|
|
super.minLines,
|
|
super.expands,
|
|
super.maxLength,
|
|
super.maxLengthEnforcement,
|
|
super.onChanged,
|
|
super.onEditingComplete,
|
|
super.onSubmitted,
|
|
super.onAppPrivateCommand,
|
|
super.inputFormatters,
|
|
super.enabled,
|
|
super.cursorWidth,
|
|
super.cursorHeight,
|
|
super.cursorRadius,
|
|
super.cursorOpacityAnimates,
|
|
super.cursorColor,
|
|
super.selectionHeightStyle,
|
|
super.selectionWidthStyle,
|
|
super.keyboardAppearance,
|
|
super.scrollPadding,
|
|
super.dragStartBehavior,
|
|
super.enableInteractiveSelection,
|
|
super.selectionControls,
|
|
super.onTap,
|
|
super.onTapOutside,
|
|
super.mouseCursor,
|
|
super.buildCounter,
|
|
super.scrollController,
|
|
super.scrollPhysics,
|
|
super.autofillHints,
|
|
super.contentInsertionConfiguration,
|
|
super.clipBehavior,
|
|
super.restorationId,
|
|
super.scribbleEnabled,
|
|
super.enableIMEPersonalizedLearning,
|
|
super.contextMenuBuilder,
|
|
super.canRequestFocus,
|
|
super.spellCheckConfiguration,
|
|
super.magnifierConfiguration,
|
|
}) : super(decoration: decoration);
|
|
}
|