lab7
This commit is contained in:
parent
5b6082e6eb
commit
5be65da2df
151
lib/components/locale/l10n/app_locale.dart
Normal file
151
lib/components/locale/l10n/app_locale.dart
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
|
||||||
|
import 'app_locale_en.dart';
|
||||||
|
import 'app_locale_ru.dart';
|
||||||
|
|
||||||
|
/// Callers can lookup localized strings with an instance of AppLocale
|
||||||
|
/// returned by `AppLocale.of(context)`.
|
||||||
|
///
|
||||||
|
/// Applications need to include `AppLocale.delegate()` in their app's
|
||||||
|
/// `localizationDelegates` list, and the locales they support in the app's
|
||||||
|
/// `supportedLocales` list. For example:
|
||||||
|
///
|
||||||
|
/// ```dart
|
||||||
|
/// import 'l10n/app_locale.dart';
|
||||||
|
///
|
||||||
|
/// return MaterialApp(
|
||||||
|
/// localizationsDelegates: AppLocale.localizationsDelegates,
|
||||||
|
/// supportedLocales: AppLocale.supportedLocales,
|
||||||
|
/// home: MyApplicationHome(),
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## Update pubspec.yaml
|
||||||
|
///
|
||||||
|
/// Please make sure to update your pubspec.yaml to include the following
|
||||||
|
/// packages:
|
||||||
|
///
|
||||||
|
/// ```yaml
|
||||||
|
/// dependencies:
|
||||||
|
/// # Internationalization support.
|
||||||
|
/// flutter_localizations:
|
||||||
|
/// sdk: flutter
|
||||||
|
/// intl: any # Use the pinned version from flutter_localizations
|
||||||
|
///
|
||||||
|
/// # Rest of dependencies
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## iOS Applications
|
||||||
|
///
|
||||||
|
/// iOS applications define key application metadata, including supported
|
||||||
|
/// locales, in an Info.plist file that is built into the application bundle.
|
||||||
|
/// To configure the locales supported by your app, you’ll need to edit this
|
||||||
|
/// file.
|
||||||
|
///
|
||||||
|
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
|
||||||
|
/// Then, in the Project Navigator, open the Info.plist file under the Runner
|
||||||
|
/// project’s Runner folder.
|
||||||
|
///
|
||||||
|
/// Next, select the Information Property List item, select Add Item from the
|
||||||
|
/// Editor menu, then select Localizations from the pop-up menu.
|
||||||
|
///
|
||||||
|
/// Select and expand the newly-created Localizations item then, for each
|
||||||
|
/// locale your application supports, add a new item and select the locale
|
||||||
|
/// you wish to add from the pop-up menu in the Value field. This list should
|
||||||
|
/// be consistent with the languages listed in the AppLocale.supportedLocales
|
||||||
|
/// property.
|
||||||
|
abstract class AppLocale {
|
||||||
|
AppLocale(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
||||||
|
|
||||||
|
final String localeName;
|
||||||
|
|
||||||
|
static AppLocale? of(BuildContext context) {
|
||||||
|
return Localizations.of<AppLocale>(context, AppLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const LocalizationsDelegate<AppLocale> delegate = _AppLocaleDelegate();
|
||||||
|
|
||||||
|
/// A list of this localizations delegate along with the default localizations
|
||||||
|
/// delegates.
|
||||||
|
///
|
||||||
|
/// Returns a list of localizations delegates containing this delegate along with
|
||||||
|
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
|
||||||
|
/// and GlobalWidgetsLocalizations.delegate.
|
||||||
|
///
|
||||||
|
/// Additional delegates can be added by appending to this list in
|
||||||
|
/// MaterialApp. This list does not have to be used at all if a custom list
|
||||||
|
/// of delegates is preferred or required.
|
||||||
|
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
|
||||||
|
delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
];
|
||||||
|
|
||||||
|
/// A list of this localizations delegate's supported locales.
|
||||||
|
static const List<Locale> supportedLocales = <Locale>[
|
||||||
|
Locale('en'),
|
||||||
|
Locale('ru')
|
||||||
|
];
|
||||||
|
|
||||||
|
/// No description provided for @search.
|
||||||
|
///
|
||||||
|
/// In ru, this message translates to:
|
||||||
|
/// **'Поиск'**
|
||||||
|
String get search;
|
||||||
|
|
||||||
|
/// No description provided for @liked.
|
||||||
|
///
|
||||||
|
/// In ru, this message translates to:
|
||||||
|
/// **'понравился!'**
|
||||||
|
String get liked;
|
||||||
|
|
||||||
|
/// No description provided for @disliked.
|
||||||
|
///
|
||||||
|
/// In ru, this message translates to:
|
||||||
|
/// **'разонравился'**
|
||||||
|
String get disliked;
|
||||||
|
|
||||||
|
/// No description provided for @arbEnding.
|
||||||
|
///
|
||||||
|
/// In ru, this message translates to:
|
||||||
|
/// **'Чтобы не забыть про отсутствие запятой :)'**
|
||||||
|
String get arbEnding;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AppLocaleDelegate extends LocalizationsDelegate<AppLocale> {
|
||||||
|
const _AppLocaleDelegate();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AppLocale> load(Locale locale) {
|
||||||
|
return SynchronousFuture<AppLocale>(lookupAppLocale(locale));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool isSupported(Locale locale) => <String>['en', 'ru'].contains(locale.languageCode);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldReload(_AppLocaleDelegate old) => false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppLocale lookupAppLocale(Locale locale) {
|
||||||
|
|
||||||
|
|
||||||
|
// Lookup logic when only language code is specified.
|
||||||
|
switch (locale.languageCode) {
|
||||||
|
case 'en': return AppLocaleEn();
|
||||||
|
case 'ru': return AppLocaleRu();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw FlutterError(
|
||||||
|
'AppLocale.delegate failed to load unsupported locale "$locale". This is likely '
|
||||||
|
'an issue with the localizations generation tool. Please file an issue '
|
||||||
|
'on GitHub with a reproducible sample app and the gen-l10n configuration '
|
||||||
|
'that was used.'
|
||||||
|
);
|
||||||
|
}
|
18
lib/components/locale/l10n/app_locale_en.dart
Normal file
18
lib/components/locale/l10n/app_locale_en.dart
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import 'app_locale.dart';
|
||||||
|
|
||||||
|
/// The translations for English (`en`).
|
||||||
|
class AppLocaleEn extends AppLocale {
|
||||||
|
AppLocaleEn([String locale = 'en']) : super(locale);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get search => 'Search';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get liked => 'liked!';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get disliked => 'disliked';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';
|
||||||
|
}
|
18
lib/components/locale/l10n/app_locale_ru.dart
Normal file
18
lib/components/locale/l10n/app_locale_ru.dart
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import 'app_locale.dart';
|
||||||
|
|
||||||
|
/// The translations for Russian (`ru`).
|
||||||
|
class AppLocaleRu extends AppLocale {
|
||||||
|
AppLocaleRu([String locale = 'ru']) : super(locale);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get search => 'Поиск';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get liked => 'понравился!';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get disliked => 'разонравился';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
class Debounce { //помощник
|
|
||||||
factory Debounce() => _instance; //обращение через статический конструктор
|
|
||||||
|
|
||||||
Debounce._();
|
|
||||||
|
|
||||||
static final Debounce _instance = Debounce._();
|
|
||||||
|
|
||||||
static Timer? _timer;
|
|
||||||
|
|
||||||
static void run(//создаём задержку для ввода пользователя в поисковую строку
|
|
||||||
VoidCallback action, {
|
|
||||||
Duration delay = const Duration(milliseconds: 500),
|
|
||||||
}) {
|
|
||||||
_timer?.cancel();
|
|
||||||
_timer = Timer(delay, action);
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,13 +12,15 @@ class WeaponsDto {
|
|||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
class WeaponDto {
|
class WeaponDto {
|
||||||
|
final String? uuid;
|
||||||
final String? displayName;
|
final String? displayName;
|
||||||
final String? displayIcon;
|
final String? displayIcon;
|
||||||
final String? category;
|
final String? category;
|
||||||
final int? magazineSize;
|
final int? magazineSize;
|
||||||
final int? cost;
|
final int? cost;
|
||||||
|
|
||||||
const WeaponDto({this.displayName, this.displayIcon, this.category, this.magazineSize, this.cost});
|
const WeaponDto(
|
||||||
|
{this.uuid, this.displayName, this.displayIcon, this.category, this.magazineSize, this.cost});
|
||||||
|
|
||||||
factory WeaponDto.fromJson(Map<String, dynamic> json) => _$WeaponDtoFromJson(json);
|
factory WeaponDto.fromJson(Map<String, dynamic> json) => _$WeaponDtoFromJson(json);
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,7 @@ part of 'weapons_dto.dart';
|
|||||||
// JsonSerializableGenerator
|
// JsonSerializableGenerator
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
WeaponsDto _$WeaponsDtoFromJson(Map<String, dynamic> json) =>
|
WeaponsDto _$WeaponsDtoFromJson(Map<String, dynamic> json) => WeaponsDto(
|
||||||
WeaponsDto(
|
|
||||||
data: (json['data'] as List<dynamic>?)
|
data: (json['data'] as List<dynamic>?)
|
||||||
?.map((e) => WeaponDto.fromJson(e as Map<String, dynamic>))
|
?.map((e) => WeaponDto.fromJson(e as Map<String, dynamic>))
|
||||||
.toList(),
|
.toList(),
|
||||||
@ -17,10 +16,11 @@ WeaponDto _$WeaponDtoFromJson(Map<String, dynamic> json) {
|
|||||||
var weaponStats = json['weaponStats'] as Map<String, dynamic>?;
|
var weaponStats = json['weaponStats'] as Map<String, dynamic>?;
|
||||||
var shopData = json['shopData'] as Map<String, dynamic>?;
|
var shopData = json['shopData'] as Map<String, dynamic>?;
|
||||||
return WeaponDto(
|
return WeaponDto(
|
||||||
|
uuid: json['uuid'] as String?,
|
||||||
displayName: json['displayName'] as String?,
|
displayName: json['displayName'] as String?,
|
||||||
displayIcon: json['displayIcon'] as String?,
|
displayIcon: json['displayIcon'] as String?,
|
||||||
category: shopData?['category'] as String?,
|
category: shopData?['category'] as String?,
|
||||||
magazineSize: weaponStats?['magazineSize'] as int?,
|
magazineSize: weaponStats?['magazineSize'] as int?,
|
||||||
cost: shopData?['cost'] as int?,
|
cost: shopData?['cost'] as int?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@ import '../dtos/weapons_dto.dart';
|
|||||||
|
|
||||||
extension WeaponDtoToModel on WeaponDto {
|
extension WeaponDtoToModel on WeaponDto {
|
||||||
CardData toDomain() => CardData(
|
CardData toDomain() => CardData(
|
||||||
displayName ?? 'UNKNOWN',
|
displayName ?? 'UNKNOWN',
|
||||||
categoryText: category ?? 'Описание отсутствует',
|
uuid: uuid ?? 'UNKNOWN',
|
||||||
gameDesc: magazineSize,
|
categoryText: category ?? 'Описание отсутствует',
|
||||||
gameDesc2: cost,
|
gameDesc: magazineSize,
|
||||||
imageUrl: displayIcon,
|
gameDesc2: cost,
|
||||||
);
|
imageUrl: displayIcon,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
|
|
||||||
import '../../domain/models/card.dart';
|
import '../../domain/models/card.dart';
|
||||||
|
|
||||||
typedef OnErrorCallback = void Function(String? error);
|
typedef OnErrorCallback = void Function(String? error);
|
||||||
|
|
||||||
abstract class ApiInterface{
|
abstract class ApiInterface {
|
||||||
Future<List<CardData>?> loadData();
|
Future<List<CardData>?> loadData();
|
||||||
}
|
}
|
||||||
|
@ -1,75 +1,72 @@
|
|||||||
|
|
||||||
import '../../domain/models/card.dart';
|
import '../../domain/models/card.dart';
|
||||||
import 'api_interface.dart';
|
import 'api_interface.dart';
|
||||||
|
|
||||||
class MockRepository extends ApiInterface {
|
class MockRepository extends ApiInterface {
|
||||||
@override
|
@override
|
||||||
Future<List<CardData>?> loadData() async{
|
Future<List<CardData>?> loadData() async {
|
||||||
return [
|
return [
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '1',
|
||||||
'Мама с сыном',
|
'Мама с сыном',
|
||||||
categoryText: '-Чё вылупился?',
|
categoryText: '-Чё вылупился?',
|
||||||
imageUrl:
|
imageUrl: 'https://pic.rutubelist.ru/video/8b/31/8b31b4f162bf11007c036be6787e9bb1.jpg',
|
||||||
'https://pic.rutubelist.ru/video/8b/31/8b31b4f162bf11007c036be6787e9bb1.jpg',
|
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '2',
|
||||||
'Ярускин Салих',
|
'Ярускин Салих',
|
||||||
categoryText: 'я мусор',
|
categoryText: 'я мусор',
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://steamuserimages-a.akamaihd.net/ugc/2030615098399987630/EB9690C3D097504388EA8F057E48631354C05182/?imw=512&&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=false',
|
'https://steamuserimages-a.akamaihd.net/ugc/2030615098399987630/EB9690C3D097504388EA8F057E48631354C05182/?imw=512&&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=false',
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '3',
|
||||||
'Гламурная бабизяна',
|
'Гламурная бабизяна',
|
||||||
categoryText: 'сделала губки 5мл',
|
categoryText: 'сделала губки 5мл',
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://avatars.dzeninfra.ru/get-zen_doc/3310860/pub_602156c24849a6360821ff59_60215909390eb32b9bb9e012/scale_1200',
|
'https://avatars.dzeninfra.ru/get-zen_doc/3310860/pub_602156c24849a6360821ff59_60215909390eb32b9bb9e012/scale_1200',
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '4',
|
||||||
'Мелкий',
|
'Мелкий',
|
||||||
categoryText: 'невдупленыш',
|
categoryText: 'невдупленыш',
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://sun9-59.userapi.com/impg/DBnGgdqZnRtBw9jchGixY6rRN-zTWaAEVjLxXw/HrYCralVB-4.jpg?size=807x577&quality=96&sign=a84b4d87249b7d5ade53369663a3a9e0&c_uniq_tag=2XoQqW9aaCVDnvITURMqqPPY9yznsdCr4HWXaSv9Q_U&type=album',
|
'https://sun9-59.userapi.com/impg/DBnGgdqZnRtBw9jchGixY6rRN-zTWaAEVjLxXw/HrYCralVB-4.jpg?size=807x577&quality=96&sign=a84b4d87249b7d5ade53369663a3a9e0&c_uniq_tag=2XoQqW9aaCVDnvITURMqqPPY9yznsdCr4HWXaSv9Q_U&type=album',
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '5',
|
||||||
'Обезьянка Олежа',
|
'Обезьянка Олежа',
|
||||||
categoryText: 'Поняла смысл жизни...',
|
categoryText: 'Поняла смысл жизни...',
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://avatars.yandex.net/get-music-content/5417945/f468314f.a.20066160-1/m1000x1000?webp=false',
|
'https://avatars.yandex.net/get-music-content/5417945/f468314f.a.20066160-1/m1000x1000?webp=false',
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '6',
|
||||||
'Афанасьев Степан',
|
'Афанасьев Степан',
|
||||||
categoryText: 'основатель ЧВК Мартышки',
|
categoryText: 'основатель ЧВК Мартышки',
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://steamuserimages-a.akamaihd.net/ugc/1621850006938404146/EA72DC3C31DED440C024F0DD1D9859C44B1BBDFF/?imw=512&&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=false',
|
'https://steamuserimages-a.akamaihd.net/ugc/1621850006938404146/EA72DC3C31DED440C024F0DD1D9859C44B1BBDFF/?imw=512&&ima=fit&impolicy=Letterbox&imcolor=%23000000&letterbox=false',
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '7',
|
||||||
'Лобашов Иван',
|
'Лобашов Иван',
|
||||||
categoryText: 'вычисляет противников',
|
categoryText: 'вычисляет противников',
|
||||||
imageUrl:
|
imageUrl: 'https://cdn1.ozone.ru/s3/multimedia-i/6449406306.jpg',
|
||||||
'https://cdn1.ozone.ru/s3/multimedia-i/6449406306.jpg',
|
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
CardData(
|
CardData(
|
||||||
|
uuid: '8',
|
||||||
'Коренной представитель ЧВК Мартышки',
|
'Коренной представитель ЧВК Мартышки',
|
||||||
categoryText: 'сейчас он где-то в Камеруне проветривает свои блохи',
|
categoryText: 'сейчас он где-то в Камеруне проветривает свои блохи',
|
||||||
imageUrl:
|
imageUrl:
|
||||||
'https://otvet.imgsmail.ru/download/306401642_9fecf789a8802c5805c4e21291cba6a6_800.jpg',
|
'https://otvet.imgsmail.ru/download/306401642_9fecf789a8802c5805c4e21291cba6a6_800.jpg',
|
||||||
gameDesc: 2,
|
gameDesc: 2,
|
||||||
gameDesc2: 2
|
gameDesc2: 2),
|
||||||
),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,10 @@ class WeaponsRepository extends ApiInterface {
|
|||||||
static const String _baseUrl = 'https://valorant-api.com/v1/weapons';
|
static const String _baseUrl = 'https://valorant-api.com/v1/weapons';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<CardData>?> loadData({OnErrorCallback? onError,String? q,}) async {
|
Future<List<CardData>?> loadData({
|
||||||
|
OnErrorCallback? onError,
|
||||||
|
String? q,
|
||||||
|
}) async {
|
||||||
try {
|
try {
|
||||||
// Формирование URL для запроса
|
// Формирование URL для запроса
|
||||||
final Response<dynamic> response = await _dio.get(_baseUrl);
|
final Response<dynamic> response = await _dio.get(_baseUrl);
|
||||||
@ -30,8 +33,9 @@ class WeaponsRepository extends ApiInterface {
|
|||||||
|
|
||||||
// Фильтрация данных по displayName
|
// Фильтрация данных по displayName
|
||||||
if (q != null && q.isNotEmpty) {
|
if (q != null && q.isNotEmpty) {
|
||||||
data = data?.where((Weapon) =>
|
data = data
|
||||||
Weapon.text?.toLowerCase().contains(q.toLowerCase()) ?? false).toList();
|
?.where((Weapon) => Weapon.text?.toLowerCase().contains(q.toLowerCase()) ?? false)
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
@ -7,13 +7,15 @@ class CardData {
|
|||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final int? gameDesc;
|
final int? gameDesc;
|
||||||
final int? gameDesc2;
|
final int? gameDesc2;
|
||||||
|
late final String uuid;
|
||||||
|
|
||||||
CardData(
|
CardData(
|
||||||
this.text, {
|
this.text, {
|
||||||
required this.categoryText,
|
required this.categoryText,
|
||||||
//this.icon = Icons.ac_unit_outlined,
|
//this.icon = Icons.ac_unit_outlined,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
required this.gameDesc,
|
required this.gameDesc,
|
||||||
required this.gameDesc2,
|
required this.gameDesc2,
|
||||||
});
|
required this.uuid,
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_test_app/presentation/home_page/bloc/bloc.dart';
|
import 'package:flutter_test_app/presentation/home_page/bloc/bloc.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/like_bloc/like_bloc.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/locale_bloc/locale_bloc.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/locale_bloc/locale_state.dart';
|
||||||
|
import 'components/locale/l10n/app_locale.dart';
|
||||||
import 'data/repositories/weapons_repository.dart';
|
import 'data/repositories/weapons_repository.dart';
|
||||||
import 'presentation/home_page/home_page.dart';
|
import 'presentation/home_page/home_page.dart';
|
||||||
|
|
||||||
@ -13,28 +18,36 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return BlocProvider<LocaleBloc>(
|
||||||
title: 'Flutter Demo',
|
lazy: false,
|
||||||
debugShowCheckedModeBanner: false,
|
create: (context) => LocaleBloc(Locale(Platform.localeName)),
|
||||||
theme: ThemeData(
|
child: BlocBuilder<LocaleBloc, LocaleState>(//Передаём текущую локаль
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
builder: (context, state) {
|
||||||
useMaterial3: true,
|
return MaterialApp(
|
||||||
),
|
title: 'Flutter Demo',
|
||||||
home: RepositoryProvider<WeaponsRepository>( //даём нашему репозиторию доступ
|
locale: state.currentLocale,
|
||||||
lazy: true, //ленивое создание объекта
|
localizationsDelegates: AppLocale.localizationsDelegates,
|
||||||
create: (_) => WeaponsRepository(),
|
supportedLocales: AppLocale.supportedLocales, // подключаем список доступных локалей
|
||||||
child: BlocProvider<HomeBloc>( //даём доступ Bloc для нашей страницы
|
debugShowCheckedModeBanner: false,
|
||||||
lazy: false,
|
theme: ThemeData(
|
||||||
create: (context) => HomeBloc(context.read<WeaponsRepository>()), //в конструктор нашего Блока передаём репозиторий с нашей апи, то есть у нас появляется доступ по дереву к апи
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurpleAccent),
|
||||||
child: const MyHomePage(title: 'Каталог оружий Valorant'),
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
),
|
home: RepositoryProvider<WeaponsRepository>(
|
||||||
|
lazy: true,
|
||||||
|
create: (_) => WeaponsRepository(),
|
||||||
|
child: BlocProvider<LikeBloc>(
|
||||||
|
lazy: false,
|
||||||
|
create: (context) => LikeBloc(),
|
||||||
|
child: BlocProvider<HomeBloc>(
|
||||||
|
lazy: false,
|
||||||
|
create: (context) => HomeBloc(context.read<WeaponsRepository>()),
|
||||||
|
child: const MyHomePage(title: 'Каталог оружия Valorant'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ class DetailsPage extends StatelessWidget {
|
|||||||
'Кол-во патрон: ${data.gameDesc.toString()}, Стоимость: ${data.gameDesc2.toString()}',
|
'Кол-во патрон: ${data.gameDesc.toString()}, Стоимость: ${data.gameDesc2.toString()}',
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
)
|
)
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -3,28 +3,30 @@ import 'package:flutter_test_app/presentation/home_page/bloc/events.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import '../../../data/repositories/weapons_repository.dart';
|
import '../../../data/repositories/weapons_repository.dart';
|
||||||
|
|
||||||
class HomeBloc extends Bloc<HomeEvent, HomeState>{//наследуем от Bloc и передаём состояния
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||||
|
//наследуем от Bloc и передаём состояния
|
||||||
final WeaponsRepository rep;
|
final WeaponsRepository rep;
|
||||||
|
|
||||||
HomeBloc(this.rep) : super(const HomeState()) {
|
HomeBloc(this.rep) : super(const HomeState()) {
|
||||||
on<HomeLoadDataEvent>(_onLoadData);
|
on<HomeLoadDataEvent>(_onLoadData);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadData(
|
Future<void> _onLoadData(HomeLoadDataEvent event, Emitter<HomeState> emit) async {
|
||||||
HomeLoadDataEvent event, Emitter<HomeState> emit) async {
|
|
||||||
emit(state.copyWith(isLoading: true)); //метода emit изменяет наши состояния
|
emit(state.copyWith(isLoading: true)); //метода emit изменяет наши состояния
|
||||||
|
|
||||||
String? error;
|
String? error;
|
||||||
|
|
||||||
final data = await rep.loadData( //загрузка данных
|
final data = await rep.loadData(
|
||||||
|
//загрузка данных
|
||||||
q: event.search,
|
q: event.search,
|
||||||
onError: (e) => error = e,
|
onError: (e) => error = e,
|
||||||
);
|
);
|
||||||
|
|
||||||
emit(state.copyWith( //метода emit изменяет наши состояния
|
emit(state.copyWith(
|
||||||
|
//метода emit изменяет наши состояния
|
||||||
isLoading: false, //флаг загрузки меняем на false
|
isLoading: false, //флаг загрузки меняем на false
|
||||||
data: data,
|
data: data,
|
||||||
error: error,
|
error: error,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
abstract class HomeEvent{ //наследуем все события
|
abstract class HomeEvent {
|
||||||
|
//наследуем все события
|
||||||
const HomeEvent();
|
const HomeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
class HomeLoadDataEvent extends HomeEvent{
|
class HomeLoadDataEvent extends HomeEvent {
|
||||||
final String? search; //событие поиска
|
final String? search; //событие поиска
|
||||||
|
|
||||||
const HomeLoadDataEvent({this.search}); //событие на загрузку данных
|
const HomeLoadDataEvent({this.search}); //событие на загрузку данных
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@ import 'package:equatable/equatable.dart';
|
|||||||
import '../../../domain/models/card.dart';
|
import '../../../domain/models/card.dart';
|
||||||
|
|
||||||
@CopyWith()
|
@CopyWith()
|
||||||
class HomeState extends Equatable{ //сравнение двух состояний через Equatable
|
class HomeState extends Equatable {
|
||||||
|
//сравнение двух состояний через Equatable
|
||||||
final List<CardData>? data;
|
final List<CardData>? data;
|
||||||
final bool isLoading; //отображение загрузки
|
final bool isLoading; //отображение загрузки
|
||||||
final String? error; //отображение ошибок
|
final String? error; //отображение ошибок
|
||||||
@ -14,7 +15,8 @@ class HomeState extends Equatable{ //сравнение двух состоян
|
|||||||
this.error,
|
this.error,
|
||||||
});
|
});
|
||||||
|
|
||||||
HomeState copyWith({ //copyWith создаёт копию объекта с изменением некоторых данных
|
HomeState copyWith({
|
||||||
|
//copyWith создаёт копию объекта с изменением некоторых данных
|
||||||
List<CardData>? data,
|
List<CardData>? data,
|
||||||
bool? isLoading,
|
bool? isLoading,
|
||||||
String? error,
|
String? error,
|
||||||
@ -27,8 +29,8 @@ class HomeState extends Equatable{ //сравнение двух состоян
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
data,
|
data,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,49 +1,49 @@
|
|||||||
part of 'home_page.dart';
|
part of 'home_page.dart';
|
||||||
|
|
||||||
typedef OnLikeCallback = void Function(String title, bool isLiked);
|
typedef OnLikeCallback = void Function(String? id, String title, bool isLiked);
|
||||||
|
|
||||||
class _Card extends StatefulWidget {
|
class _Card extends StatelessWidget {
|
||||||
final String text;
|
final String text;
|
||||||
final String categoryText;
|
final String categoryText;
|
||||||
//final IconData icon;
|
//final IconData icon;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final OnLikeCallback? onLike;
|
final OnLikeCallback? onLike;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
|
final String uuid;
|
||||||
|
final bool isLiked;
|
||||||
|
|
||||||
const _Card(
|
const _Card(
|
||||||
this.text, {
|
this.text, {
|
||||||
//this.icon = Icons.abc,
|
//this.icon = Icons.abc,
|
||||||
required this.categoryText,
|
required this.categoryText,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
this.onLike,
|
this.onLike,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
});
|
required this.uuid,
|
||||||
|
this.isLiked = false,
|
||||||
|
});
|
||||||
|
|
||||||
factory _Card.fromData(
|
factory _Card.fromData(
|
||||||
CardData data, {
|
CardData data, {
|
||||||
OnLikeCallback? onLike,
|
OnLikeCallback? onLike,
|
||||||
VoidCallback? onTap,
|
VoidCallback? onTap,
|
||||||
}) =>
|
bool isLiked = false,
|
||||||
|
}) =>
|
||||||
_Card(
|
_Card(
|
||||||
|
uuid: data.uuid,
|
||||||
data.text!,
|
data.text!,
|
||||||
categoryText: data.categoryText!,
|
categoryText: data.categoryText!,
|
||||||
//icon: data.icon,
|
//icon: data.icon,
|
||||||
imageUrl: data.imageUrl,
|
imageUrl: data.imageUrl,
|
||||||
onLike: onLike,
|
onLike: onLike,
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
|
isLiked: isLiked,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
|
||||||
State<_Card> createState() => _CardState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CardState extends State<_Card> {
|
|
||||||
bool isLiked = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: widget.onTap,
|
onTap: onTap,
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.all(5),
|
margin: const EdgeInsets.all(5),
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
@ -72,7 +72,7 @@ class _CardState extends State<_Card> {
|
|||||||
children: [
|
children: [
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: Image.network(
|
child: Image.network(
|
||||||
widget.imageUrl ?? '',
|
imageUrl ?? '',
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||||
),
|
),
|
||||||
@ -89,10 +89,8 @@ class _CardState extends State<_Card> {
|
|||||||
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
|
padding: const EdgeInsets.fromLTRB(8, 2, 8, 2),
|
||||||
child: Text(
|
child: Text(
|
||||||
'New!!!!',
|
'New!!!!',
|
||||||
style: Theme.of(context)
|
style:
|
||||||
.textTheme
|
Theme.of(context).textTheme.bodyMedium?.copyWith(color: Colors.black),
|
||||||
.bodyMedium
|
|
||||||
?.copyWith(color: Colors.black),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -102,38 +100,33 @@ class _CardState extends State<_Card> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
Text(
|
Text(
|
||||||
widget.text,
|
text,
|
||||||
style: Theme.of(context).textTheme.headlineLarge,
|
style: Theme.of(context).textTheme.headlineLarge,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
widget.categoryText,
|
categoryText,
|
||||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () => onLike?.call(uuid, text, isLiked),
|
||||||
setState(() {
|
|
||||||
isLiked = !isLiked;
|
|
||||||
});
|
|
||||||
widget.onLike?.call(widget.text, isLiked);
|
|
||||||
},
|
|
||||||
child: AnimatedSwitcher(
|
child: AnimatedSwitcher(
|
||||||
duration: const Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
child: isLiked
|
child: isLiked
|
||||||
? const Icon(
|
? const Icon(
|
||||||
Icons.favorite,
|
Icons.favorite,
|
||||||
color: Colors.redAccent,
|
color: Colors.redAccent,
|
||||||
key: ValueKey<int>(0),
|
key: ValueKey<int>(0),
|
||||||
)
|
)
|
||||||
: const Icon(
|
: const Icon(
|
||||||
Icons.favorite_border,
|
Icons.favorite_border,
|
||||||
key: ValueKey<int>(1),
|
key: ValueKey<int>(1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_test_app/components/extensions/context_x.dart';
|
||||||
|
import 'package:flutter_test_app/data/repositories/mock_repository.dart';
|
||||||
|
import 'package:flutter_test_app/main.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/like_bloc/like_bloc.dart';
|
||||||
import '../../components/utils/debounce.dart';
|
import 'package:flutter_test_app/presentation/like_bloc/like_event.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/like_bloc/like_state.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/locale_bloc/locale_bloc.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/locale_bloc/locale_events.dart';
|
||||||
|
import 'package:flutter_test_app/presentation/locale_bloc/locale_state.dart';
|
||||||
import '../../data/repositories/weapons_repository.dart';
|
import '../../data/repositories/weapons_repository.dart';
|
||||||
import '../../domain/models/card.dart';
|
import '../../domain/models/card.dart';
|
||||||
|
import '../common/svg_objects.dart';
|
||||||
import '../details_page/details_page.dart';
|
import '../details_page/details_page.dart';
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'bloc/bloc.dart';
|
import 'bloc/bloc.dart';
|
||||||
import 'bloc/events.dart';
|
import 'bloc/events.dart';
|
||||||
import 'bloc/state.dart';
|
import 'bloc/state.dart';
|
||||||
|
import '../../components/utils/debounce.dart';
|
||||||
part 'card.dart';
|
part 'card.dart';
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatefulWidget {
|
||||||
@ -50,8 +57,13 @@ class _BodyState extends State<Body> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) { // привязываем логику к кадру
|
SvgObjects.init();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
// привязываем логику к кадру
|
||||||
context.read<HomeBloc>().add(const HomeLoadDataEvent()); // добавляем данные после считывания
|
context.read<HomeBloc>().add(const HomeLoadDataEvent()); // добавляем данные после считывания
|
||||||
|
context
|
||||||
|
.read<LikeBloc>()
|
||||||
|
.add(const LoadLikesEvent()); // загрузка лайков которые ставили в прошлый раз
|
||||||
});
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
@ -62,57 +74,93 @@ class _BodyState extends State<Body> {
|
|||||||
_scrollController.dispose();
|
_scrollController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onRefresh() {
|
Future<void> _onRefresh() {
|
||||||
context
|
context.read<HomeBloc>().add(HomeLoadDataEvent(search: searchController.text));
|
||||||
.read<HomeBloc>()
|
|
||||||
.add(HomeLoadDataEvent(search: searchController.text));
|
|
||||||
return Future.value(null); //прекращение отображения загрузки
|
return Future.value(null); //прекращение отображения загрузки
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onLike(String? id, String title, bool isLiked) {
|
||||||
|
if (id != null) {
|
||||||
|
context.read<LikeBloc>().add(ChangeLikeEvent(id));
|
||||||
|
_showSnackBar(context, title, !isLiked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
child: CupertinoSearchTextField(
|
child: Row(
|
||||||
controller: searchController,
|
// наше поле для поиска
|
||||||
onChanged: (search ) { //вызов задержки пока пользователь не перестанет печатать в поисковой строке
|
children: [
|
||||||
Debounce.run(() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search)));
|
Expanded(
|
||||||
},
|
child: CupertinoSearchTextField(
|
||||||
|
// переписали под наши локали
|
||||||
|
controller: searchController,
|
||||||
|
placeholder: context.locale.search,
|
||||||
|
onChanged: (search) {
|
||||||
|
Debounce.run(
|
||||||
|
() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search)));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
// иконки для смены локали
|
||||||
|
onTap: () => context
|
||||||
|
.read<LocaleBloc>()
|
||||||
|
.add(const ChangeLocaleEvent()), //меняет в зависимости от текущей локализации
|
||||||
|
child: SizedBox.square(
|
||||||
|
dimension: 50,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 12),
|
||||||
|
child: BlocBuilder<LocaleBloc, LocaleState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return state.currentLocale.languageCode == 'ru'
|
||||||
|
? const SvgRu()
|
||||||
|
: const SvgUk(); // иконки из ассетов
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
BlocBuilder<HomeBloc, HomeState>( //ждёт изменения состояния
|
BlocBuilder<HomeBloc, HomeState>(
|
||||||
|
//ждёт изменения состояния
|
||||||
builder: (context, state) => state.error != null
|
builder: (context, state) => state.error != null
|
||||||
? Text(
|
? Text(
|
||||||
state.error ?? '',
|
state.error ?? '',
|
||||||
style: Theme.of(context)
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(color: Colors.red),
|
||||||
.textTheme
|
)
|
||||||
.headlineSmall
|
|
||||||
?.copyWith(color: Colors.red),
|
|
||||||
)
|
|
||||||
: state.isLoading
|
: state.isLoading
|
||||||
? const CircularProgressIndicator()
|
? const CircularProgressIndicator()
|
||||||
: Expanded(
|
: BlocBuilder<LikeBloc, LikeState>(
|
||||||
child: RefreshIndicator(
|
// проверяем в зависимости от стейта, лайкнута ли карточка
|
||||||
onRefresh: _onRefresh,
|
builder: (context, likeState) => Expanded(
|
||||||
child: ListView.builder(
|
child: RefreshIndicator(
|
||||||
padding: EdgeInsets.zero,
|
onRefresh: _onRefresh,
|
||||||
itemCount: state.data?.length ?? 0,
|
child: ListView.builder(
|
||||||
itemBuilder: (context, index) {
|
padding: EdgeInsets.zero,
|
||||||
final data = state.data?[index];
|
itemCount: state.data?.length ?? 0,
|
||||||
return data != null
|
itemBuilder: (context, index) {
|
||||||
? _Card.fromData(
|
final data = state.data?[index];
|
||||||
data,
|
return data != null
|
||||||
onLike: (String title, bool isLiked) =>
|
? _Card.fromData(
|
||||||
_showSnackBar(context, title, isLiked),
|
data,
|
||||||
onTap: () => _navToDetails(context, data),
|
onLike: _onLike,
|
||||||
)
|
isLiked: likeState.likedIds?.contains(data.uuid) == true,
|
||||||
: const SizedBox.shrink();
|
onTap: () => _navToDetails(context, data),
|
||||||
},
|
)
|
||||||
),
|
: const SizedBox.shrink();
|
||||||
),
|
},
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -129,7 +177,7 @@ class _BodyState extends State<Body> {
|
|||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
'News $title ${isLiked ? 'liked' : 'disliked '}',
|
'$title ${isLiked ? context.locale.liked : context.locale.disliked}',
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.deepPurpleAccent,
|
backgroundColor: Colors.deepPurpleAccent,
|
||||||
|
246
pubspec.lock
246
pubspec.lock
@ -17,6 +17,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.2.0"
|
version: "6.2.0"
|
||||||
|
archive:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: archive
|
||||||
|
sha256: "08064924cbf0ab88280a0c3f60db9dd24fec693927e725ecb176f16c629d1cb8"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.1"
|
||||||
args:
|
args:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -129,6 +137,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
version: "2.0.3"
|
||||||
|
cli_util:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: cli_util
|
||||||
|
sha256: c05b7406fdabc7a49a3929d4af76bcaccbbffcbcdcf185b082e1ae07da323d19
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.4.1"
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -162,7 +178,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.1"
|
||||||
copy_with_extension:
|
copy_with_extension:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: copy_with_extension
|
name: copy_with_extension
|
||||||
sha256: fbcf890b0c34aedf0894f91a11a579994b61b4e04080204656b582708b5b1125
|
sha256: fbcf890b0c34aedf0894f91a11a579994b61b4e04080204656b582708b5b1125
|
||||||
@ -241,6 +257,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.1"
|
version: "1.3.1"
|
||||||
|
ffi:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: ffi
|
||||||
|
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
file:
|
file:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -270,6 +294,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "8.1.6"
|
version: "8.1.6"
|
||||||
|
flutter_launcher_icons:
|
||||||
|
dependency: "direct dev"
|
||||||
|
description:
|
||||||
|
name: flutter_launcher_icons
|
||||||
|
sha256: "526faf84284b86a4cb36d20a5e45147747b7563d921373d4ee0559c54fcdbcea"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.13.1"
|
||||||
flutter_lints:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -278,11 +310,29 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.0"
|
version: "4.0.0"
|
||||||
|
flutter_localizations:
|
||||||
|
dependency: "direct main"
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
|
flutter_svg:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_svg
|
||||||
|
sha256: "8c5d68a82add3ca76d792f058b186a0599414f279f00ece4830b9b231b570338"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.7"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_web_plugins:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
frontend_server_client:
|
frontend_server_client:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -315,6 +365,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.15.4"
|
version: "0.15.4"
|
||||||
|
http:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: http
|
||||||
|
sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0"
|
||||||
http_multi_server:
|
http_multi_server:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -331,6 +389,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.2"
|
version: "4.0.2"
|
||||||
|
image:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: image
|
||||||
|
sha256: "599d08e369969bdf83138f5b4e0a7e823d3f992f23b8a64dd626877c37013533"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.4.0"
|
||||||
|
intl:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: intl
|
||||||
|
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.18.1"
|
||||||
io:
|
io:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -435,6 +509,62 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.3"
|
version: "1.8.3"
|
||||||
|
path_parsing:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_parsing
|
||||||
|
sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.1"
|
||||||
|
path_provider_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_linux
|
||||||
|
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.1"
|
||||||
|
path_provider_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_platform_interface
|
||||||
|
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.2"
|
||||||
|
path_provider_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: path_provider_windows
|
||||||
|
sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.1"
|
||||||
|
petitparser:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: petitparser
|
||||||
|
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.4.0"
|
||||||
|
platform:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: platform
|
||||||
|
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.4"
|
||||||
|
plugin_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: plugin_platform_interface
|
||||||
|
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.8"
|
||||||
pool:
|
pool:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -443,6 +573,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.5.1"
|
version: "1.5.1"
|
||||||
|
posix:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: posix
|
||||||
|
sha256: a0117dc2167805aa9125b82eee515cc891819bac2f538c83646d355b16f58b9a
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.0.1"
|
||||||
pretty_dio_logger:
|
pretty_dio_logger:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -475,6 +613,62 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.3.0"
|
||||||
|
shared_preferences:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: shared_preferences
|
||||||
|
sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.3"
|
||||||
|
shared_preferences_android:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_android
|
||||||
|
sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.1"
|
||||||
|
shared_preferences_foundation:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_foundation
|
||||||
|
sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.5"
|
||||||
|
shared_preferences_linux:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_linux
|
||||||
|
sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.2"
|
||||||
|
shared_preferences_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_platform_interface
|
||||||
|
sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.2"
|
||||||
|
shared_preferences_web:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_web
|
||||||
|
sha256: d762709c2bbe80626ecc819143013cc820fa49ca5e363620ee20a8b15a3e3daf
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.1"
|
||||||
|
shared_preferences_windows:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: shared_preferences_windows
|
||||||
|
sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.2"
|
||||||
shelf:
|
shelf:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -584,6 +778,30 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.2"
|
version: "1.3.2"
|
||||||
|
vector_graphics:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: vector_graphics
|
||||||
|
sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.11+1"
|
||||||
|
vector_graphics_codec:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: vector_graphics_codec
|
||||||
|
sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.11+1"
|
||||||
|
vector_graphics_compiler:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: vector_graphics_compiler
|
||||||
|
sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.11+1"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -616,6 +834,30 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.0"
|
version: "2.4.0"
|
||||||
|
win32:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: win32
|
||||||
|
sha256: b0f37db61ba2f2e9b7a78a1caece0052564d1bc70668156cf3a29d676fe4e574
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "5.1.1"
|
||||||
|
xdg_directories:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: xdg_directories
|
||||||
|
sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.4"
|
||||||
|
xml:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: xml
|
||||||
|
sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.3.0"
|
||||||
yaml:
|
yaml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -626,4 +868,4 @@ packages:
|
|||||||
version: "3.1.2"
|
version: "3.1.2"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=3.1.3 <4.0.0"
|
dart: ">=3.1.3 <4.0.0"
|
||||||
flutter: ">=1.16.0"
|
flutter: ">=3.13.0"
|
||||||
|
19
pubspec.yaml
19
pubspec.yaml
@ -38,11 +38,17 @@ dependencies:
|
|||||||
cupertino_icons: ^1.0.8
|
cupertino_icons: ^1.0.8
|
||||||
dio: ^5.4.2+1
|
dio: ^5.4.2+1
|
||||||
pretty_dio_logger: ^1.3.1
|
pretty_dio_logger: ^1.3.1
|
||||||
json_annotation: ^4.8.1
|
json_annotation: ^4.9.0
|
||||||
html: ^0.15.0
|
html: ^0.15.0
|
||||||
equatable: ^2.0.5
|
equatable: ^2.0.5
|
||||||
flutter_bloc: ^8.1.5
|
flutter_bloc: ^8.1.5
|
||||||
copy_with_extension_gen: ^5.0.4
|
copy_with_extension_gen: ^5.0.4
|
||||||
|
flutter_svg: 2.0.7
|
||||||
|
flutter_localizations:
|
||||||
|
sdk: flutter
|
||||||
|
intl: ^0.18.1
|
||||||
|
copy_with_extension: ^5.0.4
|
||||||
|
shared_preferences: ^2.2.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
@ -53,21 +59,26 @@ dev_dependencies:
|
|||||||
# activated in the `analysis_options.yaml` file located at the root of your
|
# activated in the `analysis_options.yaml` file located at the root of your
|
||||||
# package. See that file for information about deactivating specific lint
|
# package. See that file for information about deactivating specific lint
|
||||||
# rules and activating additional ones.
|
# rules and activating additional ones.
|
||||||
|
flutter_launcher_icons: 0.13.1
|
||||||
build_runner: ^2.4.9
|
build_runner: ^2.4.9
|
||||||
json_serializable: ^6.7.1
|
json_serializable: ^6.7.1
|
||||||
flutter_lints: ^4.0.0
|
flutter_lints: ^4.0.0
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
flutter_launcher_icons:
|
||||||
|
android: "ic_launcher"
|
||||||
|
image_path: "assets/ic_launcher.png"
|
||||||
|
min_sdk_android: 21
|
||||||
# The following section is specific to Flutter packages.
|
# The following section is specific to Flutter packages.
|
||||||
flutter:
|
flutter:
|
||||||
|
generate: true
|
||||||
# The following line ensures that the Material Icons font is
|
# The following line ensures that the Material Icons font is
|
||||||
# included with your application, so that you can use the icons in
|
# included with your application, so that you can use the icons in
|
||||||
# the material Icons class.
|
# the material Icons class.
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
assets:
|
||||||
|
- assets/svg/
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
# - images/a_dot_burr.jpeg
|
# - images/a_dot_burr.jpeg
|
||||||
|
Loading…
x
Reference in New Issue
Block a user