diff --git a/CHANGELOG.md b/CHANGELOG.md index b7197e9a..dbcc86ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.0.55 + +- [DSPhoneInput] Somes adjustment +- [DSMessageBubbleAvatarConfig] Create hideReceivedAvatar param + ## 0.0.54 - [DSPhoneInput] Add country callback and text editing controller. diff --git a/lib/src/models/ds_message_bubble_avatar_config.model.dart b/lib/src/models/ds_message_bubble_avatar_config.model.dart index 1190dc9b..c4224ea7 100644 --- a/lib/src/models/ds_message_bubble_avatar_config.model.dart +++ b/lib/src/models/ds_message_bubble_avatar_config.model.dart @@ -4,6 +4,7 @@ class DSMessageBubbleAvatarConfig { final Uri? sentAvatar; final String? sentName; final bool hideSentAvatar; + final bool hideReceivedAvatar; const DSMessageBubbleAvatarConfig({ this.receivedAvatar, @@ -11,9 +12,11 @@ class DSMessageBubbleAvatarConfig { this.sentAvatar, this.sentName, this.hideSentAvatar = false, + this.hideReceivedAvatar = false, }); bool get showReceivedAvatar => + !hideReceivedAvatar && (receivedAvatar != null || (receivedName?.isNotEmpty ?? false)); bool get showSentAvatar => !hideSentAvatar && diff --git a/lib/src/widgets/fields/ds_phone_input.widget.dart b/lib/src/widgets/fields/ds_phone_input.widget.dart index 0c28c8a0..56a43bec 100644 --- a/lib/src/widgets/fields/ds_phone_input.widget.dart +++ b/lib/src/widgets/fields/ds_phone_input.widget.dart @@ -13,31 +13,43 @@ import '../buttons/ds_tertiary_button.widget.dart'; import '../texts/ds_body_text.widget.dart'; import '../utils/ds_bottomsheet_countries.widget.dart'; -class DSPhoneInput extends StatelessWidget { +class DSPhoneInput extends StatefulWidget { final String? hintText; final TextEditingController controller; final void Function(DSCountry)? onChangeCountry; - DSPhoneInput({ + const DSPhoneInput({ super.key, this.hintText, required this.controller, this.onChangeCountry, }); + @override + State<DSPhoneInput> createState() => _DSPhoneInputState(); +} + +class _DSPhoneInputState extends State<DSPhoneInput> { + final _dropdownValue = Rx<DSCountry>(DSUtils.countriesList.first); + // TODO: get masks considering selected country. static const _defaultMask = '#################'; static const _tenDigitsMask = '(##) ####-#####'; static const _elevenDigitsMask = '(##) #####-####'; static const _brazilCode = '+55'; - final _dropdownValue = Rx<DSCountry>(DSUtils.countriesList.first); - late final maskFormatter = MaskTextInputFormatter( mask: _tenDigitsMask, filter: {"#": RegExp(r'[0-9]')}, ); + @override + void initState() { + super.initState(); + DSBottomSheetCountries.selectedCountry.value = null; + widget.onChangeCountry?.call(_dropdownValue.value); + } + @override Widget build(BuildContext context) { return GestureDetector( @@ -76,13 +88,19 @@ class DSPhoneInput extends StatelessWidget { ), ), onPressed: () async { - _dropdownValue.value = await DSBottomSheetCountries.show(); + final result = await DSBottomSheetCountries.show(); + + if (result == null) { + return; + } + + _dropdownValue.value = result; updatePhoneMask( - phoneNumber: controller.text, + phoneNumber: widget.controller.text, ); - onChangeCountry?.call(_dropdownValue.value); + widget.onChangeCountry?.call(_dropdownValue.value); }, ), ), @@ -98,7 +116,7 @@ class DSPhoneInput extends StatelessWidget { left: 8.0, ), child: TextFormField( - controller: controller, + controller: widget.controller, onChanged: (value) => updatePhoneMask( phoneNumber: value, ), @@ -112,7 +130,7 @@ class DSPhoneInput extends StatelessWidget { cursorColor: DSColors.primaryMain, decoration: InputDecoration( border: InputBorder.none, - hintText: hintText ?? 'Número de telefone', + hintText: widget.hintText ?? 'Número de telefone', hintStyle: const DSBodyTextStyle( color: DSColors.neutralMediumWave), ), @@ -129,7 +147,7 @@ class DSPhoneInput extends StatelessWidget { void updatePhoneMask({ required String phoneNumber, }) => - controller.value = maskFormatter.updateMask( + widget.controller.value = maskFormatter.updateMask( mask: _dropdownValue.value.code != _brazilCode ? _defaultMask : phoneNumber.replaceAll(RegExp('[^0-9]'), '').length <= 10 diff --git a/lib/src/widgets/utils/ds_bottomsheet_countries.widget.dart b/lib/src/widgets/utils/ds_bottomsheet_countries.widget.dart index 935b121e..c30206d7 100644 --- a/lib/src/widgets/utils/ds_bottomsheet_countries.widget.dart +++ b/lib/src/widgets/utils/ds_bottomsheet_countries.widget.dart @@ -14,6 +14,7 @@ abstract class DSBottomSheetCountries { static show() { _filterCountries.assignAll(DSUtils.countriesList); selectedCountry.value ??= _filterCountries.first; + _onClear(); return _bottomSheetCountries(); } diff --git a/pubspec.yaml b/pubspec.yaml index 134e2c39..4274fa96 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: blip_ds description: Blip Design System for Flutter. -version: 0.0.54 +version: 0.0.55 homepage: https://github.com/takenet/blip-ds-flutter#readme repository: https://github.com/takenet/blip-ds-flutter