{"id":381044,"date":"2024-06-29T03:26:40","date_gmt":"2024-06-29T03:26:40","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=381044"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=381044","title":{"rendered":"<span>Flutter ConstWidget<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/347\/bc4\/240\/347bc424029e258318de6c8ab17c9052.png\" width=\"2400\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/347\/bc4\/240\/347bc424029e258318de6c8ab17c9052.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u043a\u0430<\/h2>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043c\u0430\u043b\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0430 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432. \u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0434\u0443\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u043e \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u043a\u0440\u0443\u0433 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0438 \u0441 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. <a href=\"https:\/\/docs.flutter.dev\/development\/data-and-backend\/state-mgmt\/options\" rel=\"noopener noreferrer nofollow\">State management<\/a> \u041a\u0430\u043a? \u041a\u043e\u0433\u0434\u0430? \u041f\u043e\u0447\u0435\u043c\u0443? \u041a\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c? \u041b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\/\u0434\u0440\u0435\u0432\u0430 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432? \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412\u043e\u043f\u0440\u043e\u0441 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0447\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0441 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438, \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438, \u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e \u0442\u043e \u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043b\u0443\u0447\u0448\u0435 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435. \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u043a \u043b\u044e\u0431\u043e\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0443, \u0435\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438 \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0432\u0438\u0434\u0436\u0435\u0442. <\/p>\n<h2>\u041a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439?<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u043b\u0433\u0438\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432, \u043c\u043d\u0435 \u043f\u043e\u0434 \u0440\u0443\u043a\u0443 \u043f\u043e\u043f\u0430\u043b\u0430 \u0447\u0443\u0434\u0435\u0441\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 &#8212; <a href=\"https:\/\/pub.dev\/packages\/should_rebuild\" rel=\"noopener noreferrer nofollow\">should_rebuild<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438 \u043d\u0430 \u043c\u043e\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c &#171;\u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e&#187; \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430, \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0432\u0438\u0434\u0436\u0435\u0442 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/blob\/master\/lib\/components\/should_rebuild_widget.dart\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"dart\">import 'package:flutter\/material.dart';  typedef ShouldRebuildFunction&lt;T> = bool Function(T oldWidget, T newWidget);  class ShouldRebuild&lt;T extends Widget> extends StatefulWidget {   final T child;   final ShouldRebuildFunction&lt;T>? shouldRebuild;   ShouldRebuild({required this.child, this.shouldRebuild});   @override   _ShouldRebuildState createState() => _ShouldRebuildState&lt;T>(); }  class _ShouldRebuildState&lt;T extends Widget> extends State&lt;ShouldRebuild> {   @override   ShouldRebuild&lt;T> get widget => super.widget as ShouldRebuild&lt;T>;   T? oldWidget;   @override   Widget build(BuildContext context) {     final T newWidget = widget.child;     if (this.oldWidget == null ||         (widget.shouldRebuild == null             ? true             : widget.shouldRebuild!(oldWidget!, newWidget))) {       this.oldWidget = newWidget;     }     return oldWidget as T;   } }<\/code><\/pre>\n<p>\u0418\u0437\u0443\u0447\u0438\u0432 \u0435\u0433\u043e, \u0441\u0442\u0430\u043b\u043e \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.*<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u043c\u0430\u0440\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0430, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 &#171;\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e&#187; \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u0435 \u0432\u0430\u0448\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b \u0432 \u0431\u0438\u043b\u0434\u0435\u0440\u044b (\u0438\u043b\u0438 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043b\u044e\u0431\u044b\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c) \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0447\u044c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u044b\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0431\u043b\u043e\u043a\u0435\/\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u0440\u0435\/\u043a\u043b\u0430\u0441\u0441\u0435, \u0432\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c \u043a\u0435\u0439\u0441\u043e\u043c. \u041d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u0434\u0435\u0442\u0430\u043b\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0435\u043a\u0441\u0442, \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0438\u043b\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435).<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f. \u0410 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/blob\/master\/lib\/components\/const_widget.dart\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"dart\">import 'package:const_widget\/components\/should_rebuild_widget.dart'; import 'package:flutter\/material.dart';  class ConstWidget extends StatelessWidget {   final Widget child;   ConstWidget({required this.child});    @override   Widget build(BuildContext context) {     return ShouldRebuild(       child: child,       shouldRebuild: (n, o) {         return false;       },     );   } }<\/code><\/pre>\n<h2>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0435\u0448\u0438\u043b \u0432\u0437\u044f\u0442\u044c \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 Flutter \u043f\u0440\u043e\u0435\u043a\u0442. \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0438\u0434\u0436\u0435\u0442, \u0446\u0432\u0435\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <strong>build<\/strong>, \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/blob\/master\/lib\/components\/test_components.dart\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"dart\">import 'dart:math'; import 'package:flutter\/material.dart';  class RndColorContainer extends StatefulWidget {   final double h;   final double w;    RndColorContainer({     this.h = 100,     this.w = 100,   });    @override   _RndColorContainerState createState() => _RndColorContainerState(); }  class _RndColorContainerState extends State&lt;RndColorContainer> {   Color genRandomColor() {     return Color.fromRGBO(Random().nextInt(255) + 1, Random().nextInt(255) + 1,         Random().nextInt(255) + 1, 1);   }    @override   Widget build(BuildContext context) {     return Container(       decoration: BoxDecoration(         color: genRandomColor(),       ),       height: widget.h,       width: widget.w,     );   } }<\/code><\/pre>\n<p>\u041d\u0443 \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 StatefulWidget (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 MyHomePage), \u0438 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 setState((){}), \u0446\u0432\u0435\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. <\/p>\n<pre><code class=\"dart\">...    children: &lt;Widget>[             Text(               'You have pushed the button this many times:',             ),             RndColorContainer(),             Text(               '$_counter',               style: Theme.of(context).textTheme.headline4,             ),           ], ...<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c99\/196\/6ca\/c991966cab1bf5e338d2d9a03a2ac6c2.gif\" width=\"366\" height=\"732\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c99\/196\/6ca\/c991966cab1bf5e338d2d9a03a2ac6c2.gif\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043e\u0431\u0435\u0440\u043d\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 ConstWidget, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 &#171;\u043f\u043e\u0447\u0442\u0438&#187; \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c. <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/commit\/513907c2ae2e570a5dc74a7fc00221f343d90e77\" rel=\"noopener noreferrer nofollow\">commit*.<\/a><\/p>\n<pre><code class=\"dart\">...    children: &lt;Widget>[             Text(               'You have pushed the button this many times:',             ),             ConstWidget(               child: RndColorContainer(),             ),             Text(               '$_counter',               style: Theme.of(context).textTheme.headline4,             ),           ], ...<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d7c\/e59\/b5e\/d7ce59b5e30e15309d71ef5042dd0c6e.gif\" alt=\"\" title=\"\" width=\"366\" height=\"732\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d7c\/e59\/b5e\/d7ce59b5e30e15309d71ef5042dd0c6e.gif\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0442\u0440\u0435\u0441\u0441 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 1000 \u0442\u0430\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432\u043e\u0442, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0435\u0442 flutter Dev tool \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0436\u0435\u0442\u0430, \u0438 \u0431\u0435\u0437 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"dart\">            Wrap(               children: [                 ...List.generate(                   1000,                   (index) => RndColorContainer(                     h: 10,                     w: 10,                   ),                 ),               ],             ),<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c26\/a2f\/e5d\/c26a2fe5d0730bcf43c533ec9f65236a.jpg\" alt=\"\u0411\u0435\u0437 ConstWidget (38 FPS)\" title=\"\u0411\u0435\u0437 ConstWidget (38 FPS)\" width=\"1280\" height=\"675\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c26\/a2f\/e5d\/c26a2fe5d0730bcf43c533ec9f65236a.jpg\" data-blurred=\"true\"\/><figcaption>\u0411\u0435\u0437 ConstWidget (38 FPS)<\/figcaption><\/figure>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0435\u0441\u043b\u0438 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c Wrap \u0432 ConstWidget<\/p>\n<pre><code class=\"dart\">ConstWidget(               child: Wrap(                 children: [                   ...List.generate(                     1000,                     (index) => RndColorContainer(                       h: 10,                       w: 10,                     ),                   ),                 ],               ),             ),<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/1b0\/35d\/4a9\/1b035d4a9508de1992db11bf6f340060.jpg\" alt=\"\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0441\u0442\u0430\u043b\u043e 57 FPS. \" title=\"\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0441\u0442\u0430\u043b\u043e 57 FPS. \" width=\"1280\" height=\"672\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1b0\/35d\/4a9\/1b035d4a9508de1992db11bf6f340060.jpg\" data-blurred=\"true\"\/><figcaption>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0441\u0442\u0430\u043b\u043e 57 FPS. <\/figcaption><\/figure>\n<h2>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e<\/h2>\n<p><a href=\"https:\/\/github.com\/GridXSeven\/const_widget\" rel=\"noopener noreferrer nofollow\">Source code<\/a><br \/>\u041e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/pub.dev\/packages\/should_rebuild\" rel=\"noopener noreferrer nofollow\">should_rebuild<\/a>, <a href=\"https:\/\/developpaper.com\/the-ultimate-solution-to-prevent-widget-rebuild-by-flutter\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a>.<\/p>\n<h2>P.S.<\/h2>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439, \u0440\u0430\u043d\u0435\u0435 \u043c\u043d\u0435 \u043d\u0435 \u0434\u043e\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0435\u0439\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u0432\u043e Flutter. \u041f\u043e\u0441\u043b\u0435 \u0443\u0432\u0438\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0443 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441. \u0414\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438, \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438 \u0443\u0440\u043e\u0432\u043d\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u044e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432. \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0441\u044c \u0434\u0430\u043b\u044c\u0448\u0435.<\/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\/592007\/\"> https:\/\/habr.com\/ru\/articles\/592007\/<\/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<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u043a\u0430<\/h2>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0437\u0430\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043c\u0430\u043b\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0430 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u043d\u0435\u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432. \u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0434\u0443\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u043e \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u043a\u0440\u0443\u0433 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0438 \u0441 \u0431\u043e\u043b\u0435\u0435 \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438. <a href=\"https:\/\/docs.flutter.dev\/development\/data-and-backend\/state-mgmt\/options\" rel=\"noopener noreferrer nofollow\">State management<\/a> \u041a\u0430\u043a? \u041a\u043e\u0433\u0434\u0430? \u041f\u043e\u0447\u0435\u043c\u0443? \u041a\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c? \u041b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\/\u0434\u0440\u0435\u0432\u0430 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432? \u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412\u043e\u043f\u0440\u043e\u0441 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u0447\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0441 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u043c\u0438, \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438, \u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e \u0442\u043e \u043a\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043b\u0443\u0447\u0448\u0435 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435. \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u043a \u043b\u044e\u0431\u043e\u043c\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0443, \u0435\u043c\u0443 \u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0438 \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0432\u0438\u0434\u0436\u0435\u0442. <\/p>\n<h2>\u041a\u0430\u043a \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439?<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u043b\u0433\u0438\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432, \u043c\u043d\u0435 \u043f\u043e\u0434 \u0440\u0443\u043a\u0443 \u043f\u043e\u043f\u0430\u043b\u0430 \u0447\u0443\u0434\u0435\u0441\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 &#8212; <a href=\"https:\/\/pub.dev\/packages\/should_rebuild\" rel=\"noopener noreferrer nofollow\">should_rebuild<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438 \u043d\u0430 \u043c\u043e\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c &#171;\u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e&#187; \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430, \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0432\u0438\u0434\u0436\u0435\u0442 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/blob\/master\/lib\/components\/should_rebuild_widget.dart\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"dart\">import 'package:flutter\/material.dart';  typedef ShouldRebuildFunction&lt;T> = bool Function(T oldWidget, T newWidget);  class ShouldRebuild&lt;T extends Widget> extends StatefulWidget {   final T child;   final ShouldRebuildFunction&lt;T>? shouldRebuild;   ShouldRebuild({required this.child, this.shouldRebuild});   @override   _ShouldRebuildState createState() => _ShouldRebuildState&lt;T>(); }  class _ShouldRebuildState&lt;T extends Widget> extends State&lt;ShouldRebuild> {   @override   ShouldRebuild&lt;T> get widget => super.widget as ShouldRebuild&lt;T>;   T? oldWidget;   @override   Widget build(BuildContext context) {     final T newWidget = widget.child;     if (this.oldWidget == null ||         (widget.shouldRebuild == null             ? true             : widget.shouldRebuild!(oldWidget!, newWidget))) {       this.oldWidget = newWidget;     }     return oldWidget as T;   } }<\/code><\/pre>\n<p>\u0418\u0437\u0443\u0447\u0438\u0432 \u0435\u0433\u043e, \u0441\u0442\u0430\u043b\u043e \u044f\u0441\u043d\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.*<\/p>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u043c\u0430\u0440\u043a\u0430<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0430, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 &#171;\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e&#187; \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u0441\u0435 \u0432\u0430\u0448\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b \u0432 \u0431\u0438\u043b\u0434\u0435\u0440\u044b (\u0438\u043b\u0438 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043b\u044e\u0431\u044b\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c) \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0447\u044c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u044b\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0431\u043b\u043e\u043a\u0435\/\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0435\u0440\u0435\/\u043a\u043b\u0430\u0441\u0441\u0435, \u0432\u044b \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u0442\u0430\u043a\u0438\u043c \u043a\u0435\u0439\u0441\u043e\u043c. \u041d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0432\u0441\u0451 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0439 \u0434\u0435\u0442\u0430\u043b\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0435\u043a\u0441\u0442, \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u0438\u043b\u0438 \u0447\u0442\u043e \u0438\u043d\u043e\u0435).<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f. \u0410 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/blob\/master\/lib\/components\/const_widget.dart\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"dart\">import 'package:const_widget\/components\/should_rebuild_widget.dart'; import 'package:flutter\/material.dart';  class ConstWidget extends StatelessWidget {   final Widget child;   ConstWidget({required this.child});    @override   Widget build(BuildContext context) {     return ShouldRebuild(       child: child,       shouldRebuild: (n, o) {         return false;       },     );   } }<\/code><\/pre>\n<h2>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0435\u0448\u0438\u043b \u0432\u0437\u044f\u0442\u044c \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0439 Flutter \u043f\u0440\u043e\u0435\u043a\u0442. \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0438\u0434\u0436\u0435\u0442, \u0446\u0432\u0435\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 <strong>build<\/strong>, \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/blob\/master\/lib\/components\/test_components.dart\" rel=\"noopener noreferrer nofollow\">\u0442\u0430\u043a<\/a>:<\/p>\n<pre><code class=\"dart\">import 'dart:math'; import 'package:flutter\/material.dart';  class RndColorContainer extends StatefulWidget {   final double h;   final double w;    RndColorContainer({     this.h = 100,     this.w = 100,   });    @override   _RndColorContainerState createState() => _RndColorContainerState(); }  class _RndColorContainerState extends State&lt;RndColorContainer> {   Color genRandomColor() {     return Color.fromRGBO(Random().nextInt(255) + 1, Random().nextInt(255) + 1,         Random().nextInt(255) + 1, 1);   }    @override   Widget build(BuildContext context) {     return Container(       decoration: BoxDecoration(         color: genRandomColor(),       ),       height: widget.h,       width: widget.w,     );   } }<\/code><\/pre>\n<p>\u041d\u0443 \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0432 StatefulWidget (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 MyHomePage), \u0438 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 setState((){}), \u0446\u0432\u0435\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. <\/p>\n<pre><code class=\"dart\">...    children: &lt;Widget>[             Text(               'You have pushed the button this many times:',             ),             RndColorContainer(),             Text(               '$_counter',               style: Theme.of(context).textTheme.headline4,             ),           ], ...<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u043e, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043e\u0431\u0435\u0440\u043d\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 ConstWidget, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441\u0442\u0430\u043d\u0435\u0442 &#171;\u043f\u043e\u0447\u0442\u0438&#187; \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c. <a href=\"https:\/\/github.com\/GridXSeven\/const_widget\/commit\/513907c2ae2e570a5dc74a7fc00221f343d90e77\" rel=\"noopener noreferrer nofollow\">commit*.<\/a><\/p>\n<pre><code class=\"dart\">...    children: &lt;Widget>[             Text(               'You have pushed the button this many times:',             ),             ConstWidget(               child: RndColorContainer(),             ),             Text(               '$_counter',               style: Theme.of(context).textTheme.headline4,             ),           ], ...<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u0442\u0440\u0435\u0441\u0441 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0443 \u043d\u0430\u0441 1000 \u0442\u0430\u043a\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432\u043e\u0442, \u0447\u0442\u043e \u043f\u043e\u043a\u0430\u0436\u0435\u0442 flutter Dev tool \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0436\u0435\u0442\u0430, \u0438 \u0431\u0435\u0437 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<pre><code class=\"dart\">            Wrap(               children: [                 ...List.generate(                   1000,                   (index) => RndColorContainer(                     h: 10,                     w: 10,                   ),                 ),               ],             ),<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>\u0411\u0435\u0437 ConstWidget (38 FPS)<\/figcaption><\/figure>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0435\u0441\u043b\u0438 \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c Wrap \u0432 ConstWidget<\/p>\n<pre><code class=\"dart\">ConstWidget(               child: Wrap(                 children: [                   ...List.generate(                     1000,                     (index) => RndColorContainer(                       h: 10,                       w: 10,                     ),                   ),                 ],               ),             ),<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u0441\u0442\u0430\u043b\u043e 57 FPS. <\/figcaption><\/figure>\n<h2>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e<\/h2>\n<p><a href=\"https:\/\/github.com\/GridXSeven\/const_widget\" rel=\"noopener noreferrer nofollow\">Source code<\/a><br \/>\u041e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 <a href=\"https:\/\/pub.dev\/packages\/should_rebuild\" rel=\"noopener noreferrer nofollow\">should_rebuild<\/a>, <a href=\"https:\/\/developpaper.com\/the-ultimate-solution-to-prevent-widget-rebuild-by-flutter\/\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a>.<\/p>\n<h2>P.S.<\/h2>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439, \u0440\u0430\u043d\u0435\u0435 \u043c\u043d\u0435 \u043d\u0435 \u0434\u043e\u0432\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0442\u0435\u0439\u0442 \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u0432\u043e Flutter. \u041f\u043e\u0441\u043b\u0435 \u0443\u0432\u0438\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0443 \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441. \u0414\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438, \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438 \u0443\u0440\u043e\u0432\u043d\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u044e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432. \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0441\u044c \u0434\u0430\u043b\u044c\u0448\u0435.<\/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\/592007\/\"> https:\/\/habr.com\/ru\/articles\/592007\/<\/a><br \/><\/br><\/br><\/p>\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-381044","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381044","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=381044"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/381044\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=381044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=381044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=381044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}