diff --git a/lib/vaahextendflutter/widgets/atoms/input_auto_complete.dart b/lib/vaahextendflutter/widgets/atoms/input_auto_complete.dart index 1890f265..40d242a5 100644 --- a/lib/vaahextendflutter/widgets/atoms/input_auto_complete.dart +++ b/lib/vaahextendflutter/widgets/atoms/input_auto_complete.dart @@ -10,8 +10,12 @@ class InputAutoComplete extends StatefulWidget { final EdgeInsets padding; final double borderRadius; final bool isEnabled; + final bool isBorderEnabled; final InputSize size; final double height; + final Color? optionsBackgroundColor; + final bool isShadowEnabled; + final IconData? icon; final Color? iconBackgroundColor; final Color? iconColor; final List hints; @@ -25,9 +29,13 @@ class InputAutoComplete extends StatefulWidget { required this.label, this.padding = allPadding12, this.borderRadius = defaultPadding / 2, + this.isBorderEnabled = true, this.isEnabled = true, this.size = InputSize.medium, this.height = 250, + this.optionsBackgroundColor, + this.isShadowEnabled = false, + this.icon, this.iconBackgroundColor, this.iconColor, required this.hints, @@ -43,6 +51,7 @@ class InputAutoComplete extends StatefulWidget { class _InputAutoCompleteState extends State { final controller = TextEditingController(); + bool _optionsAvailable = false; @override Widget build(BuildContext context) { @@ -50,11 +59,15 @@ class _InputAutoCompleteState extends State { builder: (ctx, constraints) { return Autocomplete( optionsBuilder: (TextEditingValue textEditingValue) { - return widget.hints + List hints = widget.hints .where( (String hint) => hint.toLowerCase().contains(textEditingValue.text.toLowerCase()), ) .toList(); + setState(() { + _optionsAvailable = hints.isNotEmpty && textEditingValue.text != hints.first; + }); + return hints; }, displayStringForOption: (String hint) => hint, onSelected: (String selection) { @@ -66,21 +79,47 @@ class _InputAutoCompleteState extends State { return Align( alignment: Alignment.topLeft, child: Material( - child: SizedBox( + child: Container( width: constraints.maxWidth, height: widget.height, + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(widget.borderRadius), + bottomRight: Radius.circular(widget.borderRadius), + ), + border: widget.isBorderEnabled + ? Border.all(color: AppTheme.colors['black']!.shade300) + : null, + boxShadow: !widget.isShadowEnabled + ? null + : const [ + BoxShadow( + color: Color(0x44000000), + offset: Offset(0, 1), + blurRadius: 8.0, + spreadRadius: 0.0, + ), + ], + color: widget.optionsBackgroundColor ?? AppTheme.colors['primary']!.shade50, + ), child: ListView.builder( padding: const EdgeInsets.all(10.0), itemCount: options.length, itemBuilder: (BuildContext context, int index) { final String option = options.elementAt(index); - return GestureDetector( - onTap: () { - onSelected(option); - }, - child: ListTile( - title: Text(option), - ), + return Column( + children: [ + GestureDetector( + onTap: () { + setState(() {}); + FocusScope.of(context).focusedChild?.unfocus(); + onSelected(option); + }, + child: ListTile( + title: Text(option), + ), + ), + ], ); }, ), @@ -96,6 +135,7 @@ class _InputAutoCompleteState extends State { ) { return TextFormField( onTap: () { + setState(() {}); if (fieldFocusNode.hasFocus) fieldFocusNode.unfocus(); }, decoration: InputDecoration( @@ -103,7 +143,18 @@ class _InputAutoCompleteState extends State { border: border(AppTheme.colors['black']!.shade400), enabledBorder: border(AppTheme.colors['black']!.shade400), disabledBorder: border(AppTheme.colors['black']!.shade300), - focusedBorder: border(AppTheme.colors['black']!.shade400), + focusedBorder: !_optionsAvailable + ? border(AppTheme.colors['black']!.shade400) + : OutlineInputBorder( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(widget.borderRadius), + topRight: Radius.circular(widget.borderRadius), + ), + borderSide: BorderSide( + width: 1, + color: AppTheme.colors['black']!.shade400, + ), + ), errorBorder: border(AppTheme.colors['danger']!.shade400), focusedErrorBorder: border(AppTheme.colors['danger']!.shade400), errorStyle: TextStyle(color: AppTheme.colors['danger']!.shade400), @@ -119,7 +170,9 @@ class _InputAutoCompleteState extends State { decoration: BoxDecoration( borderRadius: BorderRadius.only( topRight: Radius.circular(widget.borderRadius), - bottomRight: Radius.circular(widget.borderRadius), + bottomRight: fieldFocusNode.hasFocus && _optionsAvailable + ? Radius.zero + : Radius.circular(widget.borderRadius), ), color: widget.iconBackgroundColor ?? AppTheme.colors['primary'], ), @@ -127,7 +180,7 @@ class _InputAutoCompleteState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ FaIcon( - asset(), + widget.icon ?? FontAwesomeIcons.angleDown, size: getFontSize() * 1.3, color: widget.iconColor ?? AppTheme.colors['white'], ), @@ -177,8 +230,4 @@ class _InputAutoCompleteState extends State { return AppTheme.medium; } } - - IconData asset() { - return FontAwesomeIcons.angleDown; - } }