Masterarbeit Richard Stern. Flutter App, sich mit einem Bluetooth-Gerät verbindet und Berührungen auf einem Sensor visualisiert.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.html 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <meta name="description" content="API docs for the build method from the SideBarContentState class, for the Dart programming language.">
  8. <title>build method - SideBarContentState class - SideBarContent library - Dart API</title>
  9. <!-- required because all the links are pseudo-absolute -->
  10. <base href="../..">
  11. <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  12. <link rel="stylesheet" href="static-assets/github.css">
  13. <link rel="stylesheet" href="static-assets/styles.css">
  14. <link rel="icon" href="static-assets/favicon.png">
  15. </head>
  16. <body>
  17. <div id="overlay-under-drawer"></div>
  18. <header id="title">
  19. <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  20. <ol class="breadcrumbs gt-separated dark hidden-xs">
  21. <li><a href="index.html">touch_demonstrator</a></li>
  22. <li><a href="pages_SideBarContent/pages_SideBarContent-library.html">SideBarContent</a></li>
  23. <li><a href="pages_SideBarContent/SideBarContentState-class.html">SideBarContentState</a></li>
  24. <li class="self-crumb">build method</li>
  25. </ol>
  26. <div class="self-name">build</div>
  27. <form class="search navbar-right" role="search">
  28. <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  29. </form>
  30. </header>
  31. <main>
  32. <div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
  33. <h5>SideBarContentState class</h5>
  34. <ol>
  35. <li class="section-title"><a href="pages_SideBarContent/SideBarContentState-class.html#constructors">Constructors</a></li>
  36. <li><a href="pages_SideBarContent/SideBarContentState/SideBarContentState.html">SideBarContentState</a></li>
  37. <li class="section-title inherited">
  38. <a href="pages_SideBarContent/SideBarContentState-class.html#instance-properties">Properties</a>
  39. </li>
  40. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/context.html">context</a></li>
  41. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/hashCode.html">hashCode</a></li>
  42. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/mounted.html">mounted</a></li>
  43. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/runtimeType.html">runtimeType</a></li>
  44. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/widget.html">widget</a></li>
  45. <li class="section-title"><a href="pages_SideBarContent/SideBarContentState-class.html#instance-methods">Methods</a></li>
  46. <li><a href="pages_SideBarContent/SideBarContentState/build.html">build</a></li>
  47. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/deactivate.html">deactivate</a></li>
  48. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/debugFillProperties.html">debugFillProperties</a></li>
  49. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/didChangeDependencies.html">didChangeDependencies</a></li>
  50. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/didUpdateWidget.html">didUpdateWidget</a></li>
  51. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/dispose.html">dispose</a></li>
  52. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/initState.html">initState</a></li>
  53. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/noSuchMethod.html">noSuchMethod</a></li>
  54. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/reassemble.html">reassemble</a></li>
  55. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/setState.html">setState</a></li>
  56. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/toDiagnosticsNode.html">toDiagnosticsNode</a></li>
  57. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/toString.html">toString</a></li>
  58. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/toStringShort.html">toStringShort</a></li>
  59. <li class="section-title inherited"><a href="pages_SideBarContent/SideBarContentState-class.html#operators">Operators</a></li>
  60. <li class="inherited"><a href="pages_SideBarContent/SideBarContentState/operator_equals.html">operator ==</a></li>
  61. </ol>
  62. </div><!--/.sidebar-offcanvas-->
  63. <div class="col-xs-12 col-sm-9 col-md-8 main-content">
  64. <h1>build method</h1>
  65. <section class="multi-line-signature">
  66. <div>
  67. <ol class="annotation-list">
  68. <li>@override</li>
  69. </ol>
  70. </div>
  71. <span class="returntype">Widget</span>
  72. <span class="name ">build</span>
  73. (<wbr><span class="parameter" id="build-param-context"><span class="type-annotation">BuildContext</span> <span class="parameter-name">context</span></span>)
  74. </section>
  75. <section class="desc markdown">
  76. <p>Describes the part of the user interface represented by this widget.</p>
  77. <p>The framework calls this method in a number of different situations:</p><ul><li>After calling <a href="pages_SideBarContent/SideBarContentState/initState.html">initState</a>.</li><li>After calling <a href="pages_SideBarContent/SideBarContentState/didUpdateWidget.html">didUpdateWidget</a>.</li><li>After receiving a call to <a href="pages_SideBarContent/SideBarContentState/setState.html">setState</a>.</li><li>After a dependency of this <code>State</code> object changes (e.g., an
  78. <code>InheritedWidget</code> referenced by the previous <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> changes).</li><li>After calling <a href="pages_SideBarContent/SideBarContentState/deactivate.html">deactivate</a> and then reinserting the <code>State</code> object into
  79. the tree at another location.</li></ul>
  80. <p>The framework replaces the subtree below this widget with the widget
  81. returned by this method, either by updating the existing subtree or by
  82. removing the subtree and inflating a new subtree, depending on whether the
  83. widget returned by this method can update the root of the existing
  84. subtree, as determined by calling <code>Widget.canUpdate</code>.</p>
  85. <p>Typically implementations return a newly created constellation of widgets
  86. that are configured with information from this widget's constructor, the
  87. given <code>BuildContext</code>, and the internal state of this <code>State</code> object.</p>
  88. <p>The given <code>BuildContext</code> contains information about the location in the
  89. tree at which this widget is being built. For example, the context
  90. provides the set of inherited widgets for this location in the tree. The
  91. <code>BuildContext</code> argument is always the same as the <code>context</code> property of
  92. this <code>State</code> object and will remain the same for the lifetime of this
  93. object. The <code>BuildContext</code> argument is provided redundantly here so that
  94. this method matches the signature for a <code>WidgetBuilder</code>.</p>
  95. <h2 id="design-discussion">Design discussion</h2>
  96. <h3 id="why-is-the-build-method-on-state-and-not-statefulwidget">Why is the <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> method on <code>State</code>, and not <code>StatefulWidget</code>?</h3>
  97. <p>Putting a <code>Widget build(BuildContext context)</code> method on <code>State</code> rather
  98. putting a <code>Widget build(BuildContext context, State state)</code> method on
  99. <code>StatefulWidget</code> gives developers more flexibility when subclassing
  100. <code>StatefulWidget</code>.</p>
  101. <p>For example, <code>AnimatedWidget</code> is a subclass of <code>StatefulWidget</code> that
  102. introduces an abstract <code>Widget build(BuildContext context)</code> method for its
  103. subclasses to implement. If <code>StatefulWidget</code> already had a <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> method
  104. that took a <code>State</code> argument, <code>AnimatedWidget</code> would be forced to provide
  105. its <code>State</code> object to subclasses even though its <code>State</code> object is an
  106. internal implementation detail of <code>AnimatedWidget</code>.</p>
  107. <p>Conceptually, <code>StatelessWidget</code> could also be implemented as a subclass of
  108. <code>StatefulWidget</code> in a similar manner. If the <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> method were on
  109. <code>StatefulWidget</code> rather than <code>State</code>, that would not be possible anymore.</p>
  110. <p>Putting the <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> function on <code>State</code> rather than <code>StatefulWidget</code> also
  111. helps avoid a category of bugs related to closures implicitly capturing
  112. <code>this</code>. If you defined a closure in a <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> function on a
  113. <code>StatefulWidget</code>, that closure would implicitly capture <code>this</code>, which is
  114. the current widget instance, and would have the (immutable) fields of that
  115. instance in scope:</p>
  116. <pre class="language-dart"><code class="language-dart">class MyButton extends StatefulWidget {
  117. ...
  118. final Color color;
  119. @override
  120. Widget build(BuildContext context, MyButtonState state) {
  121. ... () { print("color: $color"); } ...
  122. }
  123. }
  124. </code></pre>
  125. <p>For example, suppose the parent builds <code>MyButton</code> with <code>color</code> being blue,
  126. the <code>$color</code> in the print function refers to blue, as expected. Now,
  127. suppose the parent rebuilds <code>MyButton</code> with green. The closure created by
  128. the first build still implicitly refers to the original widget and the
  129. <code>$color</code> still prints blue even through the widget has been updated to
  130. green.</p>
  131. <p>In contrast, with the <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> function on the <code>State</code> object, closures
  132. created during <a href="pages_SideBarContent/SideBarContentState/build.html">build</a> implicitly capture the <code>State</code> instance instead of
  133. the widget instance:</p>
  134. <pre class="language-dart"><code class="language-dart">class MyButtonState extends State&lt;MyButton&gt; {
  135. ...
  136. @override
  137. Widget build(BuildContext context) {
  138. ... () { print("color: ${widget.color}"); } ...
  139. }
  140. }
  141. </code></pre>
  142. <p>Now when the parent rebuilds <code>MyButton</code> with green, the closure created by
  143. the first build still refers to <code>State</code> object, which is preserved across
  144. rebuilds, but the framework has updated that <code>State</code> object's <a href="pages_SideBarContent/SideBarContentState/widget.html">widget</a>
  145. property to refer to the new <code>MyButton</code> instance and <code>${widget.color}</code>
  146. prints green, as expected.</p>
  147. <p>See also:</p><ul><li>The discussion on performance considerations at <code>StatefulWidget</code>.</li></ul>
  148. </section>
  149. <section class="summary source-code" id="source">
  150. <h2><span>Implementation</span> </h2>
  151. <pre class="language-dart"><code class="language-dart">@override
  152. Widget build(BuildContext context) {
  153. return Scaffold(
  154. appBar: AppBar(
  155. title: Text(&#39;${widget.title}&#39;),
  156. ),
  157. body: SafeArea(child: Container()));
  158. }</code></pre>
  159. </section>
  160. </div> <!-- /.main-content -->
  161. <div class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  162. </div><!--/.sidebar-offcanvas-->
  163. </main>
  164. <footer>
  165. <span class="no-break">
  166. touch_demonstrator 1.0.0+1
  167. </span>
  168. </footer>
  169. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  170. <script src="static-assets/typeahead.bundle.min.js"></script>
  171. <script src="static-assets/highlight.pack.js"></script>
  172. <script src="static-assets/URI.js"></script>
  173. <script src="static-assets/script.js"></script>
  174. </body>
  175. </html>