<?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 ChiLi on Medium]]></title>
        <description><![CDATA[Stories by ChiLi on Medium]]></description>
        <link>https://medium.com/@justdo.85?source=rss-382491bc0b2c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*x8qMzpg5r7bOJ8KosWf9Ug.jpeg</url>
            <title>Stories by ChiLi on Medium</title>
            <link>https://medium.com/@justdo.85?source=rss-382491bc0b2c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:40:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@justdo.85/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[Build Your Own Freelance Website — Flutter — Day 1 — Basic Setup — Firebase Setup]]></title>
            <link>https://medium.com/@justdo.85/build-your-own-freelance-website-flutter-day-1-basic-setup-firebase-setup-2bd1a705b134?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bd1a705b134</guid>
            <category><![CDATA[flutter-beginner]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter-firebase]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Wed, 10 May 2023 03:27:39 GMT</pubDate>
            <atom:updated>2023-05-10T03:27:39.855Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build Your Own Freelance Website — Flutter — Day 1 — Basic Setup — Firebase Setup</h3><p>I am going to use Flutter to create my own freelance website this time. This is my first time using Flutter to build a website, so this will be a learning record for me, as well as a review and learning experience for some of the packages I have not used before!</p><h3>1. Create Project</h3><p>Move your Terminal to the root directory of your project and enter:</p><pre>$ flutter create soho</pre><p>You can replace ‘soho’ to whatever you want for your project name.</p><h3>2. Upload to GitHub</h3><p>After creating a project, I usually like to upload it to my own GitHub for easy management, or so that I can have access to the code on different computers.</p><p>First, we go to GitHub and create a new repository. Then, follow the instructions to enter the commands in the Terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*Ud2OEMP75JMvMbZS.png" /></figure><h3>3. Basic packages</h3><p>For this project, I have currently decided to use the following packages:</p><ul><li>State management : <a href="https://pub.dev/packages/flutter_bloc">Bloc</a></li><li>Route management: <a href="https://pub.dev/packages/go_router">go_router</a></li><li>Handle rwd: <a href="https://pub.dev/packages/responsive_framework">responsive_framework</a></li><li>Environment variables: <a href="https://pub.dev/packages/envied">envied</a></li><li>Database: Firebase(<a href="https://pub.dev/packages/firebase_core">fire_core</a>, <a href="https://pub.dev/packages/cloud_firestore">cloud_firestore</a>)</li></ul><p>I will be using these packages for now, and will add more later if necessary.</p><h3>4. Firebase setting</h3><p>Let’s first create a new project in the <a href="https://console.firebase.google.com/">Firebase console</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/0*EtzSzY2rhsA1kcA8.png" /></figure><p>Enter the project name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*6mBZ7krSPItCNSFN.png" /></figure><p>Then, follow the instructions provided and you should be able to create the project successfully!</p><p>After successfully creating the project, we need to add a new web app.&lt;/&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*d_AKJjY7CNYJNSJy.png" /></figure><p>After entering the project name, I will check “Also set up Firebase Hosting” because we plan to use Firebase to host our website later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/0*QnxxlPxGV-mSydZ4.png" /></figure><p>After registering, you will see this screen next. Simply copy the firebaseConfig and proceed to the next step to complete the creation process. You don’t need to worry about the other options for now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*24xP9XUD2Hgdhso8.png" /></figure><p>Follow the instructions and you will be able to successfully create a web app on Firebase.</p><h3>5. Environment variables</h3><p>Because we need API keys and other parameters to connect to Firebase, but don’t want to upload them to GitHub, we need to take some precautions and turn these parameters into environment variables. Create a .env file at the root directory of your code and add the copied parameters there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/0*Ro5E7EKMIR7xjbgy.png" /></figure><p>Next, create an env.dart file in the lib directory. If your variable names are the same as mine, you can directly copy the code below. You will see some errors, but don’t worry about them for now.</p><pre>// lib/env.dart<br>import &#39;package:envied/envied.dart&#39;;<br><br>part &#39;env.g.dart&#39;;<br>@Envied(path: &#39;.env&#39;)<br>abstract class Env {<br>  @EnviedField(varName: &#39;FIRESTORE_API_KEY&#39;)<br>  static const firestoreApiKey = _Env.firestoreApiKey;<br>  @EnviedField(varName: &#39;PROJECT_ID&#39;)<br>  static const projectId = _Env.projectId;<br>  @EnviedField(varName: &#39;MESSAGING_SENDER_ID&#39;)<br>  static const messagingSenderID = _Env.messagingSenderID;<br>  @EnviedField(varName: &#39;APP_ID&#39;)<br>  static const appId = _Env.appId;<br>  @EnviedField(varName: &#39;MEASUREMENT_ID&#39;)<br>  static const measurementId = _Env.measurementId;<br>}</pre><p>Next, we need to install the <a href="https://pub.dev/packages/envied">envied</a> package. Enter the following command in the Terminal:</p><pre>$ flutter pub add envied<br>$ flutter pub add --dev envied_generator<br>$ flutter pub add --dev build_runner</pre><p>After the installation is complete, enter the following command:</p><pre>$ flutter pub run build_runner build</pre><p>After that, a file called env.g.dart will be generated, and the errors from before should now be resolved.</p><h3>6. Initialize Firebase</h3><p>Next, we need to initialize Firebase and inject the settings in our app. Before doing so, we need to install `firebase_core`.</p><pre>$ flutter pub add firebase_core</pre><p>Next, we initialize Firebase and pass in the settings before calling runApp. Env.xxx is the variable we set in env.dart and .env earlier.</p><pre>void main() async {<br>  final List&lt;Future&gt; initFunctions = [<br>    Firebase.initializeApp(<br>      options: const FirebaseOptions(<br>        apiKey: Env.firestoreApiKey,<br>        authDomain: &quot;${Env.projectId}.firebaseapp.com&quot;,<br>        projectId: Env.projectId,<br>        storageBucket: &quot;${Env.projectId}.appspot.com&quot;,<br>        messagingSenderId: Env.messagingSenderID,<br>        appId: Env.appId,<br>        measurementId: Env.measurementId,<br>      ),<br>    ),<br>  ];<br>  await Future.wait(initFunctions);<br>  runApp(const MyApp());<br>}</pre><p>Today’s progress ends here. See you in the next article!</p><p>If you are interested in other Flutter tutorials, you can check out my <a href="https://66catknight-flutter.com/">blog</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bd1a705b134" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[打造自己的接案網站 — Flutter — Day 1 — 基本設置 — Firebase設定]]></title>
            <link>https://medium.com/@justdo.85/%E6%89%93%E9%80%A0%E8%87%AA%E5%B7%B1%E7%9A%84%E6%8E%A5%E6%A1%88%E7%B6%B2%E7%AB%99-flutter-day-1-%E5%9F%BA%E6%9C%AC%E8%A8%AD%E7%BD%AE-firebase%E8%A8%AD%E5%AE%9A-4ad3c9c42f8f?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ad3c9c42f8f</guid>
            <category><![CDATA[flutter-side-project]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-beginner]]></category>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter-firebase]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Tue, 09 May 2023 04:04:51 GMT</pubDate>
            <atom:updated>2023-05-09T10:28:44.169Z</atom:updated>
            <content:encoded><![CDATA[<h3>打造自己的接案網站 — Flutter — Day 1 — 基本設置 — Firebase設定</h3><p>這次我要使用Flutter來製作自己的接案網站，這是我第一次使用Flutter來製作網站，因此這算是一個學習記錄，順便複習跟學習一些沒有使用過的套件！</p><h3>1. 創建專案</h3><p>先將Terminal移到專案的根目錄，輸入:</p><pre>flutter create soho</pre><p>soho 可以替換成自己想要的名稱！</p><h3>2. 上傳到GitHub</h3><p>通常在創建完專案之後，我會習慣上傳到自己的GitHub以方便管理或是在使用不同電腦時都可以有程式碼可以用。</p><p>首先我們到GitHub上，創建一個新的repository，接著照著它上面的指令輸入就可以了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*MtxA7dkYy2xHr5mB.png" /></figure><h3>3. 基本套件</h3><p>在這個專案中我目前決定使用下面這些套件</p><ul><li>狀態管理 : <a href="https://pub.dev/packages/flutter_bloc">Bloc</a></li><li>路徑管理: <a href="https://pub.dev/packages/go_router">go_router</a></li><li>處理rwd: <a href="https://pub.dev/packages/responsive_framework">responsive_framework</a></li><li>環境變數: <a href="https://pub.dev/packages/envied">envied</a></li><li>資料庫: Firebase(<a href="https://pub.dev/packages/firebase_core">fire_core</a>, <a href="https://pub.dev/packages/cloud_firestore">cloud_firestore</a>)相關套件</li></ul><p>目前暫時會使用這些套件，之後新增會再補上。</p><h3>4. Firebase設定</h3><p>我們先到<a href="https://console.firebase.google.com/">firebase console</a>創建一個新的project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/0*tsF-SATVzPvWw3yq.png" /></figure><p>輸入專案名稱</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*QxkcamTv5Bt2ZR3J.png" /></figure><p>接著就照著指示做下去就可以成功創建專案了！</p><p>創建成功之後 我們要新增一個網頁 &lt;/&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/0*VcbF30e4tZkNp5RU.png" /></figure><p>輸入專案名稱之後，我會勾選 Also set up Firebase Hosting，因為我們之後打算用 Firebase 來發布我們的網站</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/0*ooYa8jCPXzZeKKPd.png" /></figure><p>註冊之後，接下來會看到這個畫面，我們把 firebaseConfig複製下來就好，其他不用管，就繼續下一步到創建完成</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/0*e-QD-kvwVlYiHaIq.png" /></figure><p>照著指示點下去，我們就可以成功創建一個web app在 firebase上了</p><h3>5. 環境變數</h3><p>因為我們要連接firebase會需要API Key等等的參數，但不想要上傳這些到GitHub上，所以我們要做一些保護措施，將這些參數變成環境參數，到程式碼的根目錄創建一個.env的檔案，把剛剛複製的參數再帶上</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/0*Edoh4YJHTkO_5Nhy.png" /></figure><p>接著在lib下，建一個 env.dart 檔案，如果你上面的變數名稱跟我的一樣，就可以直接複製下面的程式碼，會看到一些error是正常的，我們先忽略</p><pre>// lib/env.dart<br>import &#39;package:envied/envied.dart&#39;;<br><br>part &#39;env.g.dart&#39;;<br>@Envied(path: &#39;.env&#39;)<br>abstract class Env {<br>  @EnviedField(varName: &#39;FIRESTORE_API_KEY&#39;)<br>  static const firestoreApiKey = _Env.firestoreApiKey;<br>  @EnviedField(varName: &#39;PROJECT_ID&#39;)<br>  static const projectId = _Env.projectId;<br>  @EnviedField(varName: &#39;MESSAGING_SENDER_ID&#39;)<br>  static const messagingSenderID = _Env.messagingSenderID;<br>  @EnviedField(varName: &#39;APP_ID&#39;)<br>  static const appId = _Env.appId;<br>  @EnviedField(varName: &#39;MEASUREMENT_ID&#39;)<br>  static const measurementId = _Env.measurementId;<br>}</pre><p>接著我們需要安裝 <a href="https://pub.dev/packages/envied">envied</a> 這個套件，需要在Terminal輸入下面的指令</p><pre>$ flutter pub add envied<br>$ flutter pub add --dev envied_generator<br>$ flutter pub add --dev build_runner</pre><p>安裝完成後，我們接著輸入</p><pre>$ flutter pub run build_runner build</pre><p>完成之後，會產成一個env.g.dart的檔案，然後剛剛的錯誤也都正常了</p><h3>6. 初始化Firebase</h3><p>接下來我們要在app中，初始化Firebase及代入設定，在設定前，我們要先安裝 <a href="https://pub.dev/packages/firebase_core">firebase_core</a></p><pre>$ flutter pub add firebase_core</pre><p>接著在 runApp前初始化Firebase，Env.xxx 就是我們剛剛在 env.dart 和 .env 中設定的變數</p><pre>void main() async {<br>  final List&lt;Future&gt; initFunctions = [<br>    Firebase.initializeApp(<br>      options: const FirebaseOptions(<br>        apiKey: Env.firestoreApiKey,<br>        authDomain: &quot;${Env.projectId}.firebaseapp.com&quot;,<br>        projectId: Env.projectId,<br>        storageBucket: &quot;${Env.projectId}.appspot.com&quot;,<br>        messagingSenderId: Env.messagingSenderID,<br>        appId: Env.appId,<br>        measurementId: Env.measurementId,<br>      ),<br>    ),<br>  ];<br>  await Future.wait(initFunctions);<br>  runApp(const MyApp());<br>}</pre><p>今天的進度就到這，我們下一篇見！</p><p>如果對其他Flutter教學有興趣，可以到我的<a href="https://66catknight-flutter.com/">部落格</a>看看！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ad3c9c42f8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter — How to create your own package and publish to Pub.dev]]></title>
            <link>https://medium.com/@justdo.85/flutter-how-to-create-your-own-package-and-publish-to-pub-dev-ce96fd1d6d40?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce96fd1d6d40</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter-package]]></category>
            <category><![CDATA[pubdev]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Thu, 04 May 2023 02:49:08 GMT</pubDate>
            <atom:updated>2023-05-04T02:49:08.682Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter — How to create your own package and publish to Pub.dev</h3><p>When we work on various Flutter projects, we may find ourselves repeating certain code segments. When these segments are complex or lengthy, we can write them as a package to make them more convenient and efficient for future use.</p><p>Today, I’m going to share with you how to create your own package and upload it to Pub.dev!</p><p>First, we need to navigate to the location where we want to create the package using the terminal, and then enter:</p><pre>flutter create --template=package name</pre><p>You can replace “name” with the desired package name, and then you will have your first package!</p><p>At the beginning, there will be an example code in the lib folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*IBWIfpKqqFSfh5PfzwamZQ.png" /></figure><p>You can modify the code to implement the functionality or class you want. It’s up to you to explore and unleash your creativity!</p><h3>Publish to Pub.dev</h3><p><a href="https://pub.dev/">Pub.dev</a> provides a place for Flutter and Dart developers to upload packages or plugins. Here you can find other developers’ shared packages or plugins, and you can also search for any needed packages or plugins.</p><h3>Preparation</h3><p>Before uploading, we need to do some preparation to make it easier for others to use.</p><h4>1. Example</h4><p>We can create a folder called “example” and create a file named “main.dart” inside it.</p><p>Inside this file, we can demonstrate how to call and use our package. Below is a sample code for my package:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*qQG2c5NpW4t2syAdMHLFKw.png" /></figure><p>which has a simple function to calculate a linear equation. Therefore, a simple demonstration would suffice.</p><p>By doing so, you can include an example section on your Pub.dev package page after uploading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/0*UrizFxKr56u96Xib.png" /></figure><h4>2. ChangeLog</h4><p>In the top-level directory, there is a file called CHANGELOG.md, which allows you to record the changes made in each version, similar to the commits in Git. This helps users and yourself keep track of what changes were made in each version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gy0nj_5SedDYODpMEeqZew.png" /></figure><h4>3. Pubspec</h4><p>In pubspec.yaml, we can modify the description field to provide a clear and concise overview of the package&#39;s functionality, allowing others to understand it at a glance.</p><p>We can also add a repository field in pubspec.yaml, followed by the link to your Github repository. This link will appear on the right side of your package page on pub.dev website.</p><p>Also, remember that every time you want to update your package on Pub.dev, your version number should be incremented to a new number that is different from the previous one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e6bmeOwtBqE2Vj7Pm1SoEA.png" /></figure><h4>4. License</h4><p>We can create a LICENSE file, or we can choose to create a license when creating a repository on Github by checking the &quot;Choose a license&quot; option. There are various types of licenses available, and we can choose the one that best fits our needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*SPitwNGTkctB6xkf4ZJmxA.png" /></figure><h4>5. README</h4><p>README.md is a markdown file that will appear on the main page of your package on pub.dev. There are many advanced features in markdown that can make your page look beautiful, but here we will just cover some basic usage.</p><p>This <a href="https://markdownlivepreview.com/">website</a> can preview the output of markdown syntax.</p><p>##is for headings (# numbers affect the size of the heading, the more # the smaller the heading)</p><p>```dart indicates that the following block is Dart code.</p><p>[name](#abc-def) is a hyperlink, and there should be no spaces in between. Inside the parenthesis is the location that the hyperlink will lead to, where spaces are replaced with “-”. Remember that all links inside the parenthesis should be in lowercase!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*fQGJpsWzkNjs3t6Ao5mXcg.png" /></figure><h4>6.Publish</h4><p>Finally, we’ve reached the step of publishing!</p><p>We can first enter flutter pub publish --dry-run in the terminal to test if there are any issues with our upload.</p><p>If there are no issues, you can enter “flutter pub publish” in the terminal to publish your package!</p><p><strong>Reminder: If it’s your first time publishing, there will be a URL that requires Google account authentication (because we haven’t authenticated as a Publisher yet), so remember to click it and don’t wait foolishly.</strong></p><p>Once the upload is successful, you can find your package on the URL provided by pub.dev!</p><p>If you want to change to an authenticated publisher later, you can go to the “Admin” tab on the pub.dev website and change the “Package ownership” to the authenticated publisher.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/0*F2_TxqvAOoWZ5p45.png" /></figure><p>That’s the end of today’s sharing. If you have any questions or find any errors, feel free to leave a comment and let me know!</p><p>If you are interesting about more Flutter tutorial or tips, you can find them in my <a href="https://66catknight-flutter.com/">blog</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce96fd1d6d40" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter — 如何創建和上傳自己的Package到Pub.dev]]></title>
            <link>https://medium.com/@justdo.85/flutter-%E5%A6%82%E4%BD%95%E5%89%B5%E5%BB%BA%E5%92%8C%E4%B8%8A%E5%82%B3%E8%87%AA%E5%B7%B1%E7%9A%84package%E5%88%B0pub-dev-783a0967d402?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/783a0967d402</guid>
            <category><![CDATA[flutter-tips]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter-package]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Wed, 03 May 2023 03:52:22 GMT</pubDate>
            <atom:updated>2023-05-03T03:52:22.934Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter — 如何創建和上傳自己的Package到Pub.dev</h3><p>當我們在做各個Flutter專案時可能都會重複用到某些程式碼, 當這段程式碼很複雜或是冗長時, 我們就可以寫成一個Package讓我們之後使用時更加方便跟快速！</p><p>今天我就要來跟大家分享，如何創建自己的Package 並上傳到Pub.dev上！</p><p>首先我們透過Terminal到達自己要創建Package的位置, 然後輸入：</p><pre>flutter create --template=package name</pre><p>name可以替換成想要的package名稱, 然後你就有了第一個package!</p><p>一開始會有一個範例的程式碼在lib內</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/0*CKmAmlqObGWC5pOK.png" /></figure><p>可以在這邊修改成自己想要的功能或是class等，交給大家自己去發揮</p><h3>上傳Pub.dev</h3><p><a href="https://pub.dev/">Pub.dev</a> 提供了Flutter和Dart開發人員一個上傳 Package 或是 Plugin的地方, 這邊可以找到其他開發者分享的套件或插件, 可以來這邊找找有沒有需要的.</p><h3>事前準備</h3><p>在上傳前我們需要做一些事前準備, 來讓其他人更好的使用</p><h4>1. Example</h4><p>我們可以創建一個Folder叫example, 並創立一個main.dart的檔案</p><p>在裡面我們可以示範自己的package要如何呼叫和使用, 下面是我的package的樣本</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/0*Bl0GmGZ91H8nIu5J.png" /></figure><p>是一個很簡單的計算直線方程式的功能, 因此做一個簡單的示範就可以了!</p><p>這樣在你上傳Pub.dev後 就會有 Example 這個欄位了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/0*Hm7dNhNK43iScQpr.png" /></figure><h4>2. ChangeLog</h4><p>在最外層目錄, 會有一個 CHANGELOG.md, 裡面是讓你紀錄每一個版本所做的改變 有點像是 git 的 commit, 讓使用者也讓自己知道說這個版本做了哪些變動</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gl8iCu1PZIsHSCYK.png" /></figure><h4>3. Pubspec</h4><p>在pubspec.yaml中我們可以更改description, 讓別人一眼就能看出這個package的功能</p><p>也可以新增一個欄位 repository 後面放你的github連結, 這個連結也會出現在pub.dev網站的右方</p><p>也要記得每次想要更新 pub.dev, 你的version就要跟前一個是不一樣的數字</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*88g4OioD-udD3c8h.png" /></figure><h4>4. License</h4><p>我們可以創建一個LICENSE的檔案, 或是可以在github創建時 勾選創建LICENSE的選項, 這樣就不需要再特別處理, 有一個Choose a license的選項 裡面有各種 License, 可以根據需要去選擇</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/0*QsqZdXWxIoJ0OYSq.png" /></figure><h4>5. README</h4><p>README.md 是一種mark down的語法, 會出現在pub.dev中的首頁, 有許多複雜的用法, 可以讓畫面變得非常漂亮, 這邊就介紹一些基本的用法</p><p><a href="https://markdownlivepreview.com/">這個網站</a>可以預覽mark down語法的輸出畫面</p><p>##就是標題(#數量會影響標題字的大小 越多越小)</p><p>```dart 代表下面的區塊為dart程式碼</p><p>[名稱](#abc-def) 為超連結, 中間不可以有空白(#)內放的是下方要連結到的地方 空白用 “-” 代替, 記得在()內的連結全部都要是小寫哦！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/0*ZzsjIm7G9Gmdnme8.png" /></figure><h4>6.上傳</h4><p>終於到上傳這個步驟了！</p><p>我們可以先在terminal 輸入 flutter pub publish — dry-run 來測試我們的上傳有沒有問題</p><p>如果都沒有問題 就可以輸入 flutter pub publish 來正式上傳囉！</p><p><strong>提醒： 如果是第一次上傳，他會跑一跑會有一個網址需要登入Google帳號認證(因為我們還沒有認證Publisher)，要記得去點，不要傻傻的在那邊等</strong></p><p>上傳成功之後就可以在他給的網址中找到自己的Package了！</p><p>如果之後想要改成認證過的Publisher, 可以在網頁中的 Admin 的 Package ownership 改成認證成功的 publisher</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/0*zDXihJBOyFRbU5wJ.png" /></figure><p>今天的分享就到這了，如果對其他Flutter文章有興趣的話，可以到我的<a href="https://66catknight-flutter.com/">部落格</a>去看看！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=783a0967d402" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter error handle and custom error widget]]></title>
            <link>https://medium.com/@justdo.85/flutter-error-handle-and-custom-error-widget-77736a5e597e?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/77736a5e597e</guid>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-tips]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Tue, 02 May 2023 02:17:18 GMT</pubDate>
            <atom:updated>2023-05-10T12:22:15.330Z</atom:updated>
            <content:encoded><![CDATA[<p>When we are running a Flutter app, there are factors beyond our control, so errors are bound to occur. Therefore, learning how to handle errors has become an essential course.</p><h3>Basic Error Handling</h3><pre>Future&lt;Response&gt; getNetworkResponse() async {<br>  try {<br>    final uri = uri.parse(&#39;http://.....&#39;);<br>    final response = await.http.get(uri);<br>    switch(response.statusCode) {<br>      case 200:<br>        final data = json.decode(response.body);<br>        return Response.fromJson(data);<br>     default:<br>       throw Exception(response.reasonPhrase);<br>    }<br>  } catch(_) {<br>    rethrow;<br>  }<br>}</pre><p>The above code is making a GET request using the <a href="https://pub.dev/packages/http">http package</a> to retrieve some data.</p><p>If the retrieval and parsing of the data is successful, a Response will be returned.</p><p>However, when an error occurs, we will throw an error message.</p><p>Basic usage is as follows:</p><pre>try {<br>  final response = await getNetworkResponse();<br>  print(response);<br>} catch (e) {<br>  // Error Handle<br>}</pre><p>However, we did not specifically mention the need for error handling in getNetworkResponse, so it is often forgotten to add a try/catch block, which can cause the app to crash when there is a problem!</p><p>Therefore, we can use some methods to remind people who use this function to handle errors.</p><p>The most basic method is to add comments, which will appear as hints when you hover over the function with your mouse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*jqZ0_aL79OqR2ljSLu6OvA.png" /></figure><p>However, some people may not look at these comments, so we need to use a more forceful method!</p><h3>MultipleResult</h3><p><a href="https://pub.dev/packages/multiple_result">MultipleResult</a> is a pub.dev package that provides multiple return values. We can use the following method to restrict the use of this function and require error handling:</p><pre>Future&lt;Result&lt;Response, Exception&gt;&gt; getNetworkResponse() async {<br>  try {<br>    final uri = uri.parse(&#39;http://.....&#39;);<br>    final response = await.http.get(uri);<br>    switch(response.statusCode) {<br>      case 200:<br>        final data = json.decode(response.body);<br>        final res = Response.fromJson(data)<br>        return Success(res);<br>     default:<br>       return Error(Exception());<br>    }<br>  } catch(_) {<br>     return Error(Exception());<br>  }<br>}</pre><p>Then we can use ‘when&#39; to handle the returned data:</p><pre>final response = getNetworkResponse();<br>response.when(<br>  (success) {<br>    // Handle result<br>  },<br>  (exception) {<br>    // Handle exception<br>  },<br>);</pre><p>You can check out this <a href="https://pub.dev/packages/multiple_result">website</a> for more detailed instructions and examples of other usage methods. There are more detailed explanations and examples available on the website.</p><p>For more detailed usage instructions, you can visit the <a href="http://pub.dev/packages/multiple_result">package’s website</a>, where you will find more detailed explanations and examples.</p><h3>Customize error message widget</h3><p>After discussing general error handling, unexpected errors can still occur. Therefore, we can add an extra layer of protection to the outermost layer of the app:</p><p>If errors are not handled properly, the UI may end up looking like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/139/1*M2M3P2mNCLFnO2EhaUCZBQ.png" /></figure><p>When users see this, they may wonder, “What happened?!”</p><p>However, if we can use our own customized widget, users may not be as alarmed when errors occur. This can also allow for more immediate error handling.</p><p>Now let’s discuss how to add our own customized error handling widget.</p><pre>void main() {<br>  ErrorWidget.builder = (details) {<br>    return CustomErrorWidget();<br>  };<br>  runApp(const MyApp());<br>}</pre><p>By replacing CustomErrorWidget with our own desired widget, we can display this widget when errors are not caught. Then, we can implement our own desired error handling logic within the widget.</p><p>If you are interesting about more Flutter tutorial or tips, you can find them in my <a href="https://66catknight-flutter.com/">blog</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77736a5e597e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter error handle and custom error widget, 錯誤處理及客製化錯誤訊息]]></title>
            <link>https://medium.com/@justdo.85/flutter-error-handle-and-custom-error-widget-%E9%8C%AF%E8%AA%A4%E8%99%95%E7%90%86%E5%8F%8A%E5%AE%A2%E8%A3%BD%E5%8C%96%E9%8C%AF%E8%AA%A4%E8%A8%8A%E6%81%AF-fcaec3e80d34?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcaec3e80d34</guid>
            <category><![CDATA[flutter-中文]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-beginner]]></category>
            <category><![CDATA[flutter-tips]]></category>
            <category><![CDATA[flutter-tutorial]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Thu, 27 Apr 2023 07:05:22 GMT</pubDate>
            <atom:updated>2023-04-27T07:08:07.737Z</atom:updated>
            <content:encoded><![CDATA[<p>當我們在執行Flutter app時, 我們無法控制一切因素, 所以一定會有錯誤的出現, 那如何處理錯誤就成了一門必學的課程了!</p><h3>基本的錯誤處理</h3><pre>Future&lt;Response&gt; getNetworkResponse() async {<br>  try {<br>    final uri = uri.parse(&#39;http://.....&#39;);<br>    final response = await.http.get(uri);<br>    switch(response.statusCode) {<br>      case 200:<br>        final data = json.decode(response.body);<br>        return Response.fromJson(data);<br>     default:<br>       throw Exception(response.reasonPhrase);<br>    }<br>  } catch(_) {<br>    rethrow;<br>  }<br>}</pre><p>上方的程式碼是在透過 <a href="https://pub.dev/packages/http">http package</a> 去得做一個 GET 的請求, 拿到一份資料.</p><p>如果成功得到並拆解成功就會回傳一個 Response.</p><p>但當發生錯誤時我們就會拋出一個錯誤訊息</p><p>基本的使用如下:</p><pre>try {<br>  final response = await getNetworkResponse();<br>  print(response);<br>} catch (e) {<br>  // 做錯誤處理<br>}</pre><p>但是我們的 getNetworkResponse 並沒有特意提及到需要做錯誤處理, 所以常常會有人忘記加 try/catch, 導致網路有問題時 app 就會壞掉！</p><p>因此我們可以透過一些辦法來提醒需要使用這個 Function 的人來做處理.</p><p>最基本的方法就是 加註解, 當你的滑鼠移到Function上時會出現這些提示</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*jqZ0_aL79OqR2ljSLu6OvA.png" /></figure><p>但是！有些人是不會去看這些的, 所以我們要使用更強硬的方式！</p><h3>MultipleResult</h3><p><a href="https://pub.dev/packages/multiple_result">MultipleResult</a> 是一個 pub.dev的套件, 可以提供多個回傳值, 我們可以用下面的方式來限制使用這個function必須要處理error</p><pre>Future&lt;Result&lt;Response, Exception&gt;&gt; getNetworkResponse() async {<br>  try {<br>    final uri = uri.parse(&#39;http://.....&#39;);<br>    final response = await.http.get(uri);<br>    switch(response.statusCode) {<br>      case 200:<br>        final data = json.decode(response.body);<br>        final res = Response.fromJson(data)<br>        return Success(res);<br>     default:<br>       return Error(Exception());<br>    }<br>  } catch(_) {<br>     return Error(Exception());<br>  }<br>}</pre><p>接著使用 when 來處理回傳的資料:</p><pre>final response = getNetworkResponse();<br>response.when(<br>  (success) {<br>    // 處理結果<br>  },<br>  (exception) {<br>    // 錯誤處理<br>  },<br>);</pre><p>其他更詳細的使用方法可以到他的<a href="https://pub.dev/packages/multiple_result">網站</a>去查看網站去查看, 裡面有更詳細的說明跟範例</p><h3>客製化錯誤訊息</h3><p>說完了一般的錯誤處理, 但是總是可能會有意外的發生, 因此我們可以在app的最外層加上一層保險,</p><p>一般如果沒有特別處理錯誤的話, 畫面會長成下面這個樣子</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/139/1*M2M3P2mNCLFnO2EhaUCZBQ.png" /></figure><p>使用者看到就會覺得 ??? 發生什麼事情了?!</p><p>但是如果能放上自己客製化的Widget, 雖然還是遇到了錯誤, 但是對使用者來說就會覺得比較沒什麼, 而且還能即時處理.</p><p>下面我們就來講解該如何加入自己客製化的錯誤處理 Widget</p><pre>void main() {<br>  ErrorWidget.builder = (details) {<br>    return CustomErrorWidget();<br>  };<br>  runApp(const MyApp());<br>}</pre><p>只要將 CustomErrorWidget 改成自己想要的 Widget, 就可以在有錯誤沒有被catch時跑到這個畫面, 然後再做自己想要的處理！</p><p>如果對我的其他Flutter教學有興趣, 可以到我的<a href="https://66catknight-flutter.com/">部落格</a>去看看更多文章！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcaec3e80d34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[副業 — Google AdMob 收入 分享— Day1]]></title>
            <link>https://medium.com/@justdo.85/google-admob-%E6%94%B6%E5%85%A5-%E5%88%86%E4%BA%AB-day1-3519ead0c9d2?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3519ead0c9d2</guid>
            <category><![CDATA[earn-money-online]]></category>
            <category><![CDATA[google-admob]]></category>
            <category><![CDATA[google-ads]]></category>
            <category><![CDATA[sideline]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Thu, 20 Apr 2023 09:10:38 GMT</pubDate>
            <atom:updated>2023-04-20T09:14:28.818Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>最近因為閒來無事，想說寫個App順便練習接一下Google的廣告，來當作自己的練習!<br>趁機推廣一下我的App，其實就是一個簡易的時鐘，可以抓當地的天氣資料，寫一個目標激勵自己，設定背景圖片等等小功能，會陸續推出新功能，大家可以下載看看~</blockquote><blockquote><a href="https://apps.apple.com/tw/app/%E7%B0%A1%E6%98%93%E6%99%82%E9%90%98/id6447434967">連結</a>在這邊~ 目前只有iOS版, Android版還在審核中~</blockquote><p>如果對 Flutter 有興趣 可以到我的<a href="https://66catknight-flutter.com/">部落格</a>看看 ! 裡面有一些 Flutter教學, 之後也會推出如何做出個App的教學!</p><p>到今天為止 只發佈了三天 所以收益也是少得可憐, 可能還是我自己在用App產生的qq</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*ro4Jj1D8vBVbqJdV1Fxoaw.png" /></figure><p>一天0.3美 一個月 9美, 我只能說 賺錢好難</p><p>當然也是因為我的App沒有人在用，希望之後能越來越好！</p><p>過一陣子Android成功上架之後會再更新兩邊的收益！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3519ead0c9d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter tutorial for beginners — The most basic 8 widgets.]]></title>
            <link>https://medium.com/@justdo.85/flutter-tutorial-for-beginners-the-most-basic-8-widgets-a9bb2617858f?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9bb2617858f</guid>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter-tips]]></category>
            <category><![CDATA[flutter-beginner]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Wed, 19 Apr 2023 02:37:43 GMT</pubDate>
            <atom:updated>2023-04-19T02:37:43.425Z</atom:updated>
            <content:encoded><![CDATA[<h3>Flutter tutorial for beginners — The most basic 8 widgets.</h3><p>If you are someone who is just starting to learn or planning to try Flutter, but don’t know where to start, here are some commonly used and practical widgets to help you get started!</p><h3>1. Scaffold</h3><p>Scaffold is a very important widget that provides a basic structure for your app and is very easy to use. Without further ado, let’s take a look at an example.</p><pre>Scaffold(<br>  // You can customize the AppBar by setting its properties, <br>  // or you can leave it empty to not have an AppBar at all.<br>  appBar: AppBar(<br>    title: Text(&#39;App Bar Title&#39;),<br>  ),<br>  // Remaining space<br>  body: Center(<br>    child: Text(&#39;Hello World!&#39;),<br>  ),<br>  // The left-hand side sliding drawer is called the drawer, <br>  // and the one that slides out from the right-hand side is called the endDrawer.<br>  drawer: Drawer(<br>    child: ListView(...)<br>  ),<br>  // The default floating action button in Flutter is located at the bottom right corner of the screen.<br>  floatingActionButton: FloatingActionButton(<br>    // Icon of the button, can also use Container or other widget to customize<br>    child: Icon(...),<br>    // Press button event<br>    onPress: () {}<br>  )<br>)</pre><p>In addition to the features mentioned above, Scaffold also has many other useful features, such as the bottomNavigationBar that provides buttons for page navigation at the bottom. There are many more features to explore, so keep studying!</p><h3>2. SizedBox</h3><p>SizedBox is a fundamental widget that only has four parameters: key, width, height, and child. Here, let’s ignore the key parameter. The width and height parameters allow you to restrict the dimensions of the child widget. If you don’t specify a child, an empty space will be left. Sometimes, we use SizedBox to set the spacing between widgets.</p><pre>SizedBox(<br>  width: 100,<br>  height: 100,<br>  child: ABC()<br>),</pre><h3>3. Container</h3><p>The Container widget can be considered an evolution of SizedBox. It can also set the width and height of the child, but it has additional features. For example, you can set the background color or image, add borders, change the border thickness and color, and set the border radius. There are many more features to explore, so feel free to study them in more detail!</p><pre>Container(<br>  width: 100,<br>  height: 100,<br>  // setup Padding<br>  padding: const EdgeInset.all(10),<br>  // setup Margin<br>  margin: const EdgeInset.all(10),<br>  decoration: BoxDecoration(<br>    borderRadius: BorderRadius.circular(90),<br>    // setup background color<br>    color: Colors.yellow,<br>    // setup container&#39;s shape<br>    shape: BoxShape.rectangle,<br>  )<br>)</pre><p>Reminder: If you only need to set the width and height, it is better to use SizedBox(). This is because it is more efficient for the app’s performance.</p><h3>4. Text</h3><p>As its name suggests, Text is a widget used for displaying text, and it has many parameters that can be set. Here are some of the most basic ones: font size, font weight, font color, text alignment, and what to do if the text overflows the allotted space. For example, you can use ellipsis ‘…’ or simply cut off the text. Remember to set the size of Text (such as wrapping it inside a SizedBox) so that the app knows whether the text has exceeded the available space. Otherwise, bugs may occur!</p><pre>Text(<br>  &#39;Hello World!&#39;,<br>  // When the text overflows the allotted space, the excess text will be replaced by &#39;...&#39; as an ellipsis.<br>  overflow: TextOverflow.ellipsis<br>)</pre><h3>5. Row</h3><p>Row is a widget used for arranging multiple horizontal objects. It can be used to set the horizontal and vertical alignment, among other things.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/0*iZTQWJTrnoBI4fPj.png" /></figure><pre>Row(<br>  // Arrange items in reverse order from the end<br>  mainAxisAlignment: MainAxisAlignment.end,<br>  // Vertical alignment will be centered.<br>  crossAxisAlignment: CrossAxisAlignment.center,<br>  // A Row widget will expand horizontally to fit the available space, <br>  // while the mainAxisSize property is set to MainAxisSize.max. If mainAxisSize is set to MainAxisSize.min, then the Row will shrink to fit its children.<br>  mainAxisSize: MainAxisSize.max,<br>  children: [<br>    Container(),<br>    Text(<br>      &#39;Hello World!&#39;,<br>    ),<br>  ],<br>)</pre><h3>6. Column</h3><p>Column is the opposite of Row, it’s a Widget for arranging vertical objects. You can also set the horizontal and vertical alignment modes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/243/0*sy5FgOdgMR05J90H.png" /></figure><pre>Column(<br>  // The vertical alignment is from top to bottom.<br>  mainAxisAlignment: MainAxisAlignment.start,<br>  // The horizontal alignment is centered in a Row.<br>  crossAxisAlignment: CrossAxisAlignment.center,<br>  // Column will expand vertically to its maximum height, <br>  // while min will be the same height as its children.<br>  mainAxisSize: MainAxisSize.max,<br>  children: [<br>    Container(),<br>    Text(<br>      &#39;Hello World!&#39;,<br>    ),<br>  ],<br>)</pre><h3>7. ListView</h3><p>ListView is used to display a scrollable list of widgets. There are different ways to create a ListView, such as using the ListView() constructor just like Column, where you can add different types of children. If the children have the same style, you can use ListView.builder() or ListView.separated(). However, if you have a long list of items, it’s not recommended to use ListView directly, instead, you should use ListView.builder(). This is because ListView will build all the widgets inside it, which may cause lag in the app. On the other hand, the builder method only prepares and displays the parts that are about to be shown, resulting in better performance.</p><pre>ListView.separated(<br>  // If you don&#39;t need context or index, you can change it to (_, __) { ... }.<br>  itemBuilder: (context, index) {<br>    // This is where we handle the generation of Widgets for each index.<br>    return Container(),<br>  },<br>  // The separator between each child is a line in my example, <br>  // but it can be customized based on your needs.<br>  separatorBuilder: (context, index) {<br>    return const Divider(),<br>  },<br>  // For the number of ListView children, <br>  // if it comes from a list of data from an API, you can use myList.length, <br>  // and then customize the top child based on the data, such as myList[index]....<br>  itemCount: 10,<br>)</pre><h3>8. Spacer</h3><p>Spacer is a blank Widget used for layout purposes. See the example below. Spacer will fill the remaining space after subtracting the space occupied by other Widgets.</p><pre>Row(<br>  children: [<br>    Text(&#39;A&#39;),<br>    Spacer(),<br>    Text(&#39;B&#39;),<br>  ],<br>)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/0*3ZAB0KxS7pqsw4qr.png" /></figure><p>The above 8 widgets are what I believe to be the most essential ones for beginners to know, but there are still many useful and cool widgets in Flutter waiting for everyone to learn! If you find this type of tutorial helpful, please leave a comment and let me know. I will continue to write introductions for other widgets!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9bb2617858f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter入門教學 — 最基礎的8個Widget]]></title>
            <link>https://medium.com/@justdo.85/flutter%E5%85%A5%E9%96%80%E6%95%99%E5%AD%B8-%E6%9C%80%E5%9F%BA%E7%A4%8E%E7%9A%848%E5%80%8Bwidget-a4a9013f7ab3?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4a9013f7ab3</guid>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter-widget]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Tue, 18 Apr 2023 04:27:57 GMT</pubDate>
            <atom:updated>2023-04-19T02:27:42.624Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Flutter入門教學 — 最基礎的8個Widget</strong></h3><p>如果你是一個剛開始學習或是準備要開始嘗試Flutter的人，但卻不知道要從哪裡開始下手，這逼會提供一些常用且實用的Widget來幫助大家入門！</p><h3>1. Scaffold</h3><p>Scaffold是一個非常重要的Widget, 他為你的App提供一個基本的架構, 使用起來非常方便, 話不多說我們直接看一下範例</p><pre>Scaffold(<br>  // 可以對 AppBar 做客製化設定, 也可以留空就不會有 AppBar<br>  appBar: AppBar(<br>    title: Text(&#39;App Bar Title&#39;),<br>  ),<br>  // 剩餘的空間<br>  body: Center(<br>    child: Text(&#39;Hello World!&#39;),<br>  ),<br>  // 左邊可以滑出來的 drawer, endDrawer則是從右邊滑出來的<br>  drawer: Drawer(<br>    child: ListView(...)<br>  ),<br>  // Flutter 預設在右下角的懸浮按鈕<br>  floatingActionButton: FloatingActionButton(<br>    // 按鈕的Icon, 也可以使用Container等widget來客製化<br>    child: Icon(...),<br>    // 點擊按鈕的事件<br>    onPress: () {}<br>  )<br>)</pre><p>除了上面介紹的功能, Scaffold還有很多其他有用的功能像是 bottomNavigationBar 在底部有換頁的按鈕等功能等著大家去研究！</p><h3>2. SizedBox</h3><p>SizedBox是一個最基礎的物件, 他只有4個參數可以輸入(key, width, height, child), 我們這邊先忽略key, 其他參數就是讓你限制你的child的高度和寬度, 如果不寫child 則會留一個空白區塊, 我們有時候會用 SizedBox 來設定 Widget之間的間隔</p><pre>SizedBox(<br>  width: 100,<br>  height: 100,<br>  child: ABC()<br>),</pre><h3>3. Container</h3><p>Container算是SizedBox的進化版, 他一樣可以設定 child 的寬度和高度, 但他多了一些功能, 像是可以設定背景顏色、背景圖片, 也可以添加外框、改變外框粗細、顏色, 或是設定圓角等等的功能, 大家有空可以再去研究一下！</p><pre>Container(<br>  width: 100,<br>  height: 100,<br>  // 設定Padding<br>  padding: const EdgeInset.all(10),<br>  // 設定Margin<br>  margin: const EdgeInset.all(10),<br>  decoration: BoxDecoration(<br>    // 設定圓角<br>    borderRadius: BorderRadius.circular(90),<br>    // 設定背景圖片<br>    color: Colors.yellow,<br>    // 設定形狀<br>    shape: BoxShape.rectangle,<br>  )<br>)</pre><p>提醒：如果只是要設定寬度和高度的話, 可以使用SizedBox()就好, 這樣App的效能會比較好哦！</p><h3>4. Text</h3><p>Text就是一個人如其名的Widget, 他就是拿來放文字用的, 他也是有許多參數可以設定, 這邊就介紹一些最基本的, 像是字體大小(font size), 字體粗度(font weight), 字體顏色, 字的對齊, 或是超出設定的大小時該如何處理, 應該要變成 &#39;...&#39; 或是直接裁切掉等功能, 記得要幫Text設定大小(像是包在SizedBox內) 程式才會知道有沒有超出哦 否則會有Bug出現！</p><pre>Text(<br>  &#39;Hello World!&#39;,<br>  // 當超出設定大小時 多餘的字會變成 &#39;...&#39;<br>  overflow: TextOverflow.ellipsis<br>)</pre><h3>5. Row</h3><p>Row是一個讓你排列多個水平物件的Widget, 可以設定水平排列方式 或是垂直排列方式等等</p><pre>Row(<br>  // 水平排列方式是從最後往前排<br>  mainAxisAlignment: MainAxisAlignment.end,<br>  // 垂直排列會置中<br>  crossAxisAlignment: CrossAxisAlignment.center,<br>  // Row會往水平方向長到最大, min則是會變得跟children一樣寬<br>  mainAxisSize: MainAxisSize.max,<br>  children: [<br>    Container(),<br>    Text(<br>      &#39;Hello World!&#39;,<br>    ),<br>  ],<br>)</pre><h3>6. Column</h3><p>Column則是跟Row相反, 是排列垂直物件的Widget, 一樣可以設定水平和垂直的排列方式</p><pre>Column(<br>  // 垂直排列方式是從最上往下排<br>  mainAxisAlignment: MainAxisAlignment.start,<br>  // 水平排列會置中<br>  crossAxisAlignment: CrossAxisAlignment.center,<br>  // Column會往垂直方向長到最大, min則是會變得跟children一樣高<br>  mainAxisSize: MainAxisSize.max,<br>  children: [<br>    Container(),<br>    Text(<br>      &#39;Hello World!&#39;,<br>    ),<br>  ],<br>)</pre><h3>7. ListView</h3><p>ListView是用來擺放一連串可以滑動的Widget, ListView 有多種建立的方式, 有直接使用ListView() 用法就跟Column一樣 裡面可以放很多樣式不同的child, 如果樣式都相同可以使用 ListView.builder(), ListView.separated(), 但是如果你的List非常的多, 則不推薦直接使用ListView, 而是要用ListView.builder, 因為ListView會直接將所有裡面的Widget先build出來, 可能會導致畫面Lag, 而builder則是會只先準備畫面顯示及快要顯示的部分而已, 效能方面會比較好！</p><pre>ListView.separated(<br>  // 如果用不到 context 或 index 則可以改成 (_, __) { ... }<br>  itemBuilder: (context, index) {<br>    // 這邊是處理各個 index 要產生的 Widget<br>    return Container(),<br>  },<br>  // 各個 child 之間的分隔線, 我這邊是使用一條線分隔, 可以根據需求來改變<br>  separatorBuilder: (context, index) {<br>    return const Divider(),<br>  },<br>  // ListView child的數量, 如果是來自api的某個list資料 就可以放 myList.length, 再根據資料客製化上方的child, myList[index]...<br>  itemCount: 10,<br>)</pre><h3>8. Spacer</h3><p>Spacer就是一個來幫助排版的空白Widget, 下面直接看範例, Spacer會填滿扣掉Widget之後剩餘的空間</p><pre>Row(<br>  children: [<br>    Text(&#39;A&#39;),<br>    Spacer(),<br>    Text(&#39;B&#39;),<br>  ],<br>)</pre><p>上面這8個Widget就是我認為入門最需要知道的, 但Flutter還有許多好用、酷炫的Widget等著</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4a9013f7ab3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter Tips: 3 Skills to Increase Development Speed]]></title>
            <link>https://medium.com/@justdo.85/flutter-tips-3-skills-to-increase-development-speed-c03941ec95e4?source=rss-382491bc0b2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c03941ec95e4</guid>
            <category><![CDATA[flutter-tutorial]]></category>
            <category><![CDATA[flutter-tips]]></category>
            <category><![CDATA[flutter-example]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[ChiLi]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 05:57:44 GMT</pubDate>
            <atom:updated>2023-04-17T05:57:44.962Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I would like to introduce three small tips that can speed up development and make code more readable.</p><h3>1.Simplify your Assets Management</h3><p>I think everyone often uses assets, such as Image.asset(‘assets/images/…’). However, typing out long file paths can be tedious and error-prone. To solve this problem, we can create a separate class to store these assets, so we don’t have to worry about mistyping or retyping the same file paths repeatedly. Additionally, any modifications can be made all at once in the class, without worrying about missing any instances of the asset throughout the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/0*U961QpVsxQXfJb5Y.png" /></figure><p>It’s also very convenient to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/0*vbDKg7pNIIAoWgyI.png" /></figure><p>Not only Assets, but any data that requires long strings or numerical values can be managed in the same way!</p><h3>2.Handling Text Size and Dimension Settings</h3><p>For both apps and web development, Flutter developers need to consider the screen size and aspect ratio. Sometimes, when designing an app, the proportions of text or widgets may not be what the developer intended. This is where the <a href="https://pub.dev/packages/flutter_screenutil">FlutterScreentUtil</a> package comes in handy.</p><p>FlutterScreenUtil can help adjust the size of text and widgets according to the screen size and aspect ratio. It can also convert pixels to logical pixels, which is useful for handling different screen densities. By using FlutterScreenUtil, developers can ensure that their apps have consistent proportions and dimensions across different screen sizes and densities.</p><p>Here is a basic example of how to use FlutterScreenUtil. The developer should fill in the designSize field (in dp) based on the design specifications. Then, when developing the app, the developer only needs to use the dimensions from the design specs and FlutterScreenUtil will automatically adjust the size and proportions according to the screen size and density.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/0*ioQLIYTpG4Xg9cMh.png" /></figure><p>Here’s a reminder for developers who want to avoid users’ device settings from affecting the font size and causing text overflow or broken images in their app. You can set the textScaleFactor property to a fixed value of 1 in the themeData property of your MaterialApp.</p><p>You can also use 0.xx.sw to set a percentage of the screen width or .sh to set a percentage of the screen height directly, so you don&#39;t have to manually fetch the screen width or height and multiply it by a factor.</p><h3>3.VSCode extension</h3><p>If you’re using VS Code for Flutter development, you can use the Awesome Flutter Snippets extension, which provides many shortcuts to save time. The one I use the most is “stl” or “stf”, which automatically generates a Stateless or Stateful widget with just a few keystrokes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FEbyoKqMBwinLBqw.png" /></figure><p>The refactoring feature in VS Code (which is also available in Android Studio, but I prefer VS Code) is very convenient. You can wrap a widget or builder directly, or remove a widget directly. If you are using a Mac, press “command + .” on the widget you want to modify, and the window below will appear for you to make your choice. Alternatively, you can right-click and select refactor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/0*_462B-ZqaE_gqDGW.png" /></figure><p>Today I’ve introduced some tips for Flutter development. If you have any questions, errors, or topics you’d like me to cover, feel free to leave a comment and let me know. Thank you! You’re welcome to check out my other <a href="https://66catknight-flutter.com/category/flutter%e6%95%99%e5%ad%b8/">Flutter tutorials</a> for reference.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c03941ec95e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>