mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-01-24 13:47:24 +00:00
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:
@@ -9,11 +9,7 @@ void main() {
|
|||||||
// Создаем модуль, который будет предоставлять UseCase
|
// Создаем модуль, который будет предоставлять UseCase
|
||||||
]);
|
]);
|
||||||
|
|
||||||
runApp(
|
runApp(const CherryPickProvider(child: MyApp()));
|
||||||
const CherryPickProvider(
|
|
||||||
child: MyApp(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
@@ -21,10 +17,6 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CherryPickProvider(
|
return CherryPickProvider(child: MaterialApp(home: MyHomePage()));
|
||||||
child: MaterialApp(
|
|
||||||
home: MyHomePage(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,8 @@ class MyHomePage extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
//_inject(context); // Make sure this function is called in context
|
//_inject(context); // Make sure this function is called in context
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(title: const Text('Example App')),
|
||||||
title: const Text('Example App'),
|
body: Center(child: Text(useCase.fetchData())),
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
child: Text(useCase.fetchData()),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class PostRepositoryImpl implements PostRepository {
|
|||||||
Future<Either<Exception, List<Post>>> getPosts() async {
|
Future<Either<Exception, List<Post>>> getPosts() async {
|
||||||
try {
|
try {
|
||||||
final posts = await api.getPosts();
|
final posts = await api.getPosts();
|
||||||
return Right(posts
|
return Right(
|
||||||
.map((e) => Post(id: e.id, title: e.title, body: e.body))
|
posts.map((e) => Post(id: e.id, title: e.title, body: e.body)).toList(),
|
||||||
.toList());
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return Left(Exception(e.toString()));
|
return Left(Exception(e.toString()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,17 @@ abstract class AppModule extends Module {
|
|||||||
@provide()
|
@provide()
|
||||||
@singleton()
|
@singleton()
|
||||||
TalkerDioLoggerSettings talkerDioLoggerSettings() => TalkerDioLoggerSettings(
|
TalkerDioLoggerSettings talkerDioLoggerSettings() => TalkerDioLoggerSettings(
|
||||||
printRequestHeaders: true,
|
printRequestHeaders: true,
|
||||||
printResponseHeaders: true,
|
printResponseHeaders: true,
|
||||||
printResponseMessage: true,
|
printResponseMessage: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
@provide()
|
@provide()
|
||||||
@singleton()
|
@singleton()
|
||||||
TalkerDioLogger talkerDioLogger(
|
TalkerDioLogger talkerDioLogger(
|
||||||
Talker talker, TalkerDioLoggerSettings settings) =>
|
Talker talker,
|
||||||
TalkerDioLogger(talker: talker, settings: settings);
|
TalkerDioLoggerSettings settings,
|
||||||
|
) => TalkerDioLogger(talker: talker, settings: settings);
|
||||||
|
|
||||||
@instance()
|
@instance()
|
||||||
int timeout() => 1000;
|
int timeout() => 1000;
|
||||||
@@ -75,12 +76,14 @@ abstract class AppModule extends Module {
|
|||||||
@provide()
|
@provide()
|
||||||
@named('TestProvideWithParams1')
|
@named('TestProvideWithParams1')
|
||||||
String testProvideWithParams1(
|
String testProvideWithParams1(
|
||||||
@named('baseUrl') String baseUrl, @params() dynamic params) =>
|
@named('baseUrl') String baseUrl,
|
||||||
"hello $params";
|
@params() dynamic params,
|
||||||
|
) => "hello $params";
|
||||||
|
|
||||||
@provide()
|
@provide()
|
||||||
@named('TestProvideAsyncWithParams1')
|
@named('TestProvideAsyncWithParams1')
|
||||||
Future<String> testProvideAsyncWithParams1(
|
Future<String> testProvideAsyncWithParams1(
|
||||||
@named('baseUrl') String baseUrl, @params() dynamic params) async =>
|
@named('baseUrl') String baseUrl,
|
||||||
"hello $params";
|
@params() dynamic params,
|
||||||
|
) async => "hello $params";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Используем safe root scope для гарантии защиты
|
// Используем safe root scope для гарантии защиты
|
||||||
CherryPick.openRootScope()
|
CherryPick.openRootScope().installModules([
|
||||||
.installModules([CoreModule(talker: talker), $AppModule()]);
|
CoreModule(talker: talker),
|
||||||
|
$AppModule(),
|
||||||
|
]);
|
||||||
|
|
||||||
runApp(MyApp(
|
runApp(MyApp(talker: talker));
|
||||||
talker: talker,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ class PostDetailsPage extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text('Post #${post.id}')),
|
appBar: AppBar(title: Text('Post #${post.id}')),
|
||||||
body: Padding(
|
body: Padding(padding: const EdgeInsets.all(16), child: Text(post.body)),
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
child: Text(post.body),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ class PostsPage extends StatelessWidget {
|
|||||||
title: Text(posts[i].title),
|
title: Text(posts[i].title),
|
||||||
subtitle: Text(posts[i].body),
|
subtitle: Text(posts[i].body),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
AutoRouter.of(context)
|
AutoRouter.of(
|
||||||
.push(PostDetailsRoute(post: posts[i]));
|
context,
|
||||||
|
).push(PostDetailsRoute(post: posts[i]));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import 'app_router.gr.dart';
|
|||||||
class AppRouter extends RootStackRouter {
|
class AppRouter extends RootStackRouter {
|
||||||
@override
|
@override
|
||||||
List<AutoRoute> get routes => [
|
List<AutoRoute> get routes => [
|
||||||
AutoRoute(page: PostsRoute.page, initial: true),
|
AutoRoute(page: PostsRoute.page, initial: true),
|
||||||
AutoRoute(page: PostDetailsRoute.page),
|
AutoRoute(page: PostDetailsRoute.page),
|
||||||
AutoRoute(page: LogsRoute.page),
|
AutoRoute(page: LogsRoute.page),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user