mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 05:25:19 +00:00
start implement generator code
This commit is contained in:
14
examples/client_app/lib/foo.dart
Normal file
14
examples/client_app/lib/foo.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
|
||||
|
||||
part 'foo.cherrypick_injectable.g.dart';
|
||||
|
||||
@Injectable()
|
||||
class Foo {
|
||||
late final String field;
|
||||
}
|
||||
|
||||
// где-то в main:
|
||||
void iniFoo() {
|
||||
$initCherrypickGenerated();
|
||||
// ... остальной код
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
import 'package:cherrypick/cherrypick.dart';
|
||||
import 'package:client_app/my_home_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cherrypick_flutter/cherrypick_flutter.dart';
|
||||
import 'my_home_page.dart';
|
||||
import 'use_case.dart';
|
||||
|
||||
void main() {
|
||||
// Здесь происходит инициализация рутового скоупа и привязка зависимостей
|
||||
CherryPick.openRootScope().installModules([
|
||||
// Создаем модуль, который будет предоставлять UseCase
|
||||
ModuleWithUseCase(),
|
||||
]);
|
||||
|
||||
runApp(
|
||||
@@ -23,19 +21,10 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Example App',
|
||||
theme: ThemeData(primarySwatch: Colors.blue),
|
||||
home: const MyHomePage(),
|
||||
return CherryPickProvider(
|
||||
child: MaterialApp(
|
||||
home: MyHomePage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Модуль для настройки зависимостей
|
||||
class ModuleWithUseCase extends Module {
|
||||
@override
|
||||
void builder(Scope currentScope) {
|
||||
// Привязка UseCase как singleton
|
||||
bind<UseCase>().toInstance(UseCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cherrypick_flutter/cherrypick_flutter.dart';
|
||||
import 'use_case.dart';
|
||||
|
||||
part 'my_home_page.cherrypick_injectable.g.dart';
|
||||
|
||||
@Injectable()
|
||||
class MyHomePage extends StatelessWidget {
|
||||
const MyHomePage({super.key});
|
||||
late final UseCase useCase;
|
||||
|
||||
// ignore: prefer_const_constructors_in_immutables
|
||||
MyHomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Разрешение зависимости UseCase из рутового скоупа
|
||||
final UseCase useCase =
|
||||
CherryPickProvider.of(context).openRootScope().resolve<UseCase>();
|
||||
|
||||
//_inject(context); // Make sure this function is called in context
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Example App'),
|
||||
|
||||
12
examples/client_app/lib/my_service.dart
Normal file
12
examples/client_app/lib/my_service.dart
Normal file
@@ -0,0 +1,12 @@
|
||||
import 'package:cherrypick_annotations/cherrypick_annotations.dart';
|
||||
|
||||
part 'my_service.cherrypick_injectable.g.dart';
|
||||
|
||||
@Injectable()
|
||||
class MyService {}
|
||||
|
||||
// где-то в main:
|
||||
void init() {
|
||||
$initCherrypickGenerated();
|
||||
// ... остальной код
|
||||
}
|
||||
Reference in New Issue
Block a user