<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Flutter on Yaohong</title><link>https://yh.timefriend.vip/tags/flutter/</link><description>Recent content in Flutter on Yaohong</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 26 Jun 2024 09:47:20 +0800</lastBuildDate><atom:link href="https://yh.timefriend.vip/tags/flutter/index.xml" rel="self" type="application/rss+xml"/><item><title>Constraint, Layout An Size On Flutter, Android, iOS And H5</title><link>https://yh.timefriend.vip/post/flutter/constraintlayoutandsizeonflutterandroidiosh5/</link><pubDate>Wed, 26 Jun 2024 09:47:20 +0800</pubDate><guid>https://yh.timefriend.vip/post/flutter/constraintlayoutandsizeonflutterandroidiosh5/</guid><description>&lt;p&gt;In Flutter, the layout principle of &amp;ldquo;Constraints go down, Sizes go up, Parent sets position&amp;rdquo; is a clear and distinct mechanism for handling the layout of widgets. When comparing this with the layout mechanisms in Android, iOS, and HTML5/CSS/JS, we find different approaches and philosophies. Let’s compare these systems to understand their similarities and differences.&lt;/p&gt;&#10;&lt;h2 id="layout-and-size-in-different-systems"&gt;&lt;strong&gt;Layout and Size in Different Systems&lt;/strong&gt;&lt;/h2&gt;&#10;&lt;h3 id="flutter"&gt;&lt;strong&gt;Flutter&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints Go Down:&lt;/strong&gt; Parent widgets send constraints to their children, specifying permissible sizes.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Sizes Go Up:&lt;/strong&gt; Children choose their size within those constraints.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Parent Sets Position:&lt;/strong&gt; Parents position children based on their size and constraints.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="android-view-system"&gt;&lt;strong&gt;Android (View System)&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Measure Phase:&lt;/strong&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Parent Determines Constraints:&lt;/strong&gt; Parent views provide measurement specifications (&lt;code&gt;MeasureSpec&lt;/code&gt;) to children.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Children Measure Size:&lt;/strong&gt; Children determine their desired size based on these specifications, including modes (&lt;code&gt;EXACTLY&lt;/code&gt;, &lt;code&gt;AT_MOST&lt;/code&gt;, &lt;code&gt;UNSPECIFIED&lt;/code&gt;).&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Layout Phase:&lt;/strong&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Parent Sets Size and Position:&lt;/strong&gt; Parents decide the final size and position of each child view using the &lt;code&gt;layout()&lt;/code&gt; method, setting exact bounds within the parent’s coordinate system.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="ios-uikit"&gt;&lt;strong&gt;iOS (UIKit)&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints (Auto Layout):&lt;/strong&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints Propagation:&lt;/strong&gt; Constraints define relationships between views, such as size ratios or alignments.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Size Determination:&lt;/strong&gt; Each view calculates its size based on these constraints and intrinsic content size.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Layout Passes:&lt;/strong&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Parent Resolves Constraints:&lt;/strong&gt; Constraints are resolved to compute the frames (positions and sizes) of views.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Frames Set Position:&lt;/strong&gt; The final position and size of each view are determined by resolving the constraints to specific frames.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="html5cssjs"&gt;&lt;strong&gt;HTML5/CSS/JS&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;CSS Box Model:&lt;/strong&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints Through CSS:&lt;/strong&gt; CSS rules (like &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;max-width&lt;/code&gt;, &lt;code&gt;min-width&lt;/code&gt;, etc.) define size constraints.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Size Computation:&lt;/strong&gt; Elements calculate their size based on CSS rules, content size, and parent constraints.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Layout Mechanisms:&lt;/strong&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Flow Layout:&lt;/strong&gt; Default document flow where elements take up available space in order.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Flexbox:&lt;/strong&gt; Parent container defines constraints and alignment for flex items, which then size themselves within these constraints.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Grid Layout:&lt;/strong&gt; Parent defines a grid structure, and child elements size and position themselves within grid areas.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Positioning:&lt;/strong&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;CSS Positioning:&lt;/strong&gt; Elements can be positioned using properties like &lt;code&gt;position&lt;/code&gt;, &lt;code&gt;top&lt;/code&gt;, &lt;code&gt;left&lt;/code&gt;, &lt;code&gt;right&lt;/code&gt;, and &lt;code&gt;bottom&lt;/code&gt;, relative to their parent or document flow.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="comparison-key-aspects"&gt;&lt;strong&gt;Comparison: Key Aspects&lt;/strong&gt;&lt;/h2&gt;&#10;&lt;h3 id="constraints-handling"&gt;&lt;strong&gt;Constraints Handling&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Flutter:&lt;/strong&gt; Constraints explicitly passed from parent to child in a hierarchical manner.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Android:&lt;/strong&gt; Constraints come from measure specs which include modes and sizes, less explicit than Flutter.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;iOS:&lt;/strong&gt; Constraints are set using Auto Layout, forming a constraint system that is resolved for size and position.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;HTML/CSS:&lt;/strong&gt; Constraints defined using CSS properties; more flexible and varied ways to specify constraints.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="size-determination"&gt;&lt;strong&gt;Size Determination&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Flutter:&lt;/strong&gt; Children determine size within provided constraints.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Android:&lt;/strong&gt; Children measure themselves based on measure specs and report back desired sizes.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;iOS:&lt;/strong&gt; Size determined by solving constraints in Auto Layout system.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;HTML/CSS:&lt;/strong&gt; Size determined by CSS rules, intrinsic content, and parent constraints.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="positioning"&gt;&lt;strong&gt;Positioning&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Flutter:&lt;/strong&gt; Parent sets position of children after size determination.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Android:&lt;/strong&gt; Parent uses &lt;code&gt;layout()&lt;/code&gt; method to set position within bounds.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;iOS:&lt;/strong&gt; Position determined by resolving constraints to frames.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;HTML/CSS:&lt;/strong&gt; Position determined by CSS properties and layout rules (flow, flexbox, grid).&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="flexibility"&gt;&lt;strong&gt;Flexibility&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Flutter:&lt;/strong&gt; Clear and flexible constraint-based system.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Android:&lt;/strong&gt; More rigid with fixed measure/layout phases.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;iOS:&lt;/strong&gt; Flexible but complex due to constraint-solving.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;HTML/CSS:&lt;/strong&gt; Highly flexible with multiple layout models (flow, flexbox, grid).&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="examples"&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;/h3&gt;&#10;&lt;h4 id="flutter-example"&gt;&lt;strong&gt;Flutter Example:&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-dart" data-lang="dart"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Container(&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;constraints:&lt;/span&gt; BoxConstraints(&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;minWidth:&lt;/span&gt; &lt;span style="color:#bd93f9"&gt;100&lt;/span&gt;,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;maxWidth:&lt;/span&gt; &lt;span style="color:#bd93f9"&gt;200&lt;/span&gt;,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ),&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;child:&lt;/span&gt; Text(&lt;span style="color:#f1fa8c"&gt;&amp;#39;Hello&amp;#39;&lt;/span&gt;),&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints:&lt;/strong&gt; &lt;code&gt;Container&lt;/code&gt; sends constraints to &lt;code&gt;Text&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Size:&lt;/strong&gt; &lt;code&gt;Text&lt;/code&gt; chooses a size within constraints.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Position:&lt;/strong&gt; &lt;code&gt;Container&lt;/code&gt; sets the position of &lt;code&gt;Text&lt;/code&gt;.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h4 id="android-example"&gt;&lt;strong&gt;Android Example:&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-xml" data-lang="xml"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;&amp;lt;LinearLayout&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#50fa7b"&gt;android:layout_width=&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;match_parent&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#50fa7b"&gt;android:layout_height=&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;match_parent&amp;#34;&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#ff79c6"&gt;&amp;lt;TextView&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#50fa7b"&gt;android:layout_width=&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;wrap_content&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#50fa7b"&gt;android:layout_height=&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;wrap_content&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#50fa7b"&gt;android:text=&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;/&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ff79c6"&gt;&amp;lt;/LinearLayout&amp;gt;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints:&lt;/strong&gt; &lt;code&gt;LinearLayout&lt;/code&gt; provides measure specs to &lt;code&gt;TextView&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Size:&lt;/strong&gt; &lt;code&gt;TextView&lt;/code&gt; measures itself based on specs.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Position:&lt;/strong&gt; &lt;code&gt;LinearLayout&lt;/code&gt; sets &lt;code&gt;TextView&lt;/code&gt;&amp;rsquo;s position using &lt;code&gt;layout()&lt;/code&gt;.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h4 id="ios-example"&gt;&lt;strong&gt;iOS Example:&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-swift" data-lang="swift"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;let&lt;/span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;container&lt;/span&gt; = UIView()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;container.translatesAutoresizingMaskIntoConstraints = &lt;span style="color:#ff79c6"&gt;false&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd;font-style:italic"&gt;let&lt;/span&gt; &lt;span style="color:#8be9fd;font-style:italic"&gt;label&lt;/span&gt; = UILabel()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;label.translatesAutoresizingMaskIntoConstraints = &lt;span style="color:#ff79c6"&gt;false&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;label.text = &lt;span style="color:#f1fa8c"&gt;&amp;#34;Hello&amp;#34;&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;container.addSubview(label)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;NSLayoutConstraint.activate([&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; label.widthAnchor.constraint(greaterThanOrEqualToConstant: &lt;span style="color:#bd93f9"&gt;100&lt;/span&gt;),&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; label.widthAnchor.constraint(lessThanOrEqualToConstant: &lt;span style="color:#bd93f9"&gt;200&lt;/span&gt;),&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; label.centerXAnchor.constraint(equalTo: container.centerXAnchor),&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; label.centerYAnchor.constraint(equalTo: container.centerYAnchor)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;])&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints:&lt;/strong&gt; &lt;code&gt;NSLayoutConstraint&lt;/code&gt; sets constraints on &lt;code&gt;label&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Size:&lt;/strong&gt; &lt;code&gt;UILabel&lt;/code&gt; sizes itself based on constraints.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Position:&lt;/strong&gt; Constraints determine &lt;code&gt;UILabel&lt;/code&gt;&amp;rsquo;s position within &lt;code&gt;container&lt;/code&gt;.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h4 id="htmlcss-example"&gt;&lt;strong&gt;HTML/CSS Example:&lt;/strong&gt;&lt;/h4&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-html" data-lang="html"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;&lt;span style="color:#ff79c6"&gt;div&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;style&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;=&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;display: flex; justify-content: center; align-items: center; width: 200px; height: 200px;&amp;#34;&lt;/span&gt;&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;&lt;span style="color:#ff79c6"&gt;div&lt;/span&gt; &lt;span style="color:#50fa7b"&gt;style&lt;/span&gt;&lt;span style="color:#ff79c6"&gt;=&lt;/span&gt;&lt;span style="color:#f1fa8c"&gt;&amp;#34;min-width: 100px; max-width: 200px;&amp;#34;&lt;/span&gt;&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Hello&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &amp;lt;/&lt;span style="color:#ff79c6"&gt;div&lt;/span&gt;&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;lt;/&lt;span style="color:#ff79c6"&gt;div&lt;/span&gt;&amp;gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Constraints:&lt;/strong&gt; CSS properties define constraints.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Size:&lt;/strong&gt; Child &lt;code&gt;div&lt;/code&gt; sizes itself based on min and max width.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Position:&lt;/strong&gt; Parent &lt;code&gt;div&lt;/code&gt; positions the child using flexbox.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="summary"&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/h2&gt;&#10;&lt;p&gt;The layout systems in Flutter, Android, iOS, and HTML5/CSS/JS each have their own approaches:&lt;/p&gt;</description></item><item><title>The Flutter Plugin Project Files</title><link>https://yh.timefriend.vip/post/flutter/theflutterpluginprojectfiles/</link><pubDate>Fri, 24 May 2024 09:17:20 +0800</pubDate><guid>https://yh.timefriend.vip/post/flutter/theflutterpluginprojectfiles/</guid><description>&lt;h1 id="the-flutter-plugin-project-files"&gt;The Flutter Plugin Project Files&lt;/h1&gt;&#10;&lt;p&gt;Creating the plugin project&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;$ flutter create --org com.example --template=plugin --platforms=android,ios,linux,macos,windows hello_plugin &#10;&#10;Signing iOS app for device deployment using developer identity: &amp;#34;Apple&#10;Development: Yaohong Huang (WS3UUERGF9)&amp;#34;&#10;Creating project hello_plugin...&#10;Resolving dependencies in hello_plugin... (3.3s)&#10;Got dependencies in hello_plugin.&#10;Resolving dependencies in hello_plugin/example... (1.1s)&#10;Got dependencies in hello_plugin/example.&#10;Wrote 161 files.&#10;&#10;All done!&#10;&#10;Your plugin code is in hello_plugin/lib/hello_plugin.dart.&#10;&#10;Your example app code is in hello_plugin/example/lib/main.dart.&#10;&#10;&#10;Host platform code is in the android, ios, linux, macos, windows directories&#10;under hello_plugin.&#10;To edit platform code in an IDE see&#10;https://flutter.dev/developing-packages/#edit-plugin-package.&#10;&#10;&#10;To add platforms, run `flutter create -t plugin --platforms &amp;lt;platforms&amp;gt; .` under&#10;hello_plugin.&#10;For more information, see https://flutter.dev/go/plugin-platforms.&#10;&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex="0"&gt;&lt;code&gt;hello_plugin&#10;├── CHANGELOG.md&#10;├── LICENSE&#10;├── README.md&#10;├── analysis_options.yaml&#10;├── android&#10;│   ├── build.gradle&#10;│   ├── hello_plugin_android.iml&#10;│   ├── local.properties&#10;│   ├── settings.gradle&#10;│   └── src&#10;│   ├── main&#10;│   └── test&#10;├── example&#10;│   ├── README.md&#10;│   ├── analysis_options.yaml&#10;│   ├── android&#10;│   │   ├── app&#10;│   │   ├── build.gradle&#10;│   │   ├── gradle&#10;│   │   ├── gradle.properties&#10;│   │   ├── gradlew&#10;│   │   ├── gradlew.bat&#10;│   │   ├── hello_plugin_example_android.iml&#10;│   │   ├── local.properties&#10;│   │   └── settings.gradle&#10;│   ├── build&#10;│   │   ├── 52f352800ae67b257006addf8ca3668f&#10;│   │   ├── e29aedf18e567df5728f6b7ce57d2e97.cache.dill.track.dill&#10;│   │   ├── ios&#10;│   │   └── last_build_run.json&#10;│   ├── hello_plugin_example.iml&#10;│   ├── integration_test&#10;│   │   └── plugin_integration_test.dart&#10;│   ├── ios&#10;│   │   ├── Flutter&#10;│   │   ├── Podfile&#10;│   │   ├── Podfile.lock&#10;│   │   ├── Pods&#10;│   │   ├── Runner&#10;│   │   ├── Runner.xcodeproj&#10;│   │   ├── Runner.xcworkspace&#10;│   │   └── RunnerTests&#10;│   ├── lib&#10;│   │   └── main.dart&#10;│   ├── linux&#10;│   │   ├── CMakeLists.txt&#10;│   │   ├── flutter&#10;│   │   ├── main.cc&#10;│   │   ├── my_application.cc&#10;│   │   └── my_application.h&#10;│   ├── macos&#10;│   │   ├── Flutter&#10;│   │   ├── Podfile&#10;│   │   ├── Runner&#10;│   │   ├── Runner.xcodeproj&#10;│   │   ├── Runner.xcworkspace&#10;│   │   └── RunnerTests&#10;│   ├── pubspec.lock&#10;│   ├── pubspec.yaml&#10;│   ├── test&#10;│   │   └── widget_test.dart&#10;│   └── windows&#10;│   ├── CMakeLists.txt&#10;│   ├── flutter&#10;│   └── runner&#10;├── hello_plugin.iml&#10;├── ios&#10;│   ├── Assets&#10;│   ├── Classes&#10;│   │   └── HelloPlugin.swift&#10;│   └── hello_plugin.podspec&#10;├── lib&#10;│   ├── hello_plugin.dart&#10;│   ├── hello_plugin_method_channel.dart&#10;│   └── hello_plugin_platform_interface.dart&#10;├── linux&#10;│   ├── CMakeLists.txt&#10;│   ├── hello_plugin.cc&#10;│   ├── hello_plugin_private.h&#10;│   ├── include&#10;│   │   └── hello_plugin&#10;│   └── test&#10;│   └── hello_plugin_test.cc&#10;├── macos&#10;│   ├── Classes&#10;│   │   └── HelloPlugin.swift&#10;│   └── hello_plugin.podspec&#10;├── pubspec.lock&#10;├── pubspec.yaml&#10;├── test&#10;│   ├── hello_plugin_method_channel_test.dart&#10;│   └── hello_plugin_test.dart&#10;└── windows&#10; ├── CMakeLists.txt&#10; ├── hello_plugin.cpp&#10; ├── hello_plugin.h&#10; ├── hello_plugin_c_api.cpp&#10; ├── include&#10; │   └── hello_plugin&#10; └── test&#10; └── hello_plugin_test.cpp&#10;&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex="0"&gt;&lt;code&gt;name: hello_plugin&#10;description: A new Flutter plugin project.&#10;version: 0.0.1&#10;homepage:&#10;&#10;environment:&#10; sdk: &amp;#39;&amp;gt;=3.0.5 &amp;lt;4.0.0&amp;#39;&#10; flutter: &amp;#34;&amp;gt;=3.3.0&amp;#34;&#10;&#10;dependencies:&#10; flutter:&#10; sdk: flutter&#10; plugin_platform_interface: ^2.0.2&#10;&#10;dev_dependencies:&#10; flutter_test:&#10; sdk: flutter&#10; flutter_lints: ^2.0.0&#10;&#10;# For information on the generic Dart part of this file, see the&#10;# following page: https://dart.dev/tools/pub/pubspec&#10;&#10;# The following section is specific to Flutter packages.&#10;flutter:&#10; # This section identifies this Flutter project as a plugin project.&#10; # The &amp;#39;pluginClass&amp;#39; specifies the class (in Java, Kotlin, Swift, Objective-C, etc.)&#10; # which should be registered in the plugin registry. This is required for&#10; # using method channels.&#10; # The Android &amp;#39;package&amp;#39; specifies package in which the registered class is.&#10; # This is required for using method channels on Android.&#10; # The &amp;#39;ffiPlugin&amp;#39; specifies that native code should be built and bundled.&#10; # This is required for using `dart:ffi`.&#10; # All these are used by the tooling to maintain consistency when&#10; # adding or updating assets for this project.&#10; plugin:&#10; platforms:&#10; android:&#10; package: com.example.hello_plugin&#10; pluginClass: HelloPlugin&#10; ios:&#10; pluginClass: HelloPlugin&#10; linux:&#10; pluginClass: HelloPlugin&#10; macos:&#10; pluginClass: HelloPlugin&#10; windows:&#10; pluginClass: HelloPluginCApi&#10;&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>The Widget tree, Element tree, and Rendering Object tree in flutter</title><link>https://yh.timefriend.vip/post/flutter/flutterwidgetelementrenderingobjecttree/</link><pubDate>Thu, 23 May 2024 22:17:20 +0800</pubDate><guid>https://yh.timefriend.vip/post/flutter/flutterwidgetelementrenderingobjecttree/</guid><description>&lt;h1 id="the-widget-tree-element-tree-rendering-object-tree-in-flutter"&gt;The Widget tree, Element tree, Rendering Object tree in flutter&lt;/h1&gt;&#10;&lt;p&gt;The purpose of the three type of trees in Flutter:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Widget tree:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;1.hold the widget config;&lt;/li&gt;&#10;&lt;li&gt;2.offer a public API;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Element tree:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;1.manage the lifecycle of widget;&lt;/li&gt;&#10;&lt;li&gt;2.hold a spot in the UI hierarchy;&lt;/li&gt;&#10;&lt;li&gt;3.manage parent/child relationship;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;Rendering object tree:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;1.layout, size and paint itself,&lt;/li&gt;&#10;&lt;li&gt;2.layout children;&lt;/li&gt;&#10;&lt;li&gt;3.claim input event;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Entry-point &lt;a href="https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/binding.dart"&gt;binding.dart&lt;/a&gt;&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-dart" data-lang="dart"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#8be9fd"&gt;void&lt;/span&gt; runApp(Widget app){&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; WidgetsFlutterBinding.ensureInitialized()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ..attachRootWidget(app)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ..scheduleWarmUpFrame();&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Resouce: &lt;a href="https://www.youtube.com/watch?v=996ZgFRENMs"&gt;https://www.youtube.com/watch?v=996ZgFRENMs&lt;/a&gt;&lt;/p&gt;</description></item><item><title>The project files generated by 'flutter create --template=plugin_ffi' using dart:ffi to call C APIs</title><link>https://yh.timefriend.vip/post/flutter/theprojectfilesflutterpluginffidartfficapis/</link><pubDate>Thu, 23 May 2024 20:17:20 +0800</pubDate><guid>https://yh.timefriend.vip/post/flutter/theprojectfilesflutterpluginffidartfficapis/</guid><description>&lt;h1 id="the-project-files-generated-by-flutter-create-templateplugin_ffi-using-dartffi-to-call-c-apis"&gt;The project files generated by &amp;lsquo;flutter create &amp;ndash;template=plugin_ffi&amp;rsquo; using dart:ffi to call C APIs&lt;/h1&gt;&#10;&lt;p&gt;Flutter mobile and desktop apps can use the &lt;code&gt;dart:ffi&lt;/code&gt; library to call native C APIs.&lt;/p&gt;&#10;&lt;p&gt;Here are the project files generated by executing the following command:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-sh" data-lang="sh"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;flutter create --platforms&lt;span style="color:#ff79c6"&gt;=&lt;/span&gt;android,ios,macos,windows,linux --template&lt;span style="color:#ff79c6"&gt;=&lt;/span&gt;plugin_ffi native_add&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;flutter version: flutter_macos_3.10.5-stable&lt;/p&gt;&#10;&lt;p&gt;Reference:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;1.&lt;a href="https://docs.flutter.dev/platform-integration/android/c-interop"&gt;Binding to native Android code using dart:ffi&lt;/a&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;2.&lt;a href="https://docs.flutter.dev/platform-integration/ios/c-interop"&gt;Binding to native iOS code using dart:ffi&lt;/a&gt;&lt;/p&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Notes:&lt;/p&gt;&#10;&lt;p&gt;1.The FFI library can only bind against C symbols, so in C++ these symbols are marked extern &amp;ldquo;C&amp;rdquo;.&lt;/p&gt;</description></item></channel></rss>