diff --git a/lec6/.gitignore b/lec6/.gitignore
new file mode 100644
index 0000000..29a3a50
--- /dev/null
+++ b/lec6/.gitignore
@@ -0,0 +1,43 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
+.DS_Store
+.atom/
+.buildlog/
+.history
+.svn/
+migrate_working_dir/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+**/doc/api/
+**/ios/Flutter/.last_build_id
+.dart_tool/
+.flutter-plugins
+.flutter-plugins-dependencies
+.pub-cache/
+.pub/
+/build/
+
+# Symbolication related
+app.*.symbols
+
+# Obfuscation related
+app.*.map.json
+
+# Android Studio will place build artifacts here
+/android/app/debug
+/android/app/profile
+/android/app/release
diff --git a/lec6/.metadata b/lec6/.metadata
new file mode 100644
index 0000000..6bcf4e8
--- /dev/null
+++ b/lec6/.metadata
@@ -0,0 +1,33 @@
+# This file tracks properties of this Flutter project.
+# Used by Flutter tool to assess capabilities and perform upgrades etc.
+#
+# This file should be version controlled and should not be manually edited.
+
+version:
+ revision: "4cf269e36de2573851eaef3c763994f8f9be494d"
+ channel: "stable"
+
+project_type: app
+
+# Tracks metadata for the flutter migrate command
+migration:
+ platforms:
+ - platform: root
+ create_revision: 4cf269e36de2573851eaef3c763994f8f9be494d
+ base_revision: 4cf269e36de2573851eaef3c763994f8f9be494d
+ - platform: android
+ create_revision: 4cf269e36de2573851eaef3c763994f8f9be494d
+ base_revision: 4cf269e36de2573851eaef3c763994f8f9be494d
+ - platform: web
+ create_revision: 4cf269e36de2573851eaef3c763994f8f9be494d
+ base_revision: 4cf269e36de2573851eaef3c763994f8f9be494d
+
+ # User provided section
+
+ # List of Local paths (relative to this file) that should be
+ # ignored by the migrate tool.
+ #
+ # Files that are not part of the templates will be ignored by default.
+ unmanaged_files:
+ - 'lib/main.dart'
+ - 'ios/Runner.xcodeproj/project.pbxproj'
diff --git a/lec6/README.md b/lec6/README.md
new file mode 100644
index 0000000..880edaf
--- /dev/null
+++ b/lec6/README.md
@@ -0,0 +1,24 @@
+# API
+
+https://api.potterdb.com/v1/characters
+
+# Build files
+
+dart run build_runner build --delete-conflicting-outputs
+
+# test_app
+
+Test app
+
+## Getting Started
+
+This project is a starting point for a Flutter application.
+
+A few resources to get you started if this is your first Flutter project:
+
+- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
+- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
+
+For help getting started with Flutter development, view the
+[online documentation](https://docs.flutter.dev/), which offers tutorials,
+samples, guidance on mobile development, and a full API reference.
diff --git a/lec6/analysis_options.yaml b/lec6/analysis_options.yaml
new file mode 100644
index 0000000..7161cfd
--- /dev/null
+++ b/lec6/analysis_options.yaml
@@ -0,0 +1,28 @@
+# This file configures the analyzer, which statically analyzes Dart code to
+# check for errors, warnings, and lints.
+#
+# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
+# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
+# invoked from the command line by running `flutter analyze`.
+
+# The following line activates a set of recommended lints for Flutter apps,
+# packages, and plugins designed to encourage good coding practices.
+include: package:flutter_lints/flutter.yaml
+
+linter:
+ # The lint rules applied to this project can be customized in the
+ # section below to disable rules from the `package:flutter_lints/flutter.yaml`
+ # included above or to enable additional rules. A list of all available lints
+ # and their documentation is published at https://dart.dev/lints.
+ #
+ # Instead of disabling a lint rule for the entire project in the
+ # section below, it can also be suppressed for a single line of code
+ # or a specific dart file by using the `// ignore: name_of_lint` and
+ # `// ignore_for_file: name_of_lint` syntax on the line or in the file
+ # producing the lint.
+ rules:
+ # avoid_print: false # Uncomment to disable the `avoid_print` rule
+ # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
+
+# Additional information about this file can be found at
+# https://dart.dev/guides/language/analysis-options
diff --git a/lec6/android/.gitignore b/lec6/android/.gitignore
new file mode 100644
index 0000000..55afd91
--- /dev/null
+++ b/lec6/android/.gitignore
@@ -0,0 +1,13 @@
+gradle-wrapper.jar
+/.gradle
+/captures/
+/gradlew
+/gradlew.bat
+/local.properties
+GeneratedPluginRegistrant.java
+
+# Remember to never publicly share your keystore.
+# See https://flutter.dev/to/reference-keystore
+key.properties
+**/*.keystore
+**/*.jks
diff --git a/lec6/android/app/build.gradle b/lec6/android/app/build.gradle
new file mode 100644
index 0000000..397a734
--- /dev/null
+++ b/lec6/android/app/build.gradle
@@ -0,0 +1,44 @@
+plugins {
+ id "com.android.application"
+ id "kotlin-android"
+ // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
+ id "dev.flutter.flutter-gradle-plugin"
+}
+
+android {
+ namespace = "ru.ulstu.is.test_app"
+ compileSdk = flutter.compileSdkVersion
+ ndkVersion = flutter.ndkVersion
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+
+ kotlinOptions {
+ jvmTarget = JavaVersion.VERSION_1_8
+ }
+
+ defaultConfig {
+ // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
+ applicationId = "ru.ulstu.is.test_app"
+ // You can update the following values to match your application needs.
+ // For more information, see: https://flutter.dev/to/review-gradle-config.
+ minSdk = flutter.minSdkVersion
+ targetSdk = flutter.targetSdkVersion
+ versionCode = flutter.versionCode
+ versionName = flutter.versionName
+ }
+
+ buildTypes {
+ release {
+ // TODO: Add your own signing config for the release build.
+ // Signing with the debug keys for now, so `flutter run --release` works.
+ signingConfig = signingConfigs.debug
+ }
+ }
+}
+
+flutter {
+ source = "../.."
+}
diff --git a/lec6/android/app/src/debug/AndroidManifest.xml b/lec6/android/app/src/debug/AndroidManifest.xml
new file mode 100644
index 0000000..4d95910
--- /dev/null
+++ b/lec6/android/app/src/debug/AndroidManifest.xml
@@ -0,0 +1,7 @@
+
+
+
+
diff --git a/lec6/android/app/src/main/AndroidManifest.xml b/lec6/android/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..fdc9875
--- /dev/null
+++ b/lec6/android/app/src/main/AndroidManifest.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lec6/android/app/src/main/kotlin/ru/ulstu/is/test_app/MainActivity.kt b/lec6/android/app/src/main/kotlin/ru/ulstu/is/test_app/MainActivity.kt
new file mode 100644
index 0000000..60baa7b
--- /dev/null
+++ b/lec6/android/app/src/main/kotlin/ru/ulstu/is/test_app/MainActivity.kt
@@ -0,0 +1,5 @@
+package ru.ulstu.`is`.test_app
+
+import io.flutter.embedding.android.FlutterActivity
+
+class MainActivity : FlutterActivity()
diff --git a/lec6/android/app/src/main/res/drawable-v21/launch_background.xml b/lec6/android/app/src/main/res/drawable-v21/launch_background.xml
new file mode 100644
index 0000000..c03a191
--- /dev/null
+++ b/lec6/android/app/src/main/res/drawable-v21/launch_background.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
diff --git a/lec6/android/app/src/main/res/drawable/launch_background.xml b/lec6/android/app/src/main/res/drawable/launch_background.xml
new file mode 100644
index 0000000..0db4a83
--- /dev/null
+++ b/lec6/android/app/src/main/res/drawable/launch_background.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
diff --git a/lec6/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/lec6/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..db77bb4
Binary files /dev/null and b/lec6/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/lec6/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/lec6/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..17987b7
Binary files /dev/null and b/lec6/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/lec6/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/lec6/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..09d4391
Binary files /dev/null and b/lec6/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/lec6/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/lec6/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..d5f1c8d
Binary files /dev/null and b/lec6/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/lec6/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/lec6/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..4d6372e
Binary files /dev/null and b/lec6/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/lec6/android/app/src/main/res/values-night/styles.xml b/lec6/android/app/src/main/res/values-night/styles.xml
new file mode 100644
index 0000000..06952be
--- /dev/null
+++ b/lec6/android/app/src/main/res/values-night/styles.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
diff --git a/lec6/android/app/src/main/res/values/styles.xml b/lec6/android/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..cb1ef88
--- /dev/null
+++ b/lec6/android/app/src/main/res/values/styles.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
diff --git a/lec6/android/app/src/profile/AndroidManifest.xml b/lec6/android/app/src/profile/AndroidManifest.xml
new file mode 100644
index 0000000..4d95910
--- /dev/null
+++ b/lec6/android/app/src/profile/AndroidManifest.xml
@@ -0,0 +1,7 @@
+
+
+
+
diff --git a/lec6/android/build.gradle b/lec6/android/build.gradle
new file mode 100644
index 0000000..d2ffbff
--- /dev/null
+++ b/lec6/android/build.gradle
@@ -0,0 +1,18 @@
+allprojects {
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+
+rootProject.buildDir = "../build"
+subprojects {
+ project.buildDir = "${rootProject.buildDir}/${project.name}"
+}
+subprojects {
+ project.evaluationDependsOn(":app")
+}
+
+tasks.register("clean", Delete) {
+ delete rootProject.buildDir
+}
diff --git a/lec6/android/gradle.properties b/lec6/android/gradle.properties
new file mode 100644
index 0000000..2597170
--- /dev/null
+++ b/lec6/android/gradle.properties
@@ -0,0 +1,3 @@
+org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
+android.useAndroidX=true
+android.enableJetifier=true
diff --git a/lec6/android/gradle/wrapper/gradle-wrapper.properties b/lec6/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..7bb2df6
--- /dev/null
+++ b/lec6/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
diff --git a/lec6/android/settings.gradle b/lec6/android/settings.gradle
new file mode 100644
index 0000000..b9e43bd
--- /dev/null
+++ b/lec6/android/settings.gradle
@@ -0,0 +1,25 @@
+pluginManagement {
+ def flutterSdkPath = {
+ def properties = new Properties()
+ file("local.properties").withInputStream { properties.load(it) }
+ def flutterSdkPath = properties.getProperty("flutter.sdk")
+ assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
+ return flutterSdkPath
+ }()
+
+ includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
+
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+
+plugins {
+ id "dev.flutter.flutter-plugin-loader" version "1.0.0"
+ id "com.android.application" version "8.1.0" apply false
+ id "org.jetbrains.kotlin.android" version "1.8.22" apply false
+}
+
+include ":app"
diff --git a/lec6/lib/data/dto/characters_dto.dart b/lec6/lib/data/dto/characters_dto.dart
new file mode 100644
index 0000000..22a7421
--- /dev/null
+++ b/lec6/lib/data/dto/characters_dto.dart
@@ -0,0 +1,61 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'characters_dto.g.dart';
+
+@JsonSerializable(createToJson: false)
+class CharactersDto {
+ final List? data;
+ final MetaDto? meta;
+
+ const CharactersDto({this.data, this.meta});
+
+ factory CharactersDto.fromJson(Map json) =>
+ _$CharactersDtoFromJson(json);
+}
+
+@JsonSerializable(createToJson: false)
+class MetaDto {
+ final PaginationDto? pagination;
+
+ const MetaDto({this.pagination});
+
+ factory MetaDto.fromJson(Map json) =>
+ _$MetaDtoFromJson(json);
+}
+
+@JsonSerializable(createToJson: false)
+class PaginationDto {
+ final int? current;
+ final int? next;
+ final int? last;
+
+ PaginationDto({this.current, this.next, this.last});
+
+ factory PaginationDto.fromJson(Map json) =>
+ _$PaginationDtoFromJson(json);
+}
+
+@JsonSerializable(createToJson: false)
+class CharacterDto {
+ final String? id;
+ final String? type;
+ final CharacterAttributesDto? attributes;
+
+ const CharacterDto({this.id, this.type, this.attributes});
+
+ factory CharacterDto.fromJson(Map json) =>
+ _$CharacterDtoFromJson(json);
+}
+
+@JsonSerializable(createToJson: false)
+class CharacterAttributesDto {
+ final String? name;
+ final String? born;
+ final String? died;
+ final String? image;
+
+ const CharacterAttributesDto({this.name, this.born, this.died, this.image});
+
+ factory CharacterAttributesDto.fromJson(Map json) =>
+ _$CharacterAttributesDtoFromJson(json);
+}
diff --git a/lec6/lib/data/dto/characters_dto.g.dart b/lec6/lib/data/dto/characters_dto.g.dart
new file mode 100644
index 0000000..80a973a
--- /dev/null
+++ b/lec6/lib/data/dto/characters_dto.g.dart
@@ -0,0 +1,48 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'characters_dto.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+CharactersDto _$CharactersDtoFromJson(Map json) =>
+ CharactersDto(
+ data: (json['data'] as List?)
+ ?.map((e) => CharacterDto.fromJson(e as Map))
+ .toList(),
+ meta: json['meta'] == null
+ ? null
+ : MetaDto.fromJson(json['meta'] as Map),
+ );
+
+MetaDto _$MetaDtoFromJson(Map json) => MetaDto(
+ pagination: json['pagination'] == null
+ ? null
+ : PaginationDto.fromJson(json['pagination'] as Map),
+ );
+
+PaginationDto _$PaginationDtoFromJson(Map json) =>
+ PaginationDto(
+ current: (json['current'] as num?)?.toInt(),
+ next: (json['next'] as num?)?.toInt(),
+ last: (json['last'] as num?)?.toInt(),
+ );
+
+CharacterDto _$CharacterDtoFromJson(Map json) => CharacterDto(
+ id: json['id'] as String?,
+ type: json['type'] as String?,
+ attributes: json['attributes'] == null
+ ? null
+ : CharacterAttributesDto.fromJson(
+ json['attributes'] as Map),
+ );
+
+CharacterAttributesDto _$CharacterAttributesDtoFromJson(
+ Map json) =>
+ CharacterAttributesDto(
+ name: json['name'] as String?,
+ born: json['born'] as String?,
+ died: json['died'] as String?,
+ image: json['image'] as String?,
+ );
diff --git a/lec6/lib/data/mapper/characters_mapper.dart b/lec6/lib/data/mapper/characters_mapper.dart
new file mode 100644
index 0000000..a4c72ce
--- /dev/null
+++ b/lec6/lib/data/mapper/characters_mapper.dart
@@ -0,0 +1,37 @@
+import 'package:test_app/data/dto/characters_dto.dart';
+import 'package:test_app/domain/card.dart';
+import 'package:test_app/domain/home.dart';
+
+const _imagePlaceholder =
+ 'https://www.bellcold.com/wp-content/uploads/2024/04/Person-Placeholder-Icon.jpeg';
+
+extension CharactersDtoToModel on CharactersDto {
+ HomeData toDomain() => HomeData(
+ data: data?.map((e) => e.toDomain()).toList(),
+ currentPage: meta?.pagination?.current,
+ nextPage: meta?.pagination?.next,
+ );
+}
+
+extension CharacterDtoToModel on CharacterDto {
+ CardData toDomain() => CardData(
+ attributes?.name ?? 'UNKNOWN',
+ descriptionText:
+ _makeDescriptionText(attributes?.born, attributes?.died),
+ id: id,
+ imageUrl: attributes?.image ?? _imagePlaceholder,
+ );
+}
+
+String _makeDescriptionText(String? born, String? died) {
+ if (born != null && died != null) {
+ return '$born - $died';
+ }
+ if (born != null) {
+ return 'born: $born';
+ }
+ if (died != null) {
+ return 'died: $died';
+ }
+ return '';
+}
diff --git a/lec6/lib/data/repository/api_interface.dart b/lec6/lib/data/repository/api_interface.dart
new file mode 100644
index 0000000..a1da412
--- /dev/null
+++ b/lec6/lib/data/repository/api_interface.dart
@@ -0,0 +1,7 @@
+import 'package:test_app/domain/home.dart';
+
+typedef OnErrorCallback = void Function(String? error);
+
+abstract class ApiInterface {
+ Future loadData({OnErrorCallback? onError});
+}
diff --git a/lec6/lib/data/repository/mock_repository.dart b/lec6/lib/data/repository/mock_repository.dart
new file mode 100644
index 0000000..d40cc98
--- /dev/null
+++ b/lec6/lib/data/repository/mock_repository.dart
@@ -0,0 +1,29 @@
+import 'package:test_app/data/repository/api_interface.dart';
+import 'package:test_app/domain/card.dart';
+import 'package:test_app/domain/home.dart';
+
+class MockRepository extends ApiInterface {
+ @override
+ Future loadData({OnErrorCallback? onError}) async {
+ return HomeData(data: [
+ CardData(
+ 'Hello',
+ descriptionText: 'Hello text',
+ imageUrl:
+ 'https://unsplash.com/photos/6GMq7AGxNbE/download?ixid=M3wxMjA3fDB8MXxzZWFyY2h8Mnx8cmFjY29vbnxlbnwwfHx8fDE3Mjc5MTExNTl8MA&force=true&w=640',
+ ),
+ CardData(
+ 'Hello 2',
+ descriptionText: 'Hello 2 text',
+ imageUrl:
+ 'https://unsplash.com/photos/UopR2NUBYek/download?ixid=M3wxMjA3fDB8MXxzZWFyY2h8MTF8fHJhY2Nvb258ZW58MHx8fHwxNzI3OTExMTU5fDA&force=true&w=640',
+ ),
+ CardData(
+ 'Hello 3',
+ descriptionText: 'Hello 3 text',
+ imageUrl:
+ 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/Raccoon_on_Log.jpg/640px-Raccoon_on_Log.jpg',
+ ),
+ ]);
+ }
+}
diff --git a/lec6/lib/data/repository/potter_repository.dart b/lec6/lib/data/repository/potter_repository.dart
new file mode 100644
index 0000000..bee9f40
--- /dev/null
+++ b/lec6/lib/data/repository/potter_repository.dart
@@ -0,0 +1,44 @@
+import 'package:dio/dio.dart';
+import 'package:pretty_dio_logger/pretty_dio_logger.dart';
+import 'package:test_app/data/dto/characters_dto.dart';
+import 'package:test_app/data/mapper/characters_mapper.dart';
+import 'package:test_app/data/repository/api_interface.dart';
+import 'package:test_app/domain/home.dart';
+
+class PotterRepository extends ApiInterface {
+ static final Dio _dio = Dio()
+ ..interceptors.add(PrettyDioLogger(
+ requestHeader: true,
+ requestBody: false,
+ ));
+
+ static const String _baseUrl = 'https://api.potterdb.com';
+
+ @override
+ Future loadData({
+ String? q,
+ int page = 1,
+ int size = 10,
+ OnErrorCallback? onError,
+ }) async {
+ try {
+ const String url = '$_baseUrl/v1/characters';
+
+ final Response response = await _dio.get(
+ url,
+ queryParameters: {
+ 'filter[name_cont]': q,
+ 'page[number]': page,
+ 'page[size]': size,
+ },
+ );
+
+ final CharactersDto dto =
+ CharactersDto.fromJson(response.data as Map);
+ return dto.toDomain();
+ } on DioException catch (e) {
+ onError?.call(e.error?.toString());
+ return null;
+ }
+ }
+}
diff --git a/lec6/lib/domain/card.dart b/lec6/lib/domain/card.dart
new file mode 100644
index 0000000..acdc821
--- /dev/null
+++ b/lec6/lib/domain/card.dart
@@ -0,0 +1,15 @@
+
+
+class CardData {
+ final String text;
+ final String descriptionText;
+ final String? id;
+ final String? imageUrl;
+
+ CardData(
+ this.text, {
+ required this.descriptionText,
+ this.id,
+ this.imageUrl,
+ });
+}
diff --git a/lec6/lib/domain/home.dart b/lec6/lib/domain/home.dart
new file mode 100644
index 0000000..eeeac69
--- /dev/null
+++ b/lec6/lib/domain/home.dart
@@ -0,0 +1,13 @@
+import 'package:test_app/domain/card.dart';
+
+class HomeData {
+ final List? data;
+ int? currentPage;
+ int? nextPage;
+
+ HomeData({
+ this.data,
+ this.currentPage,
+ this.nextPage,
+ });
+}
diff --git a/lec6/lib/main.dart b/lec6/lib/main.dart
new file mode 100644
index 0000000..a4134ce
--- /dev/null
+++ b/lec6/lib/main.dart
@@ -0,0 +1,38 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:test_app/data/repository/potter_repository.dart';
+import 'package:test_app/view/home_page/bloc/bloc.dart';
+import 'package:test_app/view/home_page/home_page.dart';
+import 'package:test_app/view/home_page/like_bloc/like_bloc.dart';
+
+void main() {
+ runApp(const MyApp());
+}
+
+class MyApp extends StatelessWidget {
+ const MyApp({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ title: 'My Test App',
+ debugShowCheckedModeBanner: false,
+ theme: ThemeData(
+ colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
+ useMaterial3: true,
+ ),
+ home: RepositoryProvider(
+ lazy: true,
+ create: (_) => PotterRepository(),
+ child: BlocProvider(
+ lazy: true,
+ create: (context) => HomeBloc(context.read()),
+ child: BlocProvider(
+ lazy: true,
+ create: (context) => LikeBloc(),
+ child: const MyHomePage(title: 'My Test App'),
+ ),
+ ),
+ ));
+ }
+}
diff --git a/lec6/lib/utils/debounce.dart b/lec6/lib/utils/debounce.dart
new file mode 100644
index 0000000..6e1c470
--- /dev/null
+++ b/lec6/lib/utils/debounce.dart
@@ -0,0 +1,20 @@
+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);
+ }
+}
diff --git a/lec6/lib/view/details_page/details_page.dart b/lec6/lib/view/details_page/details_page.dart
new file mode 100644
index 0000000..cbaf327
--- /dev/null
+++ b/lec6/lib/view/details_page/details_page.dart
@@ -0,0 +1,45 @@
+import 'package:flutter/material.dart';
+import 'package:test_app/domain/card.dart';
+
+class DetailsPage extends StatelessWidget {
+ final CardData data;
+
+ final Color _color = Colors.orangeAccent;
+
+ const DetailsPage(this.data, {super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(
+ backgroundColor: _color,
+ title: Text(data.text),
+ ),
+ body: Padding(
+ padding: const EdgeInsets.all(8.0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(bottom: 16),
+ child: ClipRRect(
+ borderRadius: const BorderRadius.all(Radius.circular(10)),
+ child: Image.network(data.imageUrl ?? ''),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(bottom: 4),
+ child: Text(
+ data.text,
+ style: Theme.of(context).textTheme.headlineLarge,
+ ),
+ ),
+ Text(
+ data.descriptionText,
+ style: Theme.of(context).textTheme.headlineSmall,
+ )
+ ],
+ ),
+ ));
+ }
+}
diff --git a/lec6/lib/view/home_page/bloc/bloc.dart b/lec6/lib/view/home_page/bloc/bloc.dart
new file mode 100644
index 0000000..21f541f
--- /dev/null
+++ b/lec6/lib/view/home_page/bloc/bloc.dart
@@ -0,0 +1,39 @@
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:test_app/data/repository/potter_repository.dart';
+import 'package:test_app/domain/home.dart';
+import 'package:test_app/view/home_page/bloc/events.dart';
+import 'package:test_app/view/home_page/bloc/state.dart';
+
+class HomeBloc extends Bloc {
+ final PotterRepository repository;
+
+ HomeBloc(this.repository) : super(const HomeState()) {
+ on(_onLoadData);
+ }
+
+ void _onLoadData(HomeLoadDataEvent event, Emitter emit) async {
+ final nextPage = event.nextPage ?? 1;
+
+ emit(state.copyWith(
+ isLoading: true,
+ data: nextPage == 1 ? HomeData() : null,
+ ));
+
+ String? error;
+
+ final data = await repository.loadData(
+ q: event.search,
+ page: nextPage,
+ onError: (e) => error = e,
+ );
+
+ final isNextPage = data?.nextPage != null;
+
+ if (nextPage > 1) {
+ data?.data?.insertAll(0, state.data?.data ?? []);
+ }
+
+ emit(state.copyWith(
+ isLoading: false, data: isNextPage ? data : null, error: error));
+ }
+}
diff --git a/lec6/lib/view/home_page/bloc/events.dart b/lec6/lib/view/home_page/bloc/events.dart
new file mode 100644
index 0000000..f73c9a3
--- /dev/null
+++ b/lec6/lib/view/home_page/bloc/events.dart
@@ -0,0 +1,13 @@
+abstract class HomeEvent {
+ const HomeEvent();
+}
+
+class HomeLoadDataEvent extends HomeEvent {
+ final String? search;
+ final int? nextPage;
+
+ const HomeLoadDataEvent({
+ this.search,
+ this.nextPage,
+ });
+}
diff --git a/lec6/lib/view/home_page/bloc/state.dart b/lec6/lib/view/home_page/bloc/state.dart
new file mode 100644
index 0000000..54324d7
--- /dev/null
+++ b/lec6/lib/view/home_page/bloc/state.dart
@@ -0,0 +1,33 @@
+import 'package:equatable/equatable.dart';
+import 'package:test_app/domain/home.dart';
+
+class HomeState extends Equatable {
+ final HomeData? data;
+ final bool isLoading;
+ final String? error;
+
+ const HomeState({
+ this.data,
+ this.isLoading = false,
+ this.error,
+ });
+
+ HomeState copyWith({
+ HomeData? data,
+ bool? isLoading,
+ int? currentPage,
+ String? error,
+ }) =>
+ HomeState(
+ data: data ?? this.data,
+ isLoading: isLoading ?? this.isLoading,
+ error: error ?? this.error,
+ );
+
+ @override
+ List