<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by John Ryan on Medium]]></title>
        <description><![CDATA[Stories by John Ryan on Medium]]></description>
        <link>https://medium.com/@john.p.ryan4?source=rss-697e2aeb3759------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*hTvIogx1zKQUUv7npp-UQA.jpeg</url>
            <title>Stories by John Ryan on Medium</title>
            <link>https://medium.com/@john.p.ryan4?source=rss-697e2aeb3759------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 12:07:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@john.p.ryan4/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A brand new DartPad.dev with Flutter support]]></title>
            <link>https://medium.com/dartlang/a-brand-new-dartpad-dev-with-flutter-support-16fe6027784?source=rss-697e2aeb3759------2</link>
            <guid isPermaLink="false">https://medium.com/p/16fe6027784</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[dartpad]]></category>
            <category><![CDATA[announcements]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[John Ryan]]></dc:creator>
            <pubDate>Wed, 04 Dec 2019 17:27:59 GMT</pubDate>
            <atom:updated>2019-12-05T23:55:27.739Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’re announcing a major upgrade of <a href="https://dartpad.dev/">DartPad.dev</a> with a fresh new look-and-feel and support for the popular <a href="https://flutter.dev/">Flutter</a> UI toolkit. DartPad is our online editor that runs Dart programs directly in your browser, and now it runs Flutter apps too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*X7Sild_wdEFGRYaSk2C3Og.gif" /></figure><h3>Make something today</h3><p>To create a new Flutter project, click the <strong>New Pad</strong> button and choose <strong>Flutter</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Sd404nMeJmYEgbPpE7HN7g.gif" /></figure><p>This adds some starter code to the editor and runs it. Any time that DartPad sees that you’re using package:flutter, a panel comes up to display the UI. Or use the <strong>Samples</strong> menu to find a Flutter sample.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CONdjdCgZJH6oN7B4tjA5w.png" /></figure><h3>Features</h3><p>All of Flutter’s core libraries, like <a href="https://api.flutter.dev/flutter/cupertino/cupertino-library.html">cupertino</a> and <a href="https://api.flutter.dev/flutter/material/material-library.html">material</a>, are available to use, and DartPad can display their documentation. Select a symbol to see the documentation in the bottom panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*pjBKPqejQhVga2yXYWWigw.gif" /></figure><p>DartPad formats code using the Dart formatter (<a href="https://github.com/dart-lang/dart_style">dartfmt</a>), offers assists, provides fixes, suggests auto-completions, and shows errors and warnings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*f-DNPnkA6gB5wkT_TVVpSQ.gif" /></figure><p>When you’re ready to share your snippet, you can <a href="https://help.github.com/en/github/writing-on-github/creating-gists">create a GitHub gist</a> and put the gist ID in a URL like this: https://dartpad.dev/&lt;GistID&gt;. You can share this link in a bug report, in a StackOverflow question, or on your social media platform of choice. Check out the <a href="https://github.com/dart-lang/dart-pad/wiki/Sharing-Guide">sharing guide</a> for more details.</p><p>You can also embed DartPad into a page, <a href="https://flutter.dev/docs/codelabs/layout-basics">like in this codelab</a>. Embedded DartPads are especially good for articles, codelabs, and tutorials. (Check out <a href="https://dart.dev/resources/dartpad-tutorials.pdf">this guide</a> if you’re interested in using DartPad in codelabs and tutorials.) To learn more about adding DartPad to a page, check out the <a href="https://github.com/dart-lang/dart-pad/wiki/Embedding-Guide">embedding guide</a>.</p><h3>Thanks!</h3><p>DartPad is part of the Dart <a href="https://github.com/dart-lang">open-source project</a>. If you’ve filed <a href="https://github.com/dart-lang/dart-pad/issues">issues</a> or submitted changes to DartPad, thank you for making it better. If you’d like to contribute, get started at <a href="https://github.com/dart-lang/dart-pad">github.com/dart-lang/dart-pad</a>. To learn more about running Flutter on the web, visit <a href="https://flutter.dev/web">flutter.dev/web</a>.</p><p>We can’t wait to see what you build!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16fe6027784" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dartlang/a-brand-new-dartpad-dev-with-flutter-support-16fe6027784">A brand new DartPad.dev with Flutter support</a> was originally published in <a href="https://medium.com/dartlang">Dart</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Dart’s New Build System]]></title>
            <link>https://medium.com/@john.p.ryan4/exploring-darts-new-build-system-689ded1183d8?source=rss-697e2aeb3759------2</link>
            <guid isPermaLink="false">https://medium.com/p/689ded1183d8</guid>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[build-system]]></category>
            <dc:creator><![CDATA[John Ryan]]></dc:creator>
            <pubDate>Wed, 09 Jan 2019 00:19:28 GMT</pubDate>
            <atom:updated>2019-02-26T16:29:16.308Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*87hYa65eH-0usFdwInOshQ.jpeg" /></figure><p>If you’ve ever worked on a web application, you’ve probably used a build system. Webpack, Gulp, or Grunt are all build systems.</p><p>Dart 1 uses a system called Barback, but Dart 2 uses a new system called package:build. So what’s changed and why?</p><h3>What is a Build System?</h3><p>A quick definition of a build system is a program that takes a set of input files and generates output files. Those output files are usually executables or a “bundle” for the web. In Dart, a development server is provided so that any change made to your code is instantly built and served on an HTTP port.</p><p>Dart’s new build package adds an additional requirement: the outputs must be able to be determined statically. For example, if a file called post.md was fed into a Markdown builder, the build system should know that the output will be apost.html file. It must know this up-front.</p><h3>Goodbye Transformers</h3><p>Consider this Markdown transformer:</p><pre><em>import </em>&#39;dart:async&#39;;<br><br><em>import </em>&#39;package:barback/barback.dart&#39;;<br><em>import </em>&#39;package:markdown/markdown.dart&#39;;<br><br><em>class </em>Markdown <em>extends </em>Transformer {<br>  Markdown();<br>  String <em>get </em>allowedExtensions =&gt; &quot;.md .markdown .mdown&quot;;<br>  Future apply(Transform transform) <em>async </em>{<br>    <em>var </em>content = <em>await </em>transform.primaryInput.readAsString();<br>    <em>var </em>id = transform.primaryInput.id.changeExtension(&quot;.html&quot;);<br>    <em>var </em>newContent = markdownToHtml(content, extensionSet: ExtensionSet.gitHub);<br>    transform.consumePrimary();<br>    transform.addOutput(<em>new </em>Asset.fromString(id, newContent));<br>  }<br>}</pre><p>This transformer takes files ending in .md, .markdown, or .mdown, and replaces the original file with a .html tag that was generated using package:markdown. Notice that the original file got replaced and that the build system has no way to know up-front that this transformer converts .md files to .html files. It simply runs this transformer. Running this transformer call tells the build system to write the new .html file (Barback calls this an Asset), and consumes the original file.</p><p>Since the output files are opaque to the build system, the Markdown transformer has the liberty to generate additional files without telling the build system. Another build step may choose to combine multiple .md files into a single .html file.</p><p>You also may have noticed that no explicit files are being created or destroyed. Barback runs the transformers in memory. It doesn’t not write files to disk.</p><p>We’ve seen that Barback:</p><ol><li>Isn’t aware of the inputs and outputs until the build runs</li><li>Runs build steps through an abstract interface. Barback can run these build steps without necessarily writing files to disk.</li><li>Inputs can be deleted before the next build step is performed</li></ol><h3>Hello Builders</h3><p>Let’s look at the same Markdown build step implemented using package:build:</p><pre><em>import </em>&#39;package:build/build.dart&#39;;<br><em>import </em>&#39;package:markdown/markdown.dart&#39;;<br><br>Builder markdownBuilder(_) =&gt; MarkdownBuilder();<br><br><em>class </em>MarkdownBuilder <em>implements </em>Builder {<br>  Future build(BuildStep buildStep) <em>async </em>{<br>    <em>var </em>inputId = buildStep.inputId;<br><br>    <em>var </em>outputId = inputId.changeExtension(&quot;.html&quot;);<br>    <em>var </em>contents = <em>await </em>buildStep.readAsString(inputId);<br>    <em>var </em>markdownContents = markdownToHtml(contents);<br><br>    <em>await </em>buildStep.writeAsString(outputId, markdownContents);<br>  }<br><br>  Map&lt;String, List&lt;String&gt;&gt; <em>get </em>buildExtensions =&gt; {<br>        &#39;.md&#39;: [&quot;.html&quot;]<br>      };<br>}</pre><p>Notice that allowedExtensions has been replaced with buildExtensions. The Builder must define its inputs and outputs explicitly. The one additional step is to update the build.yaml file:</p><pre>metadata_stripped<br>  markdown:<br>    import: &quot;package:my_builders/markdown_builder.dart&quot;<br>    builder_factories:<br>      - markdownBuilder<br>    build_extensions:<br>      .md:<br>        - .html<br>    auto_apply: root_package<br>    required_inputs:<br>      - .md</pre><p>If the Builder writes to an AssetId with an extension that is not in buildExtensions, an UnexpectedOutputException is thrown.</p><p>Notice that this time:</p><ol><li>The build system knows the inputs and outputs up front</li><li>Files input and output is still performed through an abstract interface</li><li>Inputs cannot be deleted by a build step</li></ol><h3>An Example: Upgrading Tavern, a Static Site Generator</h3><p><a href="https://github.com/johnpryan/tavern">Tavern</a> is a static site generator for Dart. It now has basic support using Dart 2 and package build. You can find the new version at <a href="https://github.com/johnpryan/tavern2">https://github.com/johnpryan/tavern2</a>.</p><p>Tavern’s goal is to be a tool similar to Jekyll. It also automatically builds Dart scripts to run on your static site by combining it’s Builders with the official Dart builders.</p><p>It supports writing blog posts with the following format:</p><pre>---<br>title: &quot;Markdown Basics&quot;<br>tags: [&#39;code&#39;, &#39;dart&#39;]<br>---<br><br><strong># </strong>this is markdown<br><br>Here is some code about {{title}}<br><br>Tags:<br><br>{{#tags}}<br>&lt;li&gt;{{.}}<br>{{/tags}}<br><br><br>```<br>hello world!<br>```</pre><p>To do this, it applies multiple transformers in sequence. For example, the above file post.md might go through the following transformations:</p><ol><li>The Metadata transformer extracts the “metadata” YAML at the top of the file and writes two files post.md (with the metadata removed) and post.metadata.json .</li><li>The Markdown transformer consumes the post.md file and outputs a post.html file</li><li>The Template transformer runs and takes two inputs, post.html and post.metadata.json and replaces post.html with a new asset with the mustache templating applied with the metadata in post.metadata.json.</li></ol><p>Tavern 2 needs to take a different approach. Build steps can no longer replace assets with the same id. Instead, new files must be written for the next build step.</p><p>But how can the Metadata build step extract YAML from the top of the post? post.md can’t be simply replaced with a new version anymore.</p><p>The build steps need to be more well defined:</p><ol><li>The Metadata builder extracts the YAML and writes two files post.contents (containing the markdown with the top section removed) and post.metadata (containing the JSON file for the template step)</li><li>The Markdown builder now takes a .contents file and outputs a .html_template file.</li><li>The Template builder takes a .html_template file, a .metadata file, and outputs the final .html file</li><li>a PostProcessBuilder called CleanupBuilder is run to remove all .md, .contents, .metadata, and .html_template_files, leaving just the final html file.</li></ol><p>The build steps can be laid out like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IIgy5c5UAiZUg37asJU_EQ.jpeg" /></figure><h3>Wait but Why?</h3><p>Forcing build steps to obey stricter rules allows the build system to work better with Bazel and intelligently skip build steps in certain situations. For example, if our app used Sass, a sass builder could run alongside the pipeline we defined above. When the Sass file changes, the build system will only run the steps required to build that CSS file.</p><h3>Summary</h3><p>A productive build system with custom builders is something that has always been a core feature the Dart SDK. Now, it’s more optimized with new semantics, but still has great support for custom build rules.</p><h3>References</h3><ul><li><a href="https://docs.bazel.build/versions/master/build-ref.html">Bazel</a></li><li><a href="https://github.com/dart-lang/build/blob/master/docs/writing_a_builder.md">Writing a Builder</a></li><li><a href="https://docs.google.com/document/d/1juHkCRg-1YH6LvwhGPHgF2ihX-UQtR1fv-8aknO7t_4">Barback’s Design</a></li><li><a href="https://pub.dartlang.org/packages/barback">Barback</a></li><li><a href="https://github.com/johnpryan/tavern">Tavern</a></li><li><a href="https://github.com/johnpryan/tavern2">Tavern 2</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=689ded1183d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sharing code on iOS, Android and the Web]]></title>
            <link>https://medium.com/@john.p.ryan4/sharing-code-on-ios-android-and-web-85e8ed7dfccd?source=rss-697e2aeb3759------2</link>
            <guid isPermaLink="false">https://medium.com/p/85e8ed7dfccd</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[John Ryan]]></dc:creator>
            <pubDate>Tue, 23 Jan 2018 02:14:30 GMT</pubDate>
            <atom:updated>2018-10-05T19:55:56.172Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Update 2/9/2018</strong>: Watch <a href="https://www.youtube.com/watch?v=GpLb2XvKv20">our talk at DartConf 2018</a>!</p><p>Cross-platform mobile development has been a highly sought-after solution for a long time. They historically come with compromises and can’t quite deliver the same experience as a native app. But now we are convinced that this vision is a reality. Flutter allows us to build fast, native mobile apps and share 70% of our Dart code across iOS, Android, and the web.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*N0CaYwVP3b_ryCtpbGz61w.png" /></figure><p>There are <a href="https://stackoverflow.com/questions/268258/how-do-you-make-code-reusable">many tactics</a> for making code reusable. Most of these focus on reusing code within the same app or project. We focused on following these three rules:</p><ol><li>Use Layers</li><li>Simple Views</li><li>Inject Dependencies</li></ol><h3>Use Layers</h3><p>Layering is a very common technique for breaking apart a complicated app. In the context of client-side applications, the views and services are decoupled from the rest of the application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*Y3xYsDAkJAZhFhByD2Qhmg.png" /><figcaption>Using layers in your app</figcaption></figure><p>Each layer is decoupled from the others by library. For example, the Services layer never imports a controller. It’s job is only to provide an api for higher layers. The idea is that layers only access the layer directly below it.</p><p>Services are typically classes that interact a remote server, or the platform. Firebase, JSON / HTTP services, Websockets, filesystem access, etc are all examples of a service.</p><p>The Controller layer contains your app’s important domain-specific code. It does not necessarily mean to use a controller class. In fact, this layer can be completely replaced with other patterns (Redux, Flux, or any other *Ux.) The important thing is that the Views and Services are treated as abstract interfaces.</p><p>The Views are where widgets (Flutter) and components (web) are defined. Typically, the controller is interacting with a Component (Web) or Widget (Flutter) that implements an abstract interface:</p><pre>abstract class MyView {<br> Stream&lt;Event&gt; get onEvent;<br> void render(State state);<br>}</pre><p>This allows Flutter and Web apps to know what API the controller layer is expecting from it’s view.</p><p>There are different patterns for the Controller-View relationship, but typically there is a 1-to-1 relationship with the controller. Views can be independent of their controller (simple), or treat their controller as a Presenter (smart).</p><p>Caveat: There are use-cases that don’t lend themselves to this layered architecture. For example, a map. It makes much more sense to make the Views (implemented in both Flutter or Web) responsible for their own “service” for displaying a map. On Flutter, it would be a Widget using a Plugin (package:map_view) and an HTML library on web (package:google_maps).</p><h3>Remove View Logic</h3><p>Traditionally, views are platform-specific. Even if you are only building a Flutter app, you may want:</p><ol><li>Fast unit tests</li><li>To build command-line tools for interacting with services</li><li>A cleaner library and package structure</li></ol><p>Once the important code is moved out, it becomes possible to run tests. Sometimes, platform-specific libraries will be accidentally moved into the controller layer. A quick strategy for diagnosing this problem is to write test that only runs on the VM:</p><pre>@TestOn(&quot;vm&quot;)<br>library controller_test;</pre><pre>import &#39;package:myapp/controllers.dart&#39;;<br>import &#39;package:test/test.dart&#39;;</pre><pre>void main() {<br> group(&quot;controller&quot;, () {<br>   test(&quot;is pure dart&quot;, () {<br>     var controller = new AppController();<br>   });<br> });<br>}</pre><p>Then finding the culprit becomes easy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yOXJZtkmOn89mZEPMJAv2g.png" /></figure><h3>Inject Dependencies</h3><p>Services may need to use different implementations on each platform. Say we had a service and a cache:</p><pre>abstract class MyService {<br>  Future&lt;MyData&gt; fetchData();<br>}</pre><pre>abstract class MyCache {<br>  void cacheData(MyData data);<br>} </pre><pre>class AppController {<br>  final MyService _service;<br>  final MyCache _cache;<br>  <br>  AppController(this._service, this._cache);<br>  //...<br>}</pre><p>Now each entrypoint has a well-defined API for creating the AppController with the platform-specific dependencies. The Flutter app would import and inject a FlutterService and the Web app would import and inject a BrowserService.</p><h3>Example</h3><p>At AppTree, we make mobile and web solutions for enterprise problems. Our users have beautiful apps to work with their CRM, get their daily work done for universities like Stanford, and more. But there’s one problem that can waste a lot of time: deciding where to get lunch.</p><h3>Let’s Vote</h3><p>Our solution is an app called Let’s Vote. It will allow anyone to create an election and submit an idea they think should win. Once the creator closes the polls, it will display a winner. It will to display different pages:</p><pre>enum Page {<br>  home, // create or join<br>  create, // enter topic<br>  joining, // enter id (skipped if using create)<br>  username, // enter username<br>  ideaSubmission, // enter an candidate<br>  ballot, // display each candidate (idea) and pick one<br>  waitingForVotes, // wait for the polls to close<br>  result, // show the winner<br>}</pre><h3>Code Organization</h3><p>Our project needs three packages:</p><ol><li>letsvote: All platform-independent code (controllers, models, services, interfaces) goes here</li><li>letsvote_moble</li><li>letsvote_web: the web app, including the Dart server hosting it. The server includes a REST API for the web and mobile app to use.</li></ol><p>Both the web and mobile packages import letsvote using the <em>path</em> keyword in pubspec.yaml:</p><pre>dependencies:<br>  letsvote:<br>    path: ../letsvote</pre><h3>Basic Types</h3><p>First, we need to define a few basic types:</p><ul><li>Election: The parent object containing all information about an election that a group of voters are participating in.</li><li>Voter: a user with a unique name voting in an Election</li><li>Idea: Something voters can vote for.</li></ul><p>Each class can use JsonSerializable to generate toJson() methods automatically:</p><pre>@JsonSerializable()<br>class Election extends _$ElectionSerializerMixin {<br>  final String id;<br>  final String topic;<br>  final List&lt;Voter&gt; voters;<br>  final List&lt;Idea&gt; ideas;<br>  bool pollsOpen;</pre><pre>  Election(this.id, this.topic, this.voters, this.ideas, this.pollsOpen);</pre><pre>  factory Election.fromJson(json) =&gt; _$ElectionFromJson(json);<br>}</pre><pre>@JsonSerializable()<br>class Voter extends _$VoterSerializerMixin {<br>  final String name;</pre><pre>  Voter(this.name);</pre><pre>  factory Voter.fromJson(json) =&gt; _$VoterFromJson(json);<br>}</pre><pre>@JsonSerializable()<br>class Idea extends _$IdeaSerializerMixin {<br>  final String name;<br>  final String authorName;<br>  int votes;</pre><pre>  Idea(this.name, this.authorName, this.votes);<br>  factory Idea.fromJson(json) =&gt; _$IdeaFromJson(json);<br>}</pre><h3>HTTP API</h3><p>The API for our server is a REST api built using shelf:</p><pre>void configureRoutes(Router router) {<br>  router.post(&quot;/election&quot;, handleCreate);<br>  router.get(&quot;/election/{id}&quot;, handleGet);<br>  router.post(&quot;/election/{id}/user&quot;, handleJoin);<br>  router.post(&quot;/election/{id}/idea&quot;, handleSubmitIdea);<br>  router.post(&quot;/election/{id}/vote&quot;, handleVote);<br>  router.put(&quot;/election/{id}/close&quot;, handleClose);<br>}</pre><h3>The Service Layer</h3><p>These requests are defined as package:http requests in the requests library:</p><pre>import &#39;dart:convert&#39;;<br>import &#39;package:http/http.dart&#39;;<br>import &#39;package:letsvote/model.dart&#39;;</pre><pre>class JsonRequest extends Request {<br>  JsonRequest(String method, Uri uri) : super(method, uri) {<br>    this.headers[&#39;Content-Type&#39;] = &#39;application/json&#39;;<br>  }<br>}</pre><pre>class CreateElection extends JsonRequest {<br>  CreateElection(Uri host, String topic) : super(&#39;POST&#39;, _createUri(host)) {<br>    body = JSON.encode(new CreateElectionRequest(topic));<br>  }<br>  <br>  static Uri _createUri(Uri host) {<br>    return host.replace(path: &#39;election&#39;);<br>  }<br>}</pre><p>The Dart client has types for each request and response. Each request is sent using a Requester (<a href="https://pub.dartlang.org/packages/requester">pub package</a>):</p><pre>// letsvote/lib/services.dart<br>  Future&lt;Election&gt; create(String topic) async {<br>    var request = new requests.CreateElection(host, topic);<br>    var response = await requester.send(request);<br>    return new Election.fromJson(JSON.decode(response.body));<br>  }</pre><h3>The Controller Layer</h3><p>Our app needs an AppController to manage the state for our current user. It needs to store:</p><ol><li>The last known state of the election (the Election class)</li><li>The current Page</li><li>The unique username of the current voter</li><li>The abstract AppView to update when the state changes</li></ol><p>This layer is built using an MVP-style but could use Redux, Flux, or other patterns to manage state and update the view.</p><h3>The View Layer</h3><p>In this example, our View implemented has access to the controller and can access it’s public API to determine how it should render. To wire up this relationship, we use AppController.init():</p><pre>Future init(AppView view) async {<br>    // ...<br>    _view = view;<br>    _view.controller = this;<br>    // ...<br>  }</pre><p>Each “view” in flutter accesses the controller’s API to inform it the user is interacting with the app:</p><pre>class HomePage extends StatelessWidget {<br>  final AppController _controller;<br>  HomePage(this._controller);<br>  Widget build(BuildContext context) {<br>    return new Column(<br>      mainAxisAlignment: MainAxisAlignment.center,<br>      children: &lt;Widget&gt;[<br>        new Text(&quot;Let&#39;s Vote!&quot;),<br>        new Text(&quot;Create a new vote or join an existing vote&quot;),<br>        new MaterialButton(<br>          child: new Text(&quot;Create&quot;),<br>          onPressed: () =&gt; _controller.startByCreating(),<br>        ),<br>        new MaterialButton(<br>          child: new Text(&quot;Join&quot;),<br>          onPressed: () =&gt; _controller.startByJoining(),<br>        ),<br>      ],<br>    );<br>  }<br>}</pre><p>startByCreating and startByJoining have different implementations that result in updating the state of the Controller (the page) and possibly making requests.</p><p>It’s worth mentioning that this relationship could be implemented differently:</p><ol><li>Each view could have an abstract interface for it’s controller</li><li>Each view could emit events on a Stream that the controller listens to</li></ol><h3>The App</h3><p><a href="https://letsvote-dart.herokuapp.com/">https://letsvote-dart.herokuapp.com/</a></p><p><a href="https://github.com/apptreesoftware/letsvote">https://github.com/apptreesoftware/letsvote</a></p><h3>Closing thoughts</h3><p>We’ve found that using layers, simplifying views, and injecting dependencies allows us to share the most code between our Flutter app and web app. We calculate we are shaing 70% of our code (we include unit tests in this calculation) across all three platforms. But it’s not the amount of sharing, it’s <em>what</em> is being shared. Our apps share most critical code, the “brain” of our app. Instead of each platform being ahead or behind the others, all of our apps are up to date. Each person is focused on new features and improvements, not re-implementing existing work for another platform.</p><h3>FAQ</h3><h3>IntelliJ Setup</h3><p>IntelliJ can support a Dart project with multiple packages using modules. To set up three different modules:</p><ol><li>Open project settings (cmd+;)</li><li>Go to Modules</li><li>select letsvote_mobile.iml</li><li>select letsvote_server.iml</li><li>select letsvote_web.iml</li></ol><p>Then go to Preferences and re-select your Flutter SDK if it is not selected.</p><h3>Heroku Setup</h3><p>This project can run on heroku.</p><ol><li>Specify this buildpack <a href="https://github.com/johnpryan/heroku-buildpack-dart">https://github.com/johnpryan/heroku-buildpack-dart</a> , which supports a special flag for specifying the Dart build directory.</li><li>set DART_BUILD_DIR_OVERRIDE to letsvote_web</li><li>set DART_SDK_URL <a href="https://storage.googleapis.com/dart-archive/channels/stable/release/latest/sdk/dartsdk-linux-x64-release.zip">https://storage.googleapis.com/dart-archive/channels/stable/release/latest/sdk/dartsdk-linux-x64-release.zip</a></li><li>set PATH /app/bin:/usr/local/bin:/usr/bin:/bin:/app/dart-sdk/bin</li></ol><h3>What about routing?</h3><p>This app doesn’t use Flutter or Browser-based routing. It might be possible to build a shared abstraction for flutter’s Navigator and route_hierarchical. But more likely the solution will involve some custom code for each platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85e8ed7dfccd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>