feat(examples): update client_app and postly implementation details

- Refactored and updated pages, router, DI modules, and feature implementations in both example projects:
  - client_app: main.dart and my_home_page.dart updated for improved navigation and structure.
  - postly: updated DI wiring, presentation pages, repository implementation, and routing logic.
- Applied small improvements and code consistency changes in the examples.

docs: add new documentation assets and benchmarking script

BREAKING CHANGE:
Examples now reflect the latest changes in the DI framework and are ready for Dart 3.8+ and cherrypick_generator element2 API compatibility.
This commit is contained in:
Sergey Penkovsky
2025-09-09 17:30:57 +03:00
parent eb6d786600
commit 0c1ef70b73
8 changed files with 33 additions and 44 deletions

View File

@@ -9,11 +9,7 @@ void main() {
// Создаем модуль, который будет предоставлять UseCase
]);
runApp(
const CherryPickProvider(
child: MyApp(),
),
);
runApp(const CherryPickProvider(child: MyApp()));
}
class MyApp extends StatelessWidget {
@@ -21,10 +17,6 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return CherryPickProvider(
child: MaterialApp(
home: MyHomePage(),
),
);
return CherryPickProvider(child: MaterialApp(home: MyHomePage()));
}
}

View File

@@ -11,12 +11,8 @@ class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) {
//_inject(context); // Make sure this function is called in context
return Scaffold(
appBar: AppBar(
title: const Text('Example App'),
),
body: Center(
child: Text(useCase.fetchData()),
),
appBar: AppBar(title: const Text('Example App')),
body: Center(child: Text(useCase.fetchData())),
);
}
}

View File

@@ -12,9 +12,9 @@ class PostRepositoryImpl implements PostRepository {
Future<Either<Exception, List<Post>>> getPosts() async {
try {
final posts = await api.getPosts();
return Right(posts
.map((e) => Post(id: e.id, title: e.title, body: e.body))
.toList());
return Right(
posts.map((e) => Post(id: e.id, title: e.title, body: e.body)).toList(),
);
} catch (e) {
return Left(Exception(e.toString()));
}

View File

@@ -15,16 +15,17 @@ abstract class AppModule extends Module {
@provide()
@singleton()
TalkerDioLoggerSettings talkerDioLoggerSettings() => TalkerDioLoggerSettings(
printRequestHeaders: true,
printResponseHeaders: true,
printResponseMessage: true,
);
printRequestHeaders: true,
printResponseHeaders: true,
printResponseMessage: true,
);
@provide()
@singleton()
TalkerDioLogger talkerDioLogger(
Talker talker, TalkerDioLoggerSettings settings) =>
TalkerDioLogger(talker: talker, settings: settings);
Talker talker,
TalkerDioLoggerSettings settings,
) => TalkerDioLogger(talker: talker, settings: settings);
@instance()
int timeout() => 1000;
@@ -75,12 +76,14 @@ abstract class AppModule extends Module {
@provide()
@named('TestProvideWithParams1')
String testProvideWithParams1(
@named('baseUrl') String baseUrl, @params() dynamic params) =>
"hello $params";
@named('baseUrl') String baseUrl,
@params() dynamic params,
) => "hello $params";
@provide()
@named('TestProvideAsyncWithParams1')
Future<String> testProvideAsyncWithParams1(
@named('baseUrl') String baseUrl, @params() dynamic params) async =>
"hello $params";
@named('baseUrl') String baseUrl,
@params() dynamic params,
) async => "hello $params";
}

View File

@@ -23,10 +23,10 @@ void main() {
}
// Используем safe root scope для гарантии защиты
CherryPick.openRootScope()
.installModules([CoreModule(talker: talker), $AppModule()]);
CherryPick.openRootScope().installModules([
CoreModule(talker: talker),
$AppModule(),
]);
runApp(MyApp(
talker: talker,
));
runApp(MyApp(talker: talker));
}

View File

@@ -12,10 +12,7 @@ class PostDetailsPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Post #${post.id}')),
body: Padding(
padding: const EdgeInsets.all(16),
child: Text(post.body),
),
body: Padding(padding: const EdgeInsets.all(16), child: Text(post.body)),
);
}
}

View File

@@ -38,8 +38,9 @@ class PostsPage extends StatelessWidget {
title: Text(posts[i].title),
subtitle: Text(posts[i].body),
onTap: () {
AutoRouter.of(context)
.push(PostDetailsRoute(post: posts[i]));
AutoRouter.of(
context,
).push(PostDetailsRoute(post: posts[i]));
},
),
),

View File

@@ -5,8 +5,8 @@ import 'app_router.gr.dart';
class AppRouter extends RootStackRouter {
@override
List<AutoRoute> get routes => [
AutoRoute(page: PostsRoute.page, initial: true),
AutoRoute(page: PostDetailsRoute.page),
AutoRoute(page: LogsRoute.page),
];
AutoRoute(page: PostsRoute.page, initial: true),
AutoRoute(page: PostDetailsRoute.page),
AutoRoute(page: LogsRoute.page),
];
}