From 76ba761f748d9c89c695fb49ab07725a144cbb55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Mon, 11 Nov 2024 16:25:25 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BB=D1=83=D1=87=D0=B0=D0=B9=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=20=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=20=D0=B2=20=D1=82=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=B2=D0=B5=D1=82=D0=BA=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 17 ++++++--- lib/presentation/home_page/bloc/bloc.dart | 16 +++++++++ lib/presentation/home_page/bloc/events.dart | 7 ++++ lib/presentation/home_page/bloc/state.dart | 13 +++++++ pubspec.lock | 40 +++++++++++++++++++++ pubspec.yaml | 3 ++ 6 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 lib/presentation/home_page/bloc/bloc.dart create mode 100644 lib/presentation/home_page/bloc/events.dart create mode 100644 lib/presentation/home_page/bloc/state.dart diff --git a/lib/main.dart b/lib/main.dart index 9c55300..10f0ca6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart%20%20'; +import 'package:pmu_labs/data/repositories/bosses_repository.dart'; +import 'package:pmu_labs/presentation/home_page/bloc/bloc.dart'; import 'presentation/home_page/home_page.dart'; void main() { @@ -17,11 +20,15 @@ class MyApp extends StatelessWidget { colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurpleAccent), useMaterial3: true, ), - home: const MyHomePage(title: 'Яковлев Максим Григорьевич'), + home: RepositoryProvider( + lazy: true, + create: (_) => BossesRepository(), + child: BlocProvider( + lazy: false, + create: (context) => HomeBloc(context.read()), + child: const MyHomePage(title: 'Боссы Sekiro'), + ), + ), ); } } - - - - diff --git a/lib/presentation/home_page/bloc/bloc.dart b/lib/presentation/home_page/bloc/bloc.dart new file mode 100644 index 0000000..7a794fc --- /dev/null +++ b/lib/presentation/home_page/bloc/bloc.dart @@ -0,0 +1,16 @@ +import 'package:pmu_labs/data/repositories/bosses_repository.dart'; +import 'package:pmu_labs/presentation/home_page/bloc/events.dart'; +import 'package:pmu_labs/presentation/home_page/bloc/state.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class HomeBloc extends Bloc{ + final BossesRepository rep; + + HomeBloc(this.rep) : super(const HomeState()){ + on(_onLoadData); + } + + void _onLoadData(HomeLoadDataEvent event, Emitter emit){ + emit(state.copyWith(data: rep.loadData())); + } +} \ No newline at end of file diff --git a/lib/presentation/home_page/bloc/events.dart b/lib/presentation/home_page/bloc/events.dart new file mode 100644 index 0000000..7936249 --- /dev/null +++ b/lib/presentation/home_page/bloc/events.dart @@ -0,0 +1,7 @@ +abstract class HomeEvent{ + const HomeEvent(); +} + +class HomeLoadDataEvent extends HomeEvent{ + const HomeLoadDataEvent(); +} \ No newline at end of file diff --git a/lib/presentation/home_page/bloc/state.dart b/lib/presentation/home_page/bloc/state.dart new file mode 100644 index 0000000..e245dba --- /dev/null +++ b/lib/presentation/home_page/bloc/state.dart @@ -0,0 +1,13 @@ +import 'package:equatable/equatable.dart'; +import 'package:pmu_labs/domain/models/card.dart'; + +class HomeState extends Equatable{ + final Future?>? data; + + const HomeState({this.data}); + + HomeState copyWith({Future?>? data}) => HomeState(data: data ?? this.data); + + @override + List get props => [data]; +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 2fe2837..b06d1df 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -38,6 +38,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + bloc: + dependency: transitive + description: + name: bloc + sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e" + url: "https://pub.dev" + source: hosted + version: "8.1.4" boolean_selector: dependency: transitive description: @@ -206,6 +214,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + equatable: + dependency: "direct main" + description: + name: equatable + sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + url: "https://pub.dev" + source: hosted + version: "2.0.5" fake_async: dependency: transitive description: @@ -235,6 +251,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_bloc: + dependency: "direct main" + description: + name: flutter_bloc + sha256: b594505eac31a0518bdcb4b5b79573b8d9117b193cc80cc12e17d639b10aa27a + url: "https://pub.dev" + source: hosted + version: "8.1.6" flutter_lints: dependency: "direct dev" description: @@ -408,6 +432,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + nested: + dependency: transitive + description: + name: nested + sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" + url: "https://pub.dev" + source: hosted + version: "1.0.0" package_config: dependency: transitive description: @@ -440,6 +472,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.0" + provider: + dependency: transitive + description: + name: provider + sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c + url: "https://pub.dev" + source: hosted + version: "6.1.2" pub_semver: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7239e20..7cf870f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,6 +40,9 @@ dependencies: json_annotation: ^4.8.1 html: ^0.15.0 + equatable: ^2.0.5 + flutter_bloc: ^8.1.5 + dev_dependencies: flutter_test: sdk: flutter