Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CountrySelectorNavigator does not respect the order of favorite countries #25

Open
Sikorrr opened this issue Dec 6, 2024 · 1 comment

Comments

@Sikorrr
Copy link

Sikorrr commented Dec 6, 2024

The CountrySelectorNavigator widget does not display the favorite countries in the specified order, even when sortCountries: false is set. According to the documentation, favorite countries should always appear in the order they are provided in the favorites parameter, regardless of the sortCountries setting. However, they are displayed in alphabetical order instead.

Reproduction Steps
The issue can be reproduced using the following minimal code:

import 'package:flutter/material.dart';
import 'package:phone_form_field/phone_form_field.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PhoneFormField(
        countrySelectorNavigator: const CountrySelectorNavigator.page(
          favorites: [IsoCode.FR, IsoCode.GB, IsoCode.DE],
          sortCountries: false,
        ),
        initialValue: const PhoneNumber(isoCode: IsoCode.GB, nsn: ''),
        decoration: const InputDecoration(labelText: 'Phone Number'),
      ),
    );
  }
}

Observed Behavior
When running the example above, the favorite countries are displayed in alphabetical order (FR, DE, GB) instead of the specified order (FR, GB, DE).

Expected Behavior
The favorite countries should appear in the exact order provided in the favorites parameter. In this case, the expected order is [FR, GB, DE].

Environment
Flutter Version: Flutter 3.24.5 • channel stable
phone_form_field Version: 10.0.2

@cedvdb cedvdb transferred this issue from cedvdb/phone_form_field Dec 6, 2024
@cedvdb
Copy link
Owner

cedvdb commented Dec 6, 2024

The sort function here https://github.com/cedvdb/flutter_country_selector/blob/main/lib/src/_country_selector_controller.dart#L64C1-L65C1 should be removed from the function and only applied to the country list

That is:

_countries = _buildLocalizedCountryList(context, countriesIsoCode)..sort((a, b) => computeSortScore(a) - computeSortScore(b));
_favoriteCountries =  _buildLocalizedCountryList(context, favoriteCountriesIsoCode);

Can you implement that change ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants