From c8891ac7a291388b017cb3ec529755af14a49def Mon Sep 17 00:00:00 2001 From: Andre Rossi Date: Tue, 23 May 2023 10:40:51 -0300 Subject: [PATCH 1/4] Some fixes --- .../widgets/fields/ds_phone_input.widget.dart | 38 ++++++++++++++----- .../ds_bottomsheet_countries.widget.dart | 1 + 2 files changed, 29 insertions(+), 10 deletions(-) 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 createState() => _DSPhoneInputState(); +} + +class _DSPhoneInputState extends State { + final _dropdownValue = Rx(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(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(); } From 1c4a0f47dbe2a2942ebca0bfcfacc494518554fd Mon Sep 17 00:00:00 2001 From: Paolla Lira Date: Tue, 23 May 2023 11:55:06 -0300 Subject: [PATCH 2/4] Parameters --- lib/src/models/ds_message_bubble_avatar_config.model.dart | 4 ++++ 1 file changed, 4 insertions(+) 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..2e3327b1 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,8 @@ class DSMessageBubbleAvatarConfig { final Uri? sentAvatar; final String? sentName; final bool hideSentAvatar; + final Uri? customerSentAvatar; + final String? customerSentName; const DSMessageBubbleAvatarConfig({ this.receivedAvatar, @@ -11,6 +13,8 @@ class DSMessageBubbleAvatarConfig { this.sentAvatar, this.sentName, this.hideSentAvatar = false, + this.customerSentAvatar, + this.customerSentName, }); bool get showReceivedAvatar => From 8d247229e648a2bd3cb3438869f908f7eecd4799 Mon Sep 17 00:00:00 2001 From: Paolla Lira Date: Tue, 23 May 2023 14:53:42 -0300 Subject: [PATCH 3/4] hideReceivedAvatar --- lib/src/models/ds_message_bubble_avatar_config.model.dart | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 2e3327b1..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,8 +4,7 @@ class DSMessageBubbleAvatarConfig { final Uri? sentAvatar; final String? sentName; final bool hideSentAvatar; - final Uri? customerSentAvatar; - final String? customerSentName; + final bool hideReceivedAvatar; const DSMessageBubbleAvatarConfig({ this.receivedAvatar, @@ -13,11 +12,11 @@ class DSMessageBubbleAvatarConfig { this.sentAvatar, this.sentName, this.hideSentAvatar = false, - this.customerSentAvatar, - this.customerSentName, + this.hideReceivedAvatar = false, }); bool get showReceivedAvatar => + !hideReceivedAvatar && (receivedAvatar != null || (receivedName?.isNotEmpty ?? false)); bool get showSentAvatar => !hideSentAvatar && From fe33840cb4dc791e09caa1bf6aedd9a7e15abdc8 Mon Sep 17 00:00:00 2001 From: Andre Rossi Date: Tue, 23 May 2023 15:14:49 -0300 Subject: [PATCH 4/4] New version --- CHANGELOG.md | 5 +++++ pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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/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