country_provider.dart
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:shop_app/models/country.dart';
import '../utils.dart';
class CountryProvider with ChangeNotifier {
CountryProvider() {
loadCountries().then((countries) {
countries.forEach((element) {
_countries.add(Country(
phone: element.phone,
area: element.area,
population: element.population,
continent: element.continent,
currency: element.currency,
capital: element.capital,
name: element.name,
nativeName: element.nativeName,
code: element.code,
));
_countriesSorted.add(Country(
phone: element.phone,
area: element.area,
population: element.population,
continent: element.continent,
currency: element.currency,
capital: element.capital,
name: element.name,
nativeName: element.nativeName,
code: element.code,
));
});
notifyListeners();
});
}
List _countries = [];
List get countries => _countries;
List _countriesSorted = [];
List get countriesSorted => _countriesSorted;
Future> loadCountries() async {
final data = await rootBundle.loadString('assets/country_codes.json');
final countriesJson = json.decode(data);
return countriesJson.keys.map((code) {
final json = countriesJson[code];
final newJson = json..addAll({'code': code.toLowerCase()});
return Country.fromJson(newJson);
}).toList()
..sort(Utils.ascendingSort);
}
loadCountriesWithQuery(String query) {
_countriesSorted.clear();
_countries.forEach((element) {
_countriesSorted.add(Country(
phone: element.phone,
area: element.area,
population: element.population,
continent: element.continent,
currency: element.currency,
capital: element.capital,
name: element.name,
nativeName: element.nativeName,
code: element.code,
));
});
if (query.isNotEmpty)
_countriesSorted.removeWhere((element) =>
!element.name.toLowerCase().startsWith(query.toLowerCase()));
notifyListeners();
}
}
constants.dart
import 'package:flutter/material.dart';
import 'package:shop_app/size_config.dart';
const kPrimaryColor = Color(0xFFFF7643);
const kPrimaryLightColor = Color(0xFFFFECDF);
const kPrimaryGradientColor = LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFFFFA53E), Color(0xFFFF7643)],
);
const kSecondaryColor = Color(0xFF979797);
const kTextColor = Color(0xFF757575);
const kAnimationDuration = Duration(milliseconds: 200);
final headingStyle = TextStyle(
fontSize: getProportionateScreenWidth(28),
fontWeight: FontWeight.bold,
color: Colors.black,
height: 1.5,
);
const defaultDuration = Duration(milliseconds: 250);
final otpInputDecoration = InputDecoration(
contentPadding:
EdgeInsets.symmetric(vertical: getProportionateScreenWidth(15)),
border: outlineInputBorder(),
focusedBorder: outlineInputBorder(),
enabledBorder: outlineInputBorder(),
);
OutlineInputBorder outlineInputBorder() {
return OutlineInputBorder(
borderRadius: BorderRadius.circular(getProportionateScreenWidth(15)),
borderSide: BorderSide(color: kTextColor),
);
}
Do'stlaringiz bilan baham: |