Implemented country registration handling in the API, allowing for dynamic country selection in the login and country selection screens. Added parsing logic for registration countries and updated the UI to reflect allowed countries based on the API response.

This commit is contained in:
klockky
2026-04-03 21:38:59 +03:00
parent 1caa8c1049
commit 7fefb71de6
4 changed files with 68 additions and 7 deletions
+14 -2
View File
@@ -33,9 +33,19 @@ class _LoginScreenState extends State<LoginScreen> {
void initState() {
super.initState();
_selectedCountry = countriesByCode['RU'] ?? allCountries.first;
_clampCountryToAllowed();
_checkTOS();
}
void _clampCountryToAllowed() {
final allowed = api.registrationCountries;
if (allowed.any((c) => c.code == _selectedCountry.code)) return;
_selectedCountry = allowed.firstWhere(
(c) => c.code == 'RU',
orElse: () => allowed.first,
);
}
@override
void dispose() {
_phoneErrorTimer?.cancel();
@@ -66,8 +76,10 @@ class _LoginScreenState extends State<LoginScreen> {
final result = await Navigator.push<CountryName>(
context,
MaterialPageRoute(
builder: (context) =>
SelectCountryScreen(selectedCountry: _selectedCountry),
builder: (context) => SelectCountryScreen(
selectedCountry: _selectedCountry,
countries: api.registrationCountries,
),
),
);
if (result != null) {
@@ -6,8 +6,13 @@ import 'package:komet/l10n/app_localizations.dart';
class SelectCountryScreen extends StatefulWidget {
final CountryName selectedCountry;
final List<CountryName> countries;
const SelectCountryScreen({super.key, required this.selectedCountry});
SelectCountryScreen({
super.key,
required this.selectedCountry,
List<CountryName>? countries,
}) : countries = countries ?? allCountries;
@override
State<SelectCountryScreen> createState() => _SelectCountryScreenState();
@@ -16,7 +21,13 @@ class SelectCountryScreen extends StatefulWidget {
class _SelectCountryScreenState extends State<SelectCountryScreen> {
bool _isSearching = false;
final TextEditingController _searchController = TextEditingController();
List<CountryName> _filteredCountries = allCountries;
late List<CountryName> _filteredCountries;
@override
void initState() {
super.initState();
_filteredCountries = widget.countries;
}
@override
void dispose() {
@@ -27,10 +38,10 @@ class _SelectCountryScreenState extends State<SelectCountryScreen> {
void _filterCountries(String query) {
setState(() {
if (query.isEmpty) {
_filteredCountries = allCountries;
_filteredCountries = widget.countries;
} else {
final q = query.toLowerCase();
_filteredCountries = allCountries.where((c) {
_filteredCountries = widget.countries.where((c) {
return c.ru.toLowerCase().contains(q) ||
c.en.toLowerCase().contains(q) ||
c.phoneCode.contains(q);
@@ -90,7 +101,7 @@ class _SelectCountryScreenState extends State<SelectCountryScreen> {
_isSearching = !_isSearching;
if (!_isSearching) {
_searchController.clear();
_filteredCountries = allCountries;
_filteredCountries = widget.countries;
}
});
},