Skip to content

Commit

Permalink
Merge pull request #147 from takenet/release/0.0.54
Browse files Browse the repository at this point in the history
Release/0.0.54
  • Loading branch information
githubdoandre authored May 19, 2023
2 parents 4b3b6fd + 086ac3b commit 9de5e96
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 46 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.54

- [DSPhoneInput] Add country callback and text editing controller.

## 0.0.53

- [DSPhoneInput] Add phone input widget with selectable country.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/services/ds_bottom_sheet.service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:blip_ds/blip_ds.dart';
import 'package:flutter/material.dart';

import '../themes/colors/ds_colors.theme.dart';

class DSBottomSheetService {
final BuildContext context;
final Widget Function(ScrollController?) builder;
Expand Down Expand Up @@ -29,7 +30,6 @@ class DSBottomSheetService {
Visibility(
visible: !hideGrabber,
replacement: Container(
height: 7.0,
decoration: _border(),
),
child: _grabber(),
Expand Down
13 changes: 9 additions & 4 deletions lib/src/widgets/fields/ds_phone_input.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ import '../utils/ds_bottomsheet_countries.widget.dart';

class DSPhoneInput extends StatelessWidget {
final String? hintText;
final TextEditingController controller;
final void Function(DSCountry)? onChangeCountry;

DSPhoneInput({
super.key,
this.hintText,
required this.controller,
this.onChangeCountry,
});

// TODO: get masks considering selected country.
Expand All @@ -28,7 +32,6 @@ class DSPhoneInput extends StatelessWidget {
static const _brazilCode = '+55';

final _dropdownValue = Rx<DSCountry>(DSUtils.countriesList.first);
final _inputController = TextEditingController();

late final maskFormatter = MaskTextInputFormatter(
mask: _tenDigitsMask,
Expand Down Expand Up @@ -76,8 +79,10 @@ class DSPhoneInput extends StatelessWidget {
_dropdownValue.value = await DSBottomSheetCountries.show();

updatePhoneMask(
phoneNumber: _inputController.text,
phoneNumber: controller.text,
);

onChangeCountry?.call(_dropdownValue.value);
},
),
),
Expand All @@ -93,7 +98,7 @@ class DSPhoneInput extends StatelessWidget {
left: 8.0,
),
child: TextFormField(
controller: _inputController,
controller: controller,
onChanged: (value) => updatePhoneMask(
phoneNumber: value,
),
Expand Down Expand Up @@ -124,7 +129,7 @@ class DSPhoneInput extends StatelessWidget {
void updatePhoneMask({
required String phoneNumber,
}) =>
_inputController.value = maskFormatter.updateMask(
controller.value = maskFormatter.updateMask(
mask: _dropdownValue.value.code != _brazilCode
? _defaultMask
: phoneNumber.replaceAll(RegExp('[^0-9]'), '').length <= 10
Expand Down
73 changes: 37 additions & 36 deletions lib/src/widgets/utils/ds_bottomsheet_countries.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:get/get.dart';

import '../../../blip_ds.dart';
import '../../models/ds_country.model.dart';
import '../fields/ds_search_input.widget.dart';

abstract class DSBottomSheetCountries {
static final showClearButton = RxBool(false);
Expand Down Expand Up @@ -87,43 +86,45 @@ abstract class DSBottomSheetCountries {
}

static Widget _builderCountries() {
return Obx(
() => ListView.builder(
itemBuilder: (_, index) {
final country = _filterCountries[index];
return Obx(
() => Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: Column(
children: [
DSRadioTile<DSCountry>(
value: country,
onChanged: (value) {
selectedCountry.value = value!;
Get.back(result: selectedCountry.value);
},
title: Row(
children: [
SvgPicture.asset(
'assets/svg/flags/${country.flag}.svg',
width: 22.0,
package: DSUtils.packageName,
),
DSBodyText(' ${country.name} '),
DSBodyText(country.code),
],
return SafeArea(
child: Obx(
() => ListView.builder(
itemBuilder: (_, index) {
final country = _filterCountries[index];
return Obx(
() => Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: Column(
children: [
DSRadioTile<DSCountry>(
value: country,
onChanged: (value) {
selectedCountry.value = value!;
Get.back(result: selectedCountry.value);
},
title: Row(
children: [
SvgPicture.asset(
'assets/svg/flags/${country.flag}.svg',
width: 22.0,
package: DSUtils.packageName,
),
DSBodyText(' ${country.name} '),
DSBodyText(country.code),
],
),
groupValue: selectedCountry.value,
),
groupValue: selectedCountry.value,
),
const DSDivider(),
],
const DSDivider(),
],
),
),
),
);
},
itemCount: _filterCountries.length,
);
},
itemCount: _filterCountries.length,
),
),
);
}
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.53
version: 0.0.54
homepage: https://github.com/takenet/blip-ds-flutter#readme
repository: https://github.com/takenet/blip-ds-flutter

Expand Down
2 changes: 1 addition & 1 deletion sample/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class HomePage extends StatelessWidget {
const Divider(color: DSColors.neutralDarkCity),
const SampleWeblinkShowcase(),
const Divider(color: DSColors.neutralDarkCity),
const SampleInputShowcase(),
SampleInputShowcase(),
],
),
),
Expand Down
10 changes: 8 additions & 2 deletions sample/lib/widgets/showcase/sample_input.showcase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import 'package:blip_ds/blip_ds.dart';
import 'package:flutter/material.dart';

class SampleInputShowcase extends StatelessWidget {
const SampleInputShowcase({super.key});
SampleInputShowcase({super.key});

final controller = TextEditingController();

@override
Widget build(BuildContext context) {
Expand All @@ -13,7 +15,11 @@ class SampleInputShowcase extends StatelessWidget {
child: Wrap(
runSpacing: 8.0,
children: [
DSPhoneInput(),
DSPhoneInput(
controller: controller,
// ignore: avoid_print
onChangeCountry: (country) => print(country.code),
),
DSSearchInput(
onClear: () {},
onSearch: (_) {},
Expand Down

0 comments on commit 9de5e96

Please sign in to comment.