{"id":364702,"date":"2024-05-21T02:22:33","date_gmt":"2024-05-21T02:22:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=364702"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=364702","title":{"rendered":"<span>\u0423\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0435\u0439 \u0432\u043e Flutter \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 auto_route: \u0447\u0430\u0441\u0442\u044c 2. Guards, Wrappers \u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u042e\u0440\u0438\u0439 \u041f\u0435\u0442\u0440\u043e\u0432, \u044f Flutter Team Lead <a href=\"https:\/\/friflex.com\/\"><u>\u0432 Friflex<\/u><\/a>. \u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 <a href=\"https:\/\/habr.com\/ru\/companies\/friflex\/articles\/772234\/\"><u>\u043c\u043e\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/u><\/a> \u043f\u0440\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/pub.dev\/packages\/auto_route\"><u>auto_route<\/u><\/a>. \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  <strong>Guards<\/strong> \u00ab\u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u043e\u0432\u00bb \u0438 <strong>Wrappers<\/strong> \u00ab\u043e\u0431\u0435\u0440\u0442\u043a\u0438\u00bb, \u0438 \u0441 \u0447\u0435\u043c \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u043b\u0435\u0433\u0430\u0441\u0438-\u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 <a href=\"https:\/\/pub.dev\/packages\/auto_route#migrating-to-v6\"><u>auto_rout\u0435_7<\/u><\/a>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/52d\/b27\/bee\/52db27beed4482056c30292c4ed90fc0.jpg\" width=\"1958\" height=\"1103\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/52d\/b27\/bee\/52db27beed4482056c30292c4ed90fc0.jpg\" data-blurred=\"true\"\/><\/figure>\n<h2>Guards <\/h2>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u043e <a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\"><u>\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u043d\u0438\u0433\u0430\u043c\u0438<\/u><\/a> \u0435\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0448\u0435\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043d\u0438\u0433\u0435. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0433\u043e \u043a \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.\u00a0<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u044d\u043a\u0440\u0430\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>auth_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">\/\/\/ \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0444\u0435\u0439\u043a\u043e\u0432\u044b\u0439, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \/\/\/ \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. bool isAuthorized = false;  @RoutePage() class AuthScreen extends StatelessWidget {   const AuthScreen({super.key});    @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(title: const Text('\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f')),       body: Center(           child: ElevatedButton(               onPressed: () {                 \/\/ \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435                 \/\/ \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438                 isAuthorized = true;                  \/\/ \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d                 context.pushRoute(const RootRoute());               },               child: const Text('\u0412\u043e\u0438\u0306\u0442\u0438'))),     );   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u043a\u0440\u0430\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u00ab\u0412\u043e\u0439\u0442\u0438\u00bb, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u00ab\u0444\u0435\u0439\u043a\u043e\u0432\u0443\u044e\u00bb \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0438 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u043f\u0435\u0445\u043e\u043c, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"bash\">flutter packages pub run build_runner build<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u043d\u043e\u0432\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u043a\u0430\u0440\u0442\u0443:  <\/p>\n<details class=\"spoiler\">\n<summary>app_router.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">part 'app_router.gr.dart';  @AutoRouterConfig(replaceInRouteName: 'Screen,Route') class AppRouter extends _$AppRouter {   @override   List&lt;AutoRoute> get routes => [         \/\/\/ \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439, \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442         AutoRoute(           page: RootRoute.page,           initial: true,           children: [             \/\/\/ \u0412\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b             ListBooksRoutes.routes,             AutoRoute(page: MyBooksRoute.page),             AutoRoute(page: ProfileRoute.page),           ],         ),         \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438         AutoRoute(page: AuthRoute.page),       ]; }  \/\/\/ \u041f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u043a\u0430 \u043a\u0430\u043a \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0430 class EmptyRouterPage extends AutoRouter {   const EmptyRouterPage({super.key}); } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043d\u0438\u0433:  <\/p>\n<details class=\"spoiler\">\n<summary>list_books_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class ListBooksScreen extends StatelessWidget {  const ListBooksScreen({super.key});   @override  Widget build(BuildContext context) {    return Scaffold(      appBar: AppBar(        title: const Text('\u0412\u0441\u0435 \u043a\u043d\u0438\u0433\u0438'),      ),      body: ListView.separated(        separatorBuilder: (context, index) {          return const Divider(            height: 5,          );        },        itemCount: mockListBooks.length,        itemBuilder: (context, index) {          return ListTile(            onTap: () {              \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443,              \/\/ \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u0438\u043b\u0438 \u043d\u0435\u0442              if (isAuthorized) {                context.router.push(const AboutBookRoute());              } else {                context.router.push(const AuthRoute());              }            },            title: Text(mockListBooks[index]),          );        },      ),    );  } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0415\u0441\u043b\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/659fb81472e08276d7ea64a7\" data-style=\"\" id=\"659fb81472e08276d7ea64a7\" width=\"\"><\/div>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043d\u0430\u0441 \u0432\u0441\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442. \u041d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0418 \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 if \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442.\u00a0<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 <strong>Guards<\/strong>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>Guards<\/strong> \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041f\u0440\u0438 \u043b\u044e\u0431\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 <strong>Guard<\/strong> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0430\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442.<\/p>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c <strong>Guard<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.\u00a0\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>auth_guard.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">\/\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 AutoRouteGuard \/\/\/ \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 onNavigation class AuthGuard extends AutoRouteGuard {  @override  void onNavigation(NavigationResolver resolver, StackRouter router) {    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c    if (isAuthorized) {      \/\/ \u0415\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u044d\u043a\u0440\u0430\u043d\u0443 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439      \/\/ \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0445\u043e\u0442\u0435\u043b \u043f\u0435\u0440\u0435\u0438\u0306\u0442\u0438      resolver.next(true);    } else {      \/\/ \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u044d\u043a\u0440\u0430\u043d\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438      resolver.redirect(const AuthRoute());    }  } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0442\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u00ab\u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u0430\u00bb \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>guards<\/code> \u0440\u043e\u0443\u0442\u0430 <code>AboutBookRoute<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>list_books_routes.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">abstract class ListBooksRoutes {  static final routes = AutoRoute(    page: ListBooksWrapperRoute.page,    children: [      AutoRoute(        page: ListBooksRoute.page,        initial: true,      ),      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u0449\u0438\u0442\u043d\u0438\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438      \/\/ \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043d\u0438\u0433      AutoRoute(page: AboutBookRoute.page, guards: [AuthGuard()]),      AutoRoute(page: SettingsBookRoute.page),    ],  ); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 <strong>Guard<\/strong> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442. \u041c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <strong>Guard<\/strong>  \u0438 \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>app_router.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@AutoRouterConfig(replaceInRouteName: 'Screen,Route') class AppRouter extends _$AppRouter {  @override  List&lt;AutoRoute> get routes => [        \/\/\/ \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439, \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442        AutoRoute(          page: RootRoute.page,          initial: true,          \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438          \/\/ \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e          guards: [AuthGuard()],          children: [            \/\/\/ \u0412\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b            ListBooksRoutes.routes,            AutoRoute(page: MyBooksRoute.page),            AutoRoute(page: ProfileRoute.page),          ],        ),<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\/tree\/part2_guards\"><u>\u044d\u0442\u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/u><\/a><\/p>\n<h2>Wrappers  <\/h2>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u00ab\u043e\u0431\u0435\u0440\u0442\u043e\u043a\u00bb \u0438\u043b\u0438 wrappers \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0443 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u043b\u043e\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 <code>BlocProvider<\/code>.<\/p>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0431\u043b\u043e\u043a <code>UserBloc<\/code>. \u0411\u043b\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c: \u043e\u0434\u0438\u043d Event \u0438 \u043e\u0434\u043d\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0441\u0442 Yura.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/pub.dev\/packages\/flutter_bloc\">flutter_bloc<\/a><\/p>\n<details class=\"spoiler\">\n<summary>pubspec.yaml<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">dependencies:  flutter:    sdk: flutter  auto_route: ^7.8.4  cupertino_icons: ^1.0.2  flutter_bloc: ^8.1.3<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0431\u043b\u043e\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>user_bloc.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">class UserBloc extends Bloc&lt;UserEvent, String> {  UserBloc() : super('Yura'); }   final class UserEvent {}<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c <code>UserBloc<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>BlocProvider<\/code> \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 <code>ListBooksScreen<\/code><\/p>\n<details class=\"spoiler\">\n<summary>list_book_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class ListBooksScreen extends StatelessWidget {  const ListBooksScreen({super.key});    @override  Widget build(BuildContext context) {    \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0430\u0438\u0306\u0434\u0435\u0440 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0430 UserBloc,    \/\/ \u0447\u0442\u043e\u0431\u044b \u0432 \u043d\u0435\u043c \u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e    return BlocProvider(      create: (context) => UserBloc(),      child: Scaffold(        appBar: AppBar(          title: const Text('\u0412\u0441\u0435 \u043a\u043d\u0438\u0433\u0438 ]'),        ),        body: ListView.separated(          separatorBuilder: (context, index) {            return const Divider(              height: 5,            );          },          itemCount: mockListBooks.length,          itemBuilder: (context, index) {            return ListTile(              onTap: () {                context.router.push(const AboutBookRoute());              },              \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043a\u043d\u0438\u0433\u0438              title: Text(                  \"${mockListBooks[index]} ${context.read&lt;UserBloc>().state}\"),            );          },        ),      ),    );  } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043d\u0438\u0433 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043f\u0438\u0441\u043e\u043a \u043a\u043d\u0438\u0433 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/42a\/68a\/a60\/42a68aa602a1e37e7cea72c967d173ae.png\" width=\"739\" height=\"1600\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42a\/68a\/a60\/42a68aa602a1e37e7cea72c967d173ae.png\"\/><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\/tree\/722346b08e375368bb1451d40cd705b6d93b3bd5\"><u>\u044d\u0442\u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/u><\/a><\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043d\u0438\u0433\u0435.\u00a0<\/p>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043c\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0431\u043b\u043e\u043a \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u043c\u044f \u0438\u0437 \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0431\u043b\u043e\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>about_book_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class AboutBookScreen extends StatelessWidget {  const AboutBookScreen({super.key});    @override  Widget build(BuildContext context) {    return Scaffold(      appBar: AppBar(        title: Text(          '\u041e \u043a\u043d\u0438\u0433\u0435 ${context.read&lt;UserBloc>().state}',        ),        actions: [          IconButton(            onPressed: () {              context.router.push(const SettingsBookRoute());            },            icon: const Icon(Icons.settings),          )        ],      ),    );  } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043d\u0438\u0433\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:\u00a0<\/p>\n<pre><code class=\"bash\">Exception has occurred.ProviderNotFoundException (Error: Could not find the  correct Provider&lt;UserBloc> above this AboutBookScreen Widget<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a <code>UserBloc<\/code> \u043e\u043d \u043d\u0435 \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>wrappers<\/strong>.  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 <code>ListBooksWrapperScreen<\/code>. \u042d\u0442\u043e\u0442 \u044d\u043a\u0440\u0430\u043d \u0438 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u00ab\u043e\u0431\u0435\u0440\u0442\u043a\u0438\u00bb. \u0427\u0442\u043e\u0431\u044b \u0443 \u0432\u0441\u0435\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0443\u043f \u043a<code>UserBloc<\/code>, \u043d\u0443\u0436\u043d\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>wrappedRoute <\/code>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a.<\/p>\n<details class=\"spoiler\">\n<summary>list_books_wrapper_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class ListBooksWrapperScreen extends StatelessWidget    implements AutoRouteWrapper {  const ListBooksWrapperScreen({super.key});    @override  Widget build(BuildContext context) {    return const EmptyRouterPage();  }    @override  Widget wrappedRoute(BuildContext context) {    \/\/ \u041f\u0440\u043e\u0432\u0430\u0438\u0306\u0434\u0435\u0440 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0430 UserBloc,     \/\/ \u0432\u0441\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0435\u043c\u0443    return BlocProvider(create: (context) => UserBloc(), child: this);  } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c <code>BlocProvider<\/code> \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 <code>build<\/code> \u044d\u043a\u0440\u0430\u043d\u0430 <code>ListBooksScreen, <\/code>\u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u043d\u0435\u043c \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. <code>UserBloc<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0440\u043e\u0443\u0442\u043e\u0432. <\/p>\n<details class=\"spoiler\">\n<summary>\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/659fb87e6f566b30a5aed5e7\" data-style=\"\" id=\"659fb87e6f566b30a5aed5e7\" width=\"\"><\/div>\n<\/p>\n<\/div>\n<\/details>\n<p><a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\/tree\/part2_wrappers\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a> \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<h2>\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0441 5 \u043d\u0430 7 auto_route.<\/h2>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a. \u041c\u043d\u043e\u0433\u0438\u0435 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u043a\u0430\u043a \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0441 5 \u043d\u0430 7 auto_route. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0438\u0437 \u0438\u0445 \u0447\u0438\u0441\u043b\u0430, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043d\u0435 \u0447\u0438\u0442\u0430\u0442\u044c. \u0421\u0447\u0438\u0442\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0432\u0435\u0437\u043b\u043e.\u00a0<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u0431 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u043f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 auto_route 7. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0432\u0430\u043c \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442.<\/p>\n<ol>\n<li>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <strong>Guard<\/strong> \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u043d\u0435 \u043a\u0430\u043a \u0442\u0438\u043f:<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>auto_route 5<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">AutoRoute(page: AuthScreen, guards: [AuthGuard]),<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>auto_route 7<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">AutoRoute(page: AuthRoute.page, guards: [AuthGuard()]),<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<ol start=\"2\">\n<li>\n<p><strong>Guard<\/strong> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0430\u0434\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <code>AppRouter<\/code>.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>auto_route 5<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">class AppRouter extends _$AppRouter {  AppRouter({required super.authGuard}); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>auto_route 7<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">class AppRouter extends _$AppRouter {}<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<ol start=\"3\">\n<li>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u00a0 auto_route 5 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u0440\u0442\u0443 \u044d\u043a\u0440\u0430\u043d\u043e\u0432 \u0438 \u0438\u0437 \u043d\u0435\u0435 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b\u0430\u0441\u044c \u043a\u0430\u0440\u0442\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430. \u0412 auto_route 7 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u044d\u043a\u0440\u0430\u043d\u043e\u0432 <code>@RoutePage()<\/code>, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0445 \u043a\u0430\u0440\u0442\u0443.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>auto_route 5<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">part 'app_router.gr.dart';   @AdaptiveAutoRouter(  replaceInRouteName: 'Screen,Route',  routes: &lt;AutoRoute>[    AutoRoute(      path: '\/',      initial: true,      page: RootScreen,      children: [        AutoRoute(page: HomeScreen),        AutoRoute(page: ProductScreen),        FlowRoute.routers,      ],    ),    AutoRoute(page: AuthScreen, guards: [AuthGuard]),    AutoRoute(page: LoginScreen),  ], ) class AppRouter extends _$AppRouter {  AppRouter({required super.authGuard}); } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>auto_route 7<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class AuthScreen extends StatelessWidget {  const AuthScreen({super.key});    @override  Widget build(BuildContext context) {    return Scaffold(      appBar: AppBar(title: const Text('AuthScreen')),    );  } }  @AutoRouterConfig(  replaceInRouteName: 'Screen,Route', ) class AppRouter extends _$AppRouter {  @override  RouteType get defaultRouteType => const RouteType.adaptive();  @override  final List&lt;AutoRoute> routes = [    AutoRoute(path: '\/', page: RootRoute.page, children: [      AutoRoute(        page: HomeRoute.page,      ),      AutoRoute(page: ProductRoute.page),      FlowRoute.routers    ]),    AutoRoute(page: AuthRoute.page, guards: [AuthGuard()]),    AutoRoute(page: LoginRoute.page),  ]; } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<ol start=\"4\">\n<li>\n<p>\u0412 auto_route 7 \u043d\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 <code>EmptyRouterPage<\/code> \u0438 <code>EmptyRouterScreen<\/code>. \u0412\u043c\u0435\u0441\u0442\u043e\u00a0 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u00a0 <code>AutoRouter<\/code><\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0441\u0441 \u00ab\u043e\u0431\u0435\u0440\u0442\u043e\u043a\u00bb AutoRouteWrapper \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0430 \u043d\u0435 \u043c\u0438\u043a\u0441\u043e\u0432\u0430\u0442\u044c.<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>auto_route 5<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">class FlowWrapperScreen extends StatelessWidget with AutoRouteWrapper<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>auto_route_7<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class FlowWrapperScreen extends StatelessWidget           implements AutoRouteWrapper<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0440\u043e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/petrovyuri\/mitap_migration_autoroute\"><u>\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438<\/u><\/a>.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. \u0415\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c: \u044f \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c auto_route \u0432 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. \u041b\u0443\u0447\u0448\u0435 \u043f\u0440\u0438\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435\u0441\u044c \u043a <a href=\"https:\/\/pub.dev\/packages\/go_router\"><u>go_router<\/u><\/a> \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Flutter. \u041d\u043e \u0435\u0441\u043b\u0438 \u0443\u0436 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0438 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 auto_route, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u0430.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/784924\/\"> https:\/\/habr.com\/ru\/articles\/784924\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u042e\u0440\u0438\u0439 \u041f\u0435\u0442\u0440\u043e\u0432, \u044f Flutter Team Lead <a href=\"https:\/\/friflex.com\/\"><u>\u0432 Friflex<\/u><\/a>. \u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 <a href=\"https:\/\/habr.com\/ru\/companies\/friflex\/articles\/772234\/\"><u>\u043c\u043e\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/u><\/a> \u043f\u0440\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/pub.dev\/packages\/auto_route\"><u>auto_route<\/u><\/a>. \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c  <strong>Guards<\/strong> \u00ab\u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u043e\u0432\u00bb \u0438 <strong>Wrappers<\/strong> \u00ab\u043e\u0431\u0435\u0440\u0442\u043a\u0438\u00bb, \u0438 \u0441 \u0447\u0435\u043c \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0432 \u043b\u0435\u0433\u0430\u0441\u0438-\u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u043d\u0430 <a href=\"https:\/\/pub.dev\/packages\/auto_route#migrating-to-v6\"><u>auto_rout\u0435_7<\/u><\/a>.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>Guards <\/h2>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u043f\u043e <a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\"><u>\u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u043a\u043d\u0438\u0433\u0430\u043c\u0438<\/u><\/a> \u0435\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0448\u0435\u043b \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043d\u0438\u0433\u0435. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0433\u043e \u043a \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.\u00a0<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u044d\u043a\u0440\u0430\u043d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>auth_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">\/\/\/ \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0444\u0435\u0439\u043a\u043e\u0432\u044b\u0439, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \/\/\/ \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. bool isAuthorized = false;  @RoutePage() class AuthScreen extends StatelessWidget {   const AuthScreen({super.key});    @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(title: const Text('\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f')),       body: Center(           child: ElevatedButton(               onPressed: () {                 \/\/ \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0435 \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435                 \/\/ \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438                 isAuthorized = true;                  \/\/ \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d                 context.pushRoute(const RootRoute());               },               child: const Text('\u0412\u043e\u0438\u0306\u0442\u0438'))),     );   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u044d\u043a\u0440\u0430\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u00ab\u0412\u043e\u0439\u0442\u0438\u00bb, \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u00ab\u0444\u0435\u0439\u043a\u043e\u0432\u0443\u044e\u00bb \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e, \u0438 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u043f\u0435\u0445\u043e\u043c, \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"bash\">flutter packages pub run build_runner build<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u043d\u043e\u0432\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430 \u043a\u0430\u0440\u0442\u0443:  <\/p>\n<details class=\"spoiler\">\n<summary>app_router.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">part 'app_router.gr.dart';  @AutoRouterConfig(replaceInRouteName: 'Screen,Route') class AppRouter extends _$AppRouter {   @override   List&lt;AutoRoute> get routes => [         \/\/\/ \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439, \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442         AutoRoute(           page: RootRoute.page,           initial: true,           children: [             \/\/\/ \u0412\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b             ListBooksRoutes.routes,             AutoRoute(page: MyBooksRoute.page),             AutoRoute(page: ProfileRoute.page),           ],         ),         \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438         AutoRoute(page: AuthRoute.page),       ]; }  \/\/\/ \u041f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442, \u043d\u0443\u0436\u0435\u043d \u043f\u043e\u043a\u0430 \u043a\u0430\u043a \u0437\u0430\u0433\u043b\u0443\u0448\u043a\u0430 class EmptyRouterPage extends AutoRouter {   const EmptyRouterPage({super.key}); } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043d\u0438\u0433:  <\/p>\n<details class=\"spoiler\">\n<summary>list_books_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class ListBooksScreen extends StatelessWidget {  const ListBooksScreen({super.key});   @override  Widget build(BuildContext context) {    return Scaffold(      appBar: AppBar(        title: const Text('\u0412\u0441\u0435 \u043a\u043d\u0438\u0433\u0438'),      ),      body: ListView.separated(        separatorBuilder: (context, index) {          return const Divider(            height: 5,          );        },        itemCount: mockListBooks.length,        itemBuilder: (context, index) {          return ListTile(            onTap: () {              \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443,              \/\/ \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u0438\u043b\u0438 \u043d\u0435\u0442              if (isAuthorized) {                context.router.push(const AboutBookRoute());              } else {                context.router.push(const AuthRoute());              }            },            title: Text(mockListBooks[index]),          );        },      ),    );  } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0415\u0441\u043b\u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/659fb81472e08276d7ea64a7\" data-style=\"\" id=\"659fb81472e08276d7ea64a7\" width=\"\"><\/div>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043d\u0430\u0441 \u0432\u0441\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442. \u041d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0441\u0442\u0430\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0418 \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u044b\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0438\u0441\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 if \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442.\u00a0<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0440\u0430\u0437 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b\u0438 <strong>Guards<\/strong>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>Guards<\/strong> \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u041f\u0440\u0438 \u043b\u044e\u0431\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0432 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 <strong>Guard<\/strong> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0441\u0442\u0430\u0442\u0443\u0441 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0435\u0434\u0438\u0440\u0435\u043a\u0442 \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0430\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442.<\/p>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c <strong>Guard<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.\u00a0\u00a0<\/p>\n<details class=\"spoiler\">\n<summary>auth_guard.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">\/\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 AutoRouteGuard \/\/\/ \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 onNavigation class AuthGuard extends AutoRouteGuard {  @override  void onNavigation(NavigationResolver resolver, StackRouter router) {    \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c    if (isAuthorized) {      \/\/ \u0415\u0441\u043b\u0438 \u0434\u0430, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u044d\u043a\u0440\u0430\u043d\u0443 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439      \/\/ \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0445\u043e\u0442\u0435\u043b \u043f\u0435\u0440\u0435\u0438\u0306\u0442\u0438      resolver.next(true);    } else {      \/\/ \u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u044d\u043a\u0440\u0430\u043d\u0443 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438      resolver.redirect(const AuthRoute());    }  } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0442\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u00ab\u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u0430\u00bb \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>guards<\/code> \u0440\u043e\u0443\u0442\u0430 <code>AboutBookRoute<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>list_books_routes.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">abstract class ListBooksRoutes {  static final routes = AutoRoute(    page: ListBooksWrapperRoute.page,    children: [      AutoRoute(        page: ListBooksRoute.page,        initial: true,      ),      \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0437\u0430\u0449\u0438\u0442\u043d\u0438\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438      \/\/ \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043d\u0438\u0433      AutoRoute(page: AboutBookRoute.page, guards: [AuthGuard()]),      AutoRoute(page: SettingsBookRoute.page),    ],  ); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 <strong>Guard<\/strong> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442, \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0438\u043b\u0438 \u043d\u0435\u0442. \u041c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <strong>Guard<\/strong>  \u0438 \u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442. \u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432\u044b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>app_router.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@AutoRouterConfig(replaceInRouteName: 'Screen,Route') class AppRouter extends _$AppRouter {  @override  List&lt;AutoRoute> get routes => [        \/\/\/ \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439, \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442        AutoRoute(          page: RootRoute.page,          initial: true,          \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0445\u0440\u0430\u043d\u043d\u0438\u043a\u0430 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438          \/\/ \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e          guards: [AuthGuard()],          children: [            \/\/\/ \u0412\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b            ListBooksRoutes.routes,            AutoRoute(page: MyBooksRoute.page),            AutoRoute(page: ProfileRoute.page),          ],        ),<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\/tree\/part2_guards\"><u>\u044d\u0442\u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/u><\/a><\/p>\n<h2>Wrappers  <\/h2>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u00ab\u043e\u0431\u0435\u0440\u0442\u043e\u043a\u00bb \u0438\u043b\u0438 wrappers \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0443 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u043b\u043e\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 <code>BlocProvider<\/code>.<\/p>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0431\u043b\u043e\u043a <code>UserBloc<\/code>. \u0411\u043b\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c: \u043e\u0434\u0438\u043d Event \u0438 \u043e\u0434\u043d\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0442\u0435\u043a\u0441\u0442 Yura.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/pub.dev\/packages\/flutter_bloc\">flutter_bloc<\/a><\/p>\n<details class=\"spoiler\">\n<summary>pubspec.yaml<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"yaml\">dependencies:  flutter:    sdk: flutter  auto_route: ^7.8.4  cupertino_icons: ^1.0.2  flutter_bloc: ^8.1.3<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0431\u043b\u043e\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>user_bloc.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">class UserBloc extends Bloc&lt;UserEvent, String> {  UserBloc() : super('Yura'); }   final class UserEvent {}<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c <code>UserBloc<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>BlocProvider<\/code> \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 <code>ListBooksScreen<\/code><\/p>\n<details class=\"spoiler\">\n<summary>list_book_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class ListBooksScreen extends StatelessWidget {  const ListBooksScreen({super.key});    @override  Widget build(BuildContext context) {    \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0430\u0438\u0306\u0434\u0435\u0440 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0430 UserBloc,    \/\/ \u0447\u0442\u043e\u0431\u044b \u0432 \u043d\u0435\u043c \u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e    return BlocProvider(      create: (context) => UserBloc(),      child: Scaffold(        appBar: AppBar(          title: const Text('\u0412\u0441\u0435 \u043a\u043d\u0438\u0433\u0438 ]'),        ),        body: ListView.separated(          separatorBuilder: (context, index) {            return const Divider(              height: 5,            );          },          itemCount: mockListBooks.length,          itemBuilder: (context, index) {            return ListTile(              onTap: () {                context.router.push(const AboutBookRoute());              },              \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043a\u043d\u0438\u0433\u0438              title: Text(                  \"${mockListBooks[index]} ${context.read&lt;UserBloc>().state}\"),            );          },        ),      ),    );  } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043d\u0438\u0433 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043f\u0438\u0441\u043e\u043a \u043a\u043d\u0438\u0433 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\/tree\/722346b08e375368bb1451d40cd705b6d93b3bd5\"><u>\u044d\u0442\u043e\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/u><\/a><\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043d\u0438\u0433\u0435.\u00a0<\/p>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u043a\u0430\u043a \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043c\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0431\u043b\u043e\u043a \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u0430 \u043f\u043e\u0442\u043e\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u043c\u044f \u0438\u0437 \u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0435\u0441\u044c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0431\u043b\u043e\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>about_book_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class AboutBookScreen extends StatelessWidget {  const AboutBookScreen({super.key});    @override  Widget build(BuildContext context) {    return Scaffold(      appBar: AppBar(        title: Text(          '\u041e \u043a\u043d\u0438\u0433\u0435 ${context.read&lt;UserBloc>().state}',        ),        actions: [          IconButton(            onPressed: () {              context.router.push(const SettingsBookRoute());            },            icon: const Icon(Icons.settings),          )        ],      ),    );  } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u043e \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043d\u0438\u0433\u0435 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:\u00a0<\/p>\n<pre><code class=\"bash\">Exception has occurred.ProviderNotFoundException (Error: Could not find the  correct Provider&lt;UserBloc> above this AboutBookScreen Widget<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a <code>UserBloc<\/code> \u043e\u043d \u043d\u0435 \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>wrappers<\/strong>.  \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 <code>ListBooksWrapperScreen<\/code>. \u042d\u0442\u043e\u0442 \u044d\u043a\u0440\u0430\u043d \u0438 \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u00ab\u043e\u0431\u0435\u0440\u0442\u043a\u0438\u00bb. \u0427\u0442\u043e\u0431\u044b \u0443 \u0432\u0441\u0435\u0445 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u0432 \u0431\u044b\u043b \u0434\u043e\u0441\u0442\u0443\u043f \u043a<code>UserBloc<\/code>, \u043d\u0443\u0436\u043d\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>wrappedRoute <\/code>\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u043a.<\/p>\n<details class=\"spoiler\">\n<summary>list_books_wrapper_screen.dart<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"dart\">@RoutePage() class ListBooksWrapperScreen extends StatelessWidget    implements AutoRouteWrapper {  const ListBooksWrapperScreen({super.key});    @override  Widget build(BuildContext context) {    return const EmptyRouterPage();  }    @override  Widget wrappedRoute(BuildContext context) {    \/\/ \u041f\u0440\u043e\u0432\u0430\u0438\u0306\u0434\u0435\u0440 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0430 UserBloc,     \/\/ \u0432\u0441\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0435\u043c\u0443    return BlocProvider(create: (context) => UserBloc(), child: this);  } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c <code>BlocProvider<\/code> \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430 <code>build<\/code> \u044d\u043a\u0440\u0430\u043d\u0430 <code>ListBooksScreen, <\/code>\u0442\u0430\u043a \u043a\u0430\u043a \u0442\u0435\u043f\u0435\u0440\u044c \u0432 \u043d\u0435\u043c \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0442\u043e \u0432\u0441\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. <code>UserBloc<\/code> \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0440\u043e\u0443\u0442\u043e\u0432. <\/p>\n<details class=\"spoiler\">\n<summary>\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/659fb87e6f566b30a5aed5e7\" data-style=\"\" id=\"659fb87e6f566b30a5aed5e7\" width=\"\"><\/div>\n<\/p>\n<\/div>\n<\/details>\n<p><a href=\"https:\/\/github.com\/petrovyuri\/auto_route_tutorial\/tree\/part2_wrappers\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a> \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438.<\/p>\n<h2>\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0441 5 \u043d\u0430 7 auto_route.<\/h2>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a. \u041c\u043d\u043e\u0433\u0438\u0435 \u0432<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-364702","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=364702"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364702\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=364702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=364702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=364702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}