Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ PODS:
- PromisesSwift (2.4.0):
- PromisesObjC (= 2.4.0)
- RecaptchaInterop (101.0.0)
- SDWebImage (5.21.5):
- SDWebImage/Core (= 5.21.5)
- SDWebImage/Core (5.21.5)
- SDWebImage (5.21.7):
- SDWebImage/Core (= 5.21.7)
- SDWebImage/Core (5.21.7)
- share_plus (0.0.1):
- Flutter
- shared_preferences_foundation (0.0.1):
Expand All @@ -264,9 +264,9 @@ PODS:
- Flutter
- FlutterMacOS
- SwiftCBOR (0.4.4)
- SwiftProtobuf (1.33.3)
- SwiftProtobuf (1.36.1)
- SwiftyGif (5.4.5)
- TwilioVoice (6.13.5)
- TwilioVoice (6.13.6)
- url_launcher_ios (0.0.1):
- Flutter
- video_player_avfoundation (0.0.1):
Expand Down Expand Up @@ -530,15 +530,15 @@ SPEC CHECKSUMS:
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
PromisesSwift: 9d77319bbe72ebf6d872900551f7eeba9bce2851
RecaptchaInterop: 11e0b637842dfb48308d242afc3f448062325aba
SDWebImage: e9c98383c7572d713c1a0d7dd2783b10599b9838
SDWebImage: e9fc87c1aab89a8ab1bbd74eba378c6f53be8abf
share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
sign_in_with_apple: c5dcc141574c8c54d5ac99dd2163c0c72ad22418
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
SwiftCBOR: ce5354ec8b660da2d6fc754462881119dbe1f963
SwiftProtobuf: e1b437c8e31a4c5577b643249a0bb62ed4f02153
SwiftProtobuf: 9e106a71456f4d3f6a3b0c8fd87ef0be085efc38
SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4
TwilioVoice: 237d012c91fc149943589628703dfd6c7cb2eb31
TwilioVoice: 04e059fd28d95423b971e823b1c1c1d6737e4e1b
url_launcher_ios: 7a95fa5b60cc718a708b8f2966718e93db0cef1b
video_player_avfoundation: dd410b52df6d2466a42d28550e33e4146928280a
webview_flutter_wkwebview: 8ebf4fded22593026f7dbff1fbff31ea98573c8d
Expand Down
5 changes: 3 additions & 2 deletions app/lib/pages/phone_calls/phone_calls_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:intl_phone_field/countries.dart';
import 'package:intl_country_data/intl_country_data.dart';
import 'package:provider/provider.dart';

import 'package:omi/pages/phone_calls/active_call_page.dart';
Expand Down Expand Up @@ -398,11 +398,12 @@ class _PhoneCallsPageState extends State<PhoneCallsPage> with SingleTickerProvid
String? _extractCountryCode(String e164Number) {
if (!e164Number.startsWith('+')) return null;
var digits = e164Number.substring(1); // strip '+'
var allCountries = IntlCountryData.all();
// Try longest match first (country codes are 1-3 digits)
for (var len = 3; len >= 1; len--) {
if (digits.length <= len) continue;
var candidate = digits.substring(0, len);
if (countries.any((c) => c.fullCountryCode == candidate)) {
if (allCountries.any((c) => c.telephoneCode == candidate)) {
return '+$candidate';
}
}
Comment on lines 403 to 409
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 IntlCountryData.all() called on every loop iteration

IntlCountryData.all() is invoked up to 3 times inside the loop (once per iteration when len is 3, 2, and 1). If all() allocates a new list each call, this creates unnecessary allocations on every invocation of _extractCountryCode. Cache the result before the loop:

Suggested change
for (var len = 3; len >= 1; len--) {
if (digits.length <= len) continue;
var candidate = digits.substring(0, len);
if (countries.any((c) => c.fullCountryCode == candidate)) {
if (IntlCountryData.all().any((c) => c.telephoneCode == candidate)) {
return '+$candidate';
}
}
String? _extractCountryCode(String e164Number) {
if (!e164Number.startsWith('+')) return null;
var digits = e164Number.substring(1); // strip '+'
final allCountries = IntlCountryData.all();
// Try longest match first (country codes are 1-3 digits)
for (var len = 3; len >= 1; len--) {
if (digits.length <= len) continue;
var candidate = digits.substring(0, len);
if (allCountries.any((c) => c.telephoneCode == candidate)) {
return '+$candidate';
}
}
return null;
}

Expand Down
27 changes: 15 additions & 12 deletions app/lib/pages/phone_calls/phone_setup_number_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intl_phone_field/countries.dart';
import 'package:intl_country_data/intl_country_data.dart';
import 'package:provider/provider.dart';

import 'package:omi/pages/phone_calls/phone_setup_verify_page.dart';
Expand All @@ -17,7 +17,7 @@ class PhoneSetupNumberPage extends StatefulWidget {
class _PhoneSetupNumberPageState extends State<PhoneSetupNumberPage> {
final TextEditingController _phoneController = TextEditingController();
final FocusNode _phoneFocus = FocusNode();
Country _selectedCountry = countries.firstWhere((c) => c.code == 'US');
IntlCountryData _selectedCountry = IntlCountryData.fromCountryCodeAlpha2('US');
bool _isLoading = false;
String? _errorMessage;

Expand All @@ -38,12 +38,12 @@ class _PhoneSetupNumberPageState extends State<PhoneSetupNumberPage> {

bool get _isValid {
var digits = _phoneController.text.replaceAll(RegExp(r'\D'), '');
return digits.length >= _selectedCountry.minLength && digits.length <= _selectedCountry.maxLength;
return digits.length >= _selectedCountry.telephoneMinLength && digits.length <= _selectedCountry.telephoneMaxLength;
}

String get _fullNumber {
var digits = _phoneController.text.replaceAll(RegExp(r'\D'), '');
return '+${_selectedCountry.fullCountryCode}$digits';
return '+${_selectedCountry.telephoneCode}$digits';
}

void _showCountryPicker() {
Expand Down Expand Up @@ -146,7 +146,7 @@ class _PhoneSetupNumberPageState extends State<PhoneSetupNumberPage> {
Text(_selectedCountry.flag, style: const TextStyle(fontSize: 22)),
const SizedBox(width: 6),
Text(
'+${_selectedCountry.fullCountryCode}',
'+${_selectedCountry.telephoneCode}',
style: const TextStyle(color: Colors.white, fontSize: 16),
),
const SizedBox(width: 4),
Expand Down Expand Up @@ -225,8 +225,8 @@ class _PhoneSetupNumberPageState extends State<PhoneSetupNumberPage> {
}

class _CountryPickerSheet extends StatefulWidget {
final Country selected;
final ValueChanged<Country> onSelect;
final IntlCountryData selected;
final ValueChanged<IntlCountryData> onSelect;

const _CountryPickerSheet({required this.selected, required this.onSelect});

Expand All @@ -236,13 +236,16 @@ class _CountryPickerSheet extends StatefulWidget {

class _CountryPickerSheetState extends State<_CountryPickerSheet> {
final TextEditingController _searchController = TextEditingController();
List<Country> _filtered = countries;
final List<IntlCountryData> _allCountries = IntlCountryData.all();
List<IntlCountryData> _filtered = IntlCountryData.all();

void _filter(String query) {
var q = query.toLowerCase();
setState(() {
_filtered = countries.where((c) {
return c.name.toLowerCase().contains(q) || c.dialCode.contains(q) || c.code.toLowerCase().contains(q);
_filtered = _allCountries.where((c) {
return c.name.toLowerCase().contains(q) ||
c.telephoneCode.contains(q) ||
c.codeAlpha2.toLowerCase().contains(q);
}).toList();
});
}
Expand Down Expand Up @@ -293,7 +296,7 @@ class _CountryPickerSheetState extends State<_CountryPickerSheet> {
itemCount: _filtered.length,
itemBuilder: (_, i) {
var c = _filtered[i];
var isSelected = c.code == widget.selected.code;
var isSelected = c.codeAlpha2 == widget.selected.codeAlpha2;
return GestureDetector(
onTap: () => widget.onSelect(c),
child: Container(
Expand All @@ -314,7 +317,7 @@ class _CountryPickerSheetState extends State<_CountryPickerSheet> {
overflow: TextOverflow.ellipsis,
),
),
Text('+${c.fullCountryCode}', style: TextStyle(fontSize: 14, color: Colors.grey[500])),
Text('+${c.telephoneCode}', style: TextStyle(fontSize: 14, color: Colors.grey[500])),
],
),
),
Expand Down
28 changes: 14 additions & 14 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev"
source: hosted
version: "1.4.1"
version: "1.4.0"
checked_yaml:
dependency: transitive
description:
Expand Down Expand Up @@ -1285,14 +1285,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.20.2"
intl_phone_field:
intl_country_data:
dependency: "direct main"
description:
name: intl_phone_field
sha256: "73819d3dfcb68d2c85663606f6842597c3ddf6688ac777f051b17814fe767bbf"
name: intl_country_data
sha256: "6f67014fab815ecdd312113d68f90998d8e91f861bc6282f0e540cf1229248a3"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "1.2.9"
io:
dependency: transitive
description:
Expand Down Expand Up @@ -1457,18 +1457,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.dev"
source: hosted
version: "0.12.18"
version: "0.12.17"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.13.0"
version: "0.11.1"
mcumgr_flutter:
dependency: "direct main"
description:
Expand All @@ -1481,10 +1481,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.16.0"
mgrs_dart:
dependency: transitive
description:
Expand Down Expand Up @@ -2219,10 +2219,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "19a78f63e83d3a61f00826d09bc2f60e191bf3504183c001262be6ac75589fb8"
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
url: "https://pub.dev"
source: hosted
version: "0.7.8"
version: "0.7.6"
time:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ dependencies:
intl: 0.20.2
permission_handler: ^12.0.0+1
flutter_contacts: ^1.1.9+2
intl_phone_field: ^3.2.0
intl_country_data: ^1.2.9
share_plus: 11.0.0
shared_preferences: 2.5.3
url_launcher: ^6.3.0
Expand Down
Loading