Skip to content

Commit

Permalink
Merge pull request #150 from takenet/release/0.0.55
Browse files Browse the repository at this point in the history
New version
  • Loading branch information
githubdoandre authored May 23, 2023
2 parents 9de5e96 + fe33840 commit 5d9f336
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 3 additions & 0 deletions lib/src/models/ds_message_bubble_avatar_config.model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ class DSMessageBubbleAvatarConfig {
final Uri? sentAvatar;
final String? sentName;
final bool hideSentAvatar;
final bool hideReceivedAvatar;

const DSMessageBubbleAvatarConfig({
this.receivedAvatar,
this.receivedName,
this.sentAvatar,
this.sentName,
this.hideSentAvatar = false,
this.hideReceivedAvatar = false,
});

bool get showReceivedAvatar =>
!hideReceivedAvatar &&
(receivedAvatar != null || (receivedName?.isNotEmpty ?? false));
bool get showSentAvatar =>
!hideSentAvatar &&
Expand Down
38 changes: 28 additions & 10 deletions lib/src/widgets/fields/ds_phone_input.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
},
),
),
Expand All @@ -98,7 +116,7 @@ class DSPhoneInput extends StatelessWidget {
left: 8.0,
),
child: TextFormField(
controller: controller,
controller: widget.controller,
onChanged: (value) => updatePhoneMask(
phoneNumber: value,
),
Expand All @@ -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),
),
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/utils/ds_bottomsheet_countries.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class DSBottomSheetCountries {
static show() {
_filterCountries.assignAll(DSUtils.countriesList);
selectedCountry.value ??= _filterCountries.first;
_onClear();
return _bottomSheetCountries();
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 5d9f336

Please sign in to comment.