<?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 Fang on Medium]]></title>
        <description><![CDATA[Stories by Fang on Medium]]></description>
        <link>https://medium.com/@fang3116?source=rss-e357f14564d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Fang on Medium</title>
            <link>https://medium.com/@fang3116?source=rss-e357f14564d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:48:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fang3116/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[【Flutter 跨平台 App 程式設計入門】#04 期末專題]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-04-%E6%9C%9F%E6%9C%AB%E5%B0%88%E9%A1%8C-d129676b7814?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d129676b7814</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[medicine]]></category>
            <category><![CDATA[google-gemini]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[final-project]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Tue, 11 Jun 2024 20:13:44 GMT</pubDate>
            <atom:updated>2024-06-12T07:32:28.765Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>本次APP的主題是與疾病相關～</em></strong></p><blockquote>GitHub連結：</blockquote><p><a href="https://github.com/Fangyil/Flutter-HW4.git">GitHub - Fangyil/Flutter-HW4</a></p><blockquote>App使用影片：</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FEnRGRAh-0eo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEnRGRAh-0eo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FEnRGRAh-0eo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5baa53acbf781eeabe9fc5abf4e7d8a/href">https://medium.com/media/d5baa53acbf781eeabe9fc5abf4e7d8a/href</a></iframe><blockquote>App頁面預覽：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yuNg71InUh1D5HI8cAvRHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QvLDs1KGqdiAuf5O2Id9VQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDqZ-5NMz18OE9dFFjqU8Q.png" /><figcaption>由左至右依序為 App初始畫面、登入頁面、註冊畫面</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5USuQftQs7jgmcqPcQFJmw.png" /><figcaption>Daily News頁面</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j4S-RhZzsxygGJ5BuaaOfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vr6EKeSYnZ3u-7eYc4mjIA.png" /><figcaption>Search頁面 及 點入的Detail Page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nOOjkL9ddfUhlknLsmvjkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*236HqUsSdQrpixzfCK-B6w.png" /><figcaption>Chat Room畫面 與 Profile頁面</figcaption></figure><blockquote>使用到的功能：</blockquote><p>◎<strong>串接網路上的 API 抓取 JSON 資料</strong>⬇︎</p><pre>Future&lt;News&gt; fetchNews(date) async {<br>  final response =<br>      await http.get(Uri.parse(&#39;https://www.hpa.gov.tw/wf/newsapi.ashx?startdate=$date&amp;enddate=$date&#39;));<br><br>  if (response.statusCode == 200) {<br>    // If the server did return a 200 OK response,<br>    // then parse the JSON.<br>    // debugPrint(&#39;${response.stream.bytesToString()}&#39;);<br>    final jsonresponse = json.decode(response.body);<br>    return News.fromJson(jsonresponse[0] as Map&lt;String, dynamic&gt;);<br>  } else {<br>    // If the server did not return a 200 OK response,<br>    // then throw an exception.<br>    throw Exception(&#39;Failed to load news&#39;);<br>  }<br>}</pre><p>◎<strong>串接網路上的 API 抓取 XML 資料</strong>⬇︎</p><pre>Future&lt;List&lt;DiseaseTiles&gt;&gt; fetchDiseaseTiles(String searchTerm) async {<br>  var url = Uri.parse(<br>      &#39;https://wsearch.nlm.nih.gov/ws/query?db=healthTopics&amp;term=$searchTerm&#39;);<br>  var response = await http.get(url);<br><br>  if (response.statusCode == 200) {<br>    var document = XmlDocument.parse(response.body);<br>    var tiles = &lt;DiseaseTiles&gt;[];<br><br>    // 解析XML並創建DiseaseTiles列表<br>    var results = document.findAllElements(&#39;document&#39;);<br>    for (var result in results) {<br>      var title = result<br>          .findElements(&#39;content&#39;)<br>          .firstWhere((element) =&gt; element.getAttribute(&#39;name&#39;) == &#39;title&#39;);<br>      var fullsummary = result<br>          .findElements(&#39;content&#39;)<br>          .firstWhere(<br>              (element) =&gt; element.getAttribute(&#39;name&#39;) == &#39;FullSummary&#39;);<br>      var snippet = result<br>          .findElements(&#39;content&#39;)<br>          .firstWhere((element) =&gt; element.getAttribute(&#39;name&#39;) == &#39;snippet&#39;);<br><br>      var tile = DiseaseTiles(<br>          title: title, fullsummary: fullsummary, snippet: snippet);<br>      tiles.add(tile);<br>    }<br><br>    return tiles;<br>  } else {<br>    throw Exception(&#39;Failed to load tracks&#39;);<br>  }<br>}</pre><p>◎<strong>串接gemini API 抓取資料</strong>⬇︎</p><pre>import &#39;package:google_generative_ai/google_generative_ai.dart&#39;;<br><br>Future&lt;String?&gt; generateResponse(String userInput) async {<br>  const apiKey = ***;<br><br>  final model = GenerativeModel(<br>    model: &#39;gemini-1.5-flash-latest&#39;,<br>    apiKey: apiKey,<br>  );<br><br>  final content = [Content.text(userInput)];<br>  final response = await model.generateContent(content);<br>  return response.text;<br>}</pre><p>◎<strong>抓取 XML 資料後以 List 顯示，點選 Card 可到下一頁顯示 detail</strong>⬇︎</p><pre>ListView.builder(<br>  itemCount: diseases.length,<br>  itemBuilder: (context, index) {<br>    var disease = diseases[index];<br>    return Card.outlined(<br>      child: InkWell(<br>        onTap: () {<br>          Navigator.push(<br>              context,<br>              MaterialPageRoute(<br>                  builder: (context) =&gt; DiseaseDetail(<br>                        title: disease.title,<br>                        fullsummary: disease.fullsummary,<br>                      )));<br>        },<br>        child: ListTile(<br>          title:<br>              // Html(data: disease.title),<br>              Text(<br>            parseHtmlString(disease.title),<br>            style: const TextStyle(<br>                fontWeight: FontWeight.bold),<br>          ),<br>          subtitle: Column(<br>            crossAxisAlignment: CrossAxisAlignment.start,<br>            children: [<br>              Html(data: disease.snippet),<br>              // Text(<br>              //   maxLines: 4,<br>              // ),<br>            ],<br>          ),<br>        ),<br>      ),<br>    );<br>  },<br>),</pre><p>◎<strong>將 JSON 轉換成自訂型別</strong>⬇︎</p><pre>class News {<br>  final String title;<br>  final String body;<br>  ・・・<br><br>  const News({<br>    ・・・<br>  });<br><br>  factory News.fromJson(Map&lt;String, dynamic&gt; json) {<br>    return switch (json) {<br>      {<br>        ・・・<br>      } =&gt;<br>        News(<br>          ・・・<br>        ),<br>      _ =&gt; throw const FormatException(&#39;Failed to load News.&#39;),<br>    };<br>  }<br>}</pre><p>◎<strong>將 XML 轉換成自訂型別</strong>⬇︎</p><pre>class DiseaseTiles {<br>  final String title;<br>    ・・・<br><br>  DiseaseTiles({<br>    ・・・<br>  });<br>}</pre><p>◎<strong>畫面正在抓資料時顯示資料下載中</strong>⬇︎</p><pre>if (searchTerm.isEmpty) {<br>  return const SizedBox();<br>} else {<br>  return const CircularProgressIndicator();<br>}</pre><p>◎<strong>抓不到資料，畫面上顯示錯誤資訊</strong>⬇︎</p><pre>if (snapshot.hasError) {<br>  return Text(&#39;hasError ${snapshot.error}&#39;);<br>}</pre><p>◎<strong>下拉更新功能</strong>⬇︎</p><pre>Future&lt;void&gt; refresh() async {<br>  setState(() {<br>    futureDiseaseTiles = fetchDiseaseTiles(searchTerm);<br>  });<br>  await futureDiseaseTiles;<br>}<br><br>RefreshIndicator(<br>  onRefresh: refresh,<br>  child: ListView.builder(<br>    itemCount: diseases.length,<br>    itemBuilder: (context, index) {<br>      ・・・<br>    },<br>  ),<br>);</pre><p>◎<strong>使用 SearchBar 實現 search 功能</strong>⬇︎</p><pre>SearchAnchor(<br>  builder: (context, controller) {<br>    return SearchBar(<br>      leading: const Icon(Icons.search),<br>      controller: controller,<br>      hintText: &#39;Search disease&#39;,<br>      textInputAction: TextInputAction.search,<br>      onSubmitted: (value) {<br>        setState(() {<br>          ・・・<br>        });<br>      },<br>    );<br>  },<br>  suggestionsBuilder:<br>      (BuildContext context, SearchController controller) {<br>    ・・・<br>  },<br>),</pre><p>◎<strong>使用 FavQs API 開發註冊登入功能</strong>⬇︎</p><pre>Future&lt;void&gt; _postData() async {<br>  try {<br>    final response = await http.post(<br>      Uri.parse(apiUrl),<br>      headers: &lt;String, String&gt;{<br>        &#39;Authorization&#39;: ・・・,<br>        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>      },<br>      body: jsonEncode({<br>        &quot;user&quot;: {<br>          &#39;login&#39;: loginController.text,<br>          &#39;password&#39;: passwordController.text,<br>          // Add any other data you want to send in the body<br>        }<br>      }),<br>    );<br><br>    final responseData = jsonDecode(response.body);<br>    debugPrint(&#39;Response data: ${response.body}&#39;);<br><br>    ・・・<br><br>    if (response.statusCode == 200) {<br>      // Successful POST request, handle the response here<br>      result =<br>          &#39;User-Token: ${responseData[&#39;User-Token&#39;]}\nLogin: ${responseData[&#39;login&#39;]}\nEmail: ${responseData[&#39;email&#39;]}&#39;;<br>      login = responseData[&#39;login&#39;];<br>      debugPrint(login);<br>      if (login == loginController.text) {<br>        ・・・<br>      } else {<br>        snack(warning, context);<br>        debugPrint(&quot;here&quot;);<br>      }<br>    } else {<br>      // If the server returns an error response, throw an exception<br>      throw Exception(<br>          &quot;Request to $apiUrl failed with status ${response.statusCode}: ${response.body}&quot;);<br>    }<br>  } catch (e) {<br>    setState(() {<br>      if (warning == &#39;&#39;) {<br>        result = &#39;Error:\n$e&#39;;<br>        warning = result;<br>      }<br>      snack(warning, context);<br>      warning = &#39;&#39;;<br>    });<br>  }<br><br>  ・・・<br>}</pre><p>◎<strong>使用 showDialog 顯示登入成功</strong>⬇︎</p><pre>showDialog(<br>  context: context,<br>  builder: (BuildContext context) {<br>    return _dialogBuilder();<br>  },<br>);</pre><p>◎<strong>使用 showSnackBar 顯示登入失敗</strong>⬇︎</p><pre>void snack(String warning, BuildContext context) {<br>  SnackBar snackBar = SnackBar(<br>    content: Text(warning),<br>    behavior: SnackBarBehavior.floating,<br>  );<br>  ScaffoldMessenger.of(context).showSnackBar(snackBar);<br>}</pre><p>◎<strong>使用到 HTML 渲染</strong>⬇︎</p><pre>Html(data: ・・・)</pre><p>◎<strong>使用到 HTML 轉 String</strong>⬇︎</p><pre>String parseHtmlString(String htmlString) {<br>  final document = html_parser.parse(htmlString);<br>  final String parsedString =<br>      html_dom.DocumentFragment.html(document.body!.text).text!;<br>  return parsedString;<br>}</pre><p>◎<strong>使用到 GiffyDialog </strong>⬇︎</p><pre>GiffyDialog.image(<br>  Image.network(<br>    &quot;https://raw.githubusercontent.com/Shashank02051997/FancyGifDialog-Android/master/GIF&#39;s/gif14.gif&quot;,<br>    height: 200,<br>    fit: BoxFit.cover,<br>  ),<br>  title: const Text(<br>    &#39;No results found.&#39;,<br>    textAlign: TextAlign.center,<br>  ),<br>  content: const Text(<br>    &#39;Please re-enter the query content.&#39;,<br>    textAlign: TextAlign.center,<br>  ),<br>),</pre><p>◎<strong>使用到 flutter_spinkit</strong> ⬇︎</p><pre>SpinKitFadingCircle(<br>  color: Colors.red,<br>  size: 50.0,<br>),<br><br>SpinKitCircle(<br>  color: Colors.blue,<br>  size: 50.0,<br>);</pre><p>◎<strong>使用到 onPanUpdate</strong> ⬇︎</p><pre>Positioned(<br>  left: offset.dx,<br>  top: offset.dy,<br>  child: GestureDetector(<br>    onPanUpdate: (d) =&gt;<br>        setState(() =&gt; offset += Offset(d.delta.dx, d.delta.dy)),<br>    child: FloatingActionButton(<br>      onPressed: _presentDatePicker,<br>      backgroundColor: Colors.orange,<br>      child: const Icon(Icons.date_range_rounded),<br>    ),<br>  ),<br>),</pre><p>◎<strong>使用到 HollowText</strong> ⬇︎</p><pre>HollowText(<br>  text: snapshot.data!.title<br>      .replaceAll(RegExp(r&quot;\s+&quot;), &quot;\n&quot;),<br>  size: 23,<br>  hollowColor: Colors.white,<br>  strokeColor: Colors.black,<br>  strokeWidth: 3,<br>),</pre><p>◎<strong>使用到 url_launcher</strong> ⬇︎</p><pre>Future&lt;void&gt; _launchUrl(String url) async {<br>  Uri _url = Uri.parse(url);<br>  if (!await launchUrl(_url)) {<br>    throw Exception(&#39;Could not launch $_url&#39;);<br>  }<br>}<br><br>_launchUrl(snapshot.data!.link);</pre><p>◎<strong>使用到 DatePicker </strong>⬇︎</p><pre>void _presentDatePicker() async {<br>  final pickedDate = await showDatePicker(<br>    context: context,<br>    initialDate: DateTime.now(),<br>    firstDate: DateTime(1900),<br>    lastDate: DateTime.now(),<br>  );<br>  setState(() {<br>    if (pickedDate != null) {<br>      selectedDate = pickedDate;<br>      debugPrint(dateFormatter.format(selectedDate));<br>      futureNews = fetchNews(dateFormatter.format(selectedDate));<br>      // _age = DateTime.now().year - pickedDate.year;<br>    }<br>  });<br>}<br><br></pre><p>◎<strong>使用到 RegExp</strong> ⬇︎</p><pre>.replaceAll(RegExp(r&quot;\s+&quot;), &quot;\n&quot;),<br>RegExp limitName = RegExp(r&#39;^(?=.*[A-Za-z])[A-Za-z0-9_]+$&#39;);<br>RegExp limitEmail = RegExp(&quot;^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}\$&quot;);</pre><p>◎<strong>使用到 Flexible</strong> ⬇︎</p><pre>Flexible(<br>  child: Html(<br>      data: &#39;publication Date:\n${snapshot.data!.pubdate}&#39;),<br>),</pre><p>◎<strong>使用到 floatsutton </strong>⬇︎</p><pre>import &#39;dart:math&#39;;<br>import &#39;package:flutter/material.dart&#39;;<br>export &#39;package:draggable_widget/model/anchor_docker.dart&#39;;<br><br>enum AnchoringPosition {<br>  topLeft,<br>  topRight,<br>  bottomLeft,<br>  bottomRight,<br>  center,<br>}<br><br>class DraggableWidget extends StatefulWidget {<br>  /// The widget that will be displayed as dragging widget<br>  final Widget child;<br><br>  /// The horizontal padding around the widget<br>  final double horizontalSpace;<br><br>  /// The vertical padding around the widget<br>  final double verticalSpace;<br><br>  /// Intial location of the widget, default to [AnchoringPosition.bottomRight]<br>  final AnchoringPosition initialPosition;<br><br>  /// Intially should the widget be visible or not, default to [true]<br>  final bool intialVisibility;<br><br>  /// The top bottom pargin to create the bottom boundary for the widget, for example if you have a [BottomNavigationBar],<br>  /// then you may need to set the bottom boundary so that the draggable button can&#39;t get on top of the [BottomNavigationBar]<br>  final double bottomMargin;<br><br>  /// The top bottom pargin to create the top boundary for the widget, for example if you have a [AppBar],<br>  /// then you may need to set the bottom boundary so that the draggable button can&#39;t get on top of the [AppBar]<br>  final double topMargin;<br><br>  /// Status bar&#39;s height, default to 24<br>  final double statusBarHeight;<br><br>  /// Shadow&#39;s border radius for the draggable widget, default to 10<br>  final double shadowBorderRadius;<br><br>  /// A drag controller to show/hide or move the widget around the screen<br>  final DragController? dragController;<br><br>  final BoxShadow normalShadow;<br><br>  final BoxShadow draggingShadow;<br><br>  /// How much should the [DraggableWidget] be scaled when it is being dragged, default to 1.1<br>  final double dragAnimationScale;<br><br>  /// Touch Delay Duration. Default value is zero. When set, drag operations will trigger after the duration.<br>  final Duration touchDelay;<br><br>  const DraggableWidget({<br>    super.key,<br>    required this.child,<br>    this.horizontalSpace = 0,<br>    this.verticalSpace = 0,<br>    this.initialPosition = AnchoringPosition.bottomRight,<br>    this.intialVisibility = true,<br>    this.bottomMargin = 0,<br>    this.topMargin = 0,<br>    this.statusBarHeight = 24,<br>    this.shadowBorderRadius = 10,<br>    this.dragController,<br>    this.dragAnimationScale = 1.1,<br>    this.touchDelay = Duration.zero,<br>    this.normalShadow = const BoxShadow(<br>      color: Colors.transparent,<br>      offset: Offset(0, 4),<br>      blurRadius: 2,<br>    ),<br>    this.draggingShadow = const BoxShadow(<br>      color: Colors.black12,<br>      offset: Offset(0, 1),<br>      blurRadius: 10,<br>    ),<br>  })  : assert(statusBarHeight &gt;= 0),<br>        assert(horizontalSpace &gt;= 0),<br>        assert(verticalSpace &gt;= 0),<br>        assert(bottomMargin &gt;= 0);<br>  @override<br>  _DraggableWidgetState createState() =&gt; _DraggableWidgetState();<br>}<br><br>class _DraggableWidgetState extends State&lt;DraggableWidget&gt;<br>    with SingleTickerProviderStateMixin {<br>  double top = 0, left = 0;<br>  double boundary = 0;<br>  late AnimationController animationController;<br>  late Animation animation;<br>  double hardLeft = 0, hardTop = 0;<br>  bool offstage = true;<br><br>  AnchoringPosition? currentDocker;<br><br>  double widgetHeight = 18;<br>  double widgetWidth = 50;<br><br>  final key = GlobalKey();<br><br>  bool dragging = false;<br><br>  late AnchoringPosition currentlyDocked;<br><br>  bool? visible;<br><br>  bool get currentVisibilty =&gt; visible ?? widget.intialVisibility;<br><br>  bool isStillTouching = false;<br><br>  @override<br>  void initState() {<br>    currentlyDocked = widget.initialPosition;<br>    hardTop = widget.topMargin;<br>    animationController = AnimationController(<br>      value: 1,<br>      vsync: this,<br>      duration: const Duration(milliseconds: 150),<br>    )<br>      ..addListener(() {<br>        if (currentDocker != null) {<br>          animateSideWidget(currentDocker!);<br>        }<br>      })<br>      ..addStatusListener(<br>        (status) {<br>          if (status == AnimationStatus.completed) {<br>            hardLeft = left;<br>            hardTop = top;<br>          }<br>        },<br>      );<br><br>    animation = Tween&lt;double&gt;(<br>      begin: 0,<br>      end: 1,<br>    ).animate(CurvedAnimation(<br>      parent: animationController,<br>      curve: Curves.easeInOut,<br>    ));<br><br>    widget.dragController?._addState(this);<br><br>    WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {<br>      final widgetSize = getWidgetSize(key);<br>      if (widgetSize != null) {<br>        setState(() {<br>          widgetHeight = widgetSize.height;<br>          widgetWidth = widgetSize.width;<br>        });<br>      }<br><br>      await Future.delayed(const Duration(<br>        milliseconds: 100,<br>      ));<br>      setState(() {<br>        offstage = false;<br>        boundary = MediaQuery.of(context).size.height - widget.bottomMargin;<br>        if (widget.initialPosition == AnchoringPosition.bottomRight) {<br>          top = boundary - widgetHeight + widget.statusBarHeight;<br>          left = MediaQuery.of(context).size.width - widgetWidth;<br>          hardLeft = left;<br>          pointerUpX = left;<br>        } else if (widget.initialPosition == AnchoringPosition.bottomLeft) {<br>          top = boundary - widgetHeight + widget.statusBarHeight;<br>          left = 0;<br>        } else if (widget.initialPosition == AnchoringPosition.topRight) {<br>          top = widget.topMargin - widget.topMargin;<br>          left = MediaQuery.of(context).size.width - widgetWidth;<br>          hardLeft = left;<br>          pointerUpX = left;<br>        } else {<br>          top = widget.topMargin;<br>          left = 0;<br>        }<br>      });<br>    });<br>      super.initState();<br>  }<br><br>  @override<br>  void dispose() {<br>    animationController.dispose();<br>    super.dispose();<br>  }<br><br>  @override<br>  void didUpdateWidget(DraggableWidget oldWidget) {<br>    if (offstage == false) {<br>      WidgetsBinding.instance.addPostFrameCallback((timeStamp) {<br>        final widgetSize = getWidgetSize(key);<br>        if (widgetSize != null) {<br>          setState(() {<br>            widgetHeight = widgetSize.height;<br>            widgetWidth = widgetSize.width;<br>          });<br>        }<br>        setState(() {<br>          boundary = MediaQuery.of(context).size.height - widget.bottomMargin;<br>          animateSideWidget(currentlyDocked);<br>        });<br>      });<br>    }<br>    super.didUpdateWidget(oldWidget);<br>  }<br><br>  var pointerUpX = .0;<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Positioned(<br>      top: top,<br>      left: left,<br>      child: AnimatedSwitcher(<br>        duration: const Duration(<br>          milliseconds: 150,<br>        ),<br>        transitionBuilder: (child, animation) {<br>          return ScaleTransition(<br>            scale: animation,<br>            child: child,<br>          );<br>        },<br>        child: !currentVisibilty<br>            ? Container()<br>            : Listener(<br>                onPointerUp: (v) {<br>                  if (!isStillTouching) {<br>                    return;<br>                  }<br>                  isStillTouching = false;<br><br>                  final p = v.position;<br>                  pointerUpX = p.dx;<br>                  currentDocker = determineDocker(p.dx, p.dy);<br>                  setState(() {<br>                    dragging = false;<br>                  });<br>                  if (animationController.isAnimating) {<br>                    animationController.stop();<br>                  }<br>                  animationController.reset();<br>                  animationController.forward();<br>                },<br>                onPointerDown: (v) async {<br>                  isStillTouching = false;<br>                  await Future.delayed(widget.touchDelay);<br>                  isStillTouching = true;<br>                },<br>                onPointerMove: (v) async {<br>                  if (!isStillTouching) {<br>                    return;<br>                  }<br>                  if (animationController.isAnimating) {<br>                    animationController.stop();<br>                    animationController.reset();<br>                  }<br><br>                  setState(() {<br>                    dragging = true;<br>                    if (v.position.dy &lt; boundary &amp;&amp;<br>                        v.position.dy &gt; widget.topMargin) {<br>                      top = max(v.position.dy - (widgetHeight) / 2, 0);<br>                    }<br><br>                    left = max(v.position.dx - (widgetWidth) / 2, 0);<br><br>                    hardLeft = left;<br>                    hardTop = top;<br>                  });<br>                },<br>                child: Offstage(<br>                  offstage: offstage,<br>                  child: Container(<br>                    key: key,<br>                    padding: EdgeInsets.symmetric(<br>                      horizontal: widget.horizontalSpace,<br>                      vertical: widget.verticalSpace,<br>                    ),<br>                    child: AnimatedContainer(<br>                        duration: const Duration(milliseconds: 150),<br>                        decoration: BoxDecoration(<br>                          borderRadius:<br>                              BorderRadius.circular(widget.shadowBorderRadius),<br>                          boxShadow: [<br>                            dragging<br>                                ? widget.draggingShadow<br>                                : widget.normalShadow<br>                            // BoxShadow(<br>                            //   color: Colors.black38,<br>                            //   offset: dragging ? Offset(0, 10) : Offset(0, 4),<br>                            //   blurRadius: dragging ? 10 : 2,<br>                            // )<br>                          ],<br>                        ),<br>                        child: Transform.scale(<br>                            scale: dragging ? widget.dragAnimationScale : 1,<br>                            child: widget.child)),<br>                  ),<br>                ),<br>              ),<br>      ),<br>    );<br>  }<br><br>  AnchoringPosition determineDocker(double x, double y) {<br>    final double totalHeight = boundary;<br>    final double totalWidth = MediaQuery.of(context).size.width;<br><br>    if (x &lt;= totalWidth / 2 &amp;&amp; y &lt;= totalHeight / 2) {<br>      return AnchoringPosition.topLeft;<br>    } else if (x &lt; totalWidth / 2 &amp;&amp; y &gt; totalHeight / 2) {<br>      return AnchoringPosition.bottomLeft;<br>    } else if (x &gt; totalWidth / 2 &amp;&amp; y &lt; totalHeight / 2) {<br>      return AnchoringPosition.topRight;<br>    } else {<br>      return AnchoringPosition.bottomRight;<br>    }<br>  }<br><br>  void animateSideWidget(AnchoringPosition docker) {<br>    final double totalWidth = MediaQuery.of(context).size.width;<br>    double remaingDistanceX = (totalWidth - widgetWidth - hardLeft);<br><br>    debugPrint(&quot;animateWidget - ${totalWidth / 2} -- $pointerUpX&quot;);<br><br>    if ((totalWidth / 2) &lt;= pointerUpX) {<br>      setState(() {<br>        left = hardLeft + (animation.value) * remaingDistanceX;<br>      });<br>    } else {<br>      setState(() {<br>        left = (1 - animation.value) * hardLeft;<br>      });<br>    }<br>  }<br><br>  void animateWidget(AnchoringPosition docker) {<br>    final double totalHeight = boundary;<br>    final double totalWidth = MediaQuery.of(context).size.width;<br><br>    switch (docker) {<br>      case AnchoringPosition.topLeft:<br>        setState(() {<br>          left = (1 - animation.value) * hardLeft;<br>          if (animation.value == 0) {<br>            top = hardTop;<br>          } else {<br>            top = ((1 - animation.value) * hardTop +<br>                (widget.topMargin * (animation.value)));<br>          }<br><br>          currentlyDocked = AnchoringPosition.topLeft;<br>        });<br>        break;<br>      case AnchoringPosition.topRight:<br>        double remaingDistanceX = (totalWidth - widgetWidth - hardLeft);<br>        setState(() {<br>          left = hardLeft + (animation.value) * remaingDistanceX;<br>          if (animation.value == 0) {<br>            top = hardTop;<br>          } else {<br>            top = ((1 - animation.value) * hardTop +<br>                (widget.topMargin * (animation.value)));<br>          }<br>          currentlyDocked = AnchoringPosition.topRight;<br>        });<br>        break;<br>      case AnchoringPosition.bottomLeft:<br>        double remaingDistanceY = (totalHeight - widgetHeight - hardTop);<br>        setState(() {<br>          left = (1 - animation.value) * hardLeft;<br>          top = hardTop +<br>              (animation.value) * remaingDistanceY +<br>              (widget.statusBarHeight * animation.value);<br>          currentlyDocked = AnchoringPosition.bottomLeft;<br>        });<br>        break;<br>      case AnchoringPosition.bottomRight:<br>        double remaingDistanceX = (totalWidth - widgetWidth - hardLeft);<br>        double remaingDistanceY = (totalHeight - widgetHeight - hardTop);<br>        setState(() {<br>          left = hardLeft + (animation.value) * remaingDistanceX;<br>          top = hardTop +<br>              (animation.value) * remaingDistanceY +<br>              (widget.statusBarHeight * animation.value);<br>          currentlyDocked = AnchoringPosition.bottomRight;<br>        });<br>        break;<br>      case AnchoringPosition.center:<br>        double remaingDistanceX =<br>            (totalWidth / 2 - (widgetWidth / 2)) - hardLeft;<br>        double remaingDistanceY =<br>            (totalHeight / 2 - (widgetHeight / 2)) - hardTop;<br>        // double remaingDistanceX = (totalWidth - widgetWidth - hardLeft) / 2.0;<br>        // double remaingDistanceY = (totalHeight - widgetHeight - hardTop) / 2.0;<br>        setState(() {<br>          left = (animation.value) * remaingDistanceX + hardLeft;<br>          top = (animation.value) * remaingDistanceY + hardTop;<br>          currentlyDocked = AnchoringPosition.center;<br>        });<br>        break;<br>      default:<br>    }<br>  }<br><br>  Size? getWidgetSize(GlobalKey key) {<br>    final keyContext = key.currentContext;<br>    if (keyContext != null) {<br>      final box = keyContext.findRenderObject() as RenderBox;<br>      return box.size;<br>    } else {<br>      return null;<br>    }<br>  }<br><br>  void _showWidget() {<br>    setState(() {<br>      visible = true;<br>    });<br>  }<br><br>  void _hideWidget() {<br>    setState(() {<br>      visible = false;<br>    });<br>  }<br><br>  void _animateTo(AnchoringPosition anchoringPosition) {<br>    if (animationController.isAnimating) {<br>      animationController.stop();<br>    }<br>    animationController.reset();<br>    currentDocker = anchoringPosition;<br>    animationController.forward();<br>  }<br><br>  Offset _getCurrentPosition() {<br>    return Offset(left, top);<br>  }<br>}<br><br>class DragController {<br>  _DraggableWidgetState? _widgetState;<br>  void _addState(_DraggableWidgetState widgetState) {<br>    _widgetState = widgetState;<br>  }<br><br>  /// Jump to any [AnchoringPosition] programatically<br>  void jumpTo(AnchoringPosition anchoringPosition) {<br>    _widgetState?._animateTo(anchoringPosition);<br>  }<br><br>  /// Get the current screen [Offset] of the widget<br>  Offset? getCurrentPosition() {<br>    return _widgetState?._getCurrentPosition();<br>  }<br><br>  /// Makes the widget visible<br>  void showWidget() {<br>    _widgetState?._showWidget();<br>  }<br><br>  /// Hide the widget<br>  void hideWidget() {<br>    _widgetState?._hideWidget();<br>  }<br>}</pre><p>◎<strong>使用到 Slider</strong> <strong>&amp;</strong> <strong>round</strong>⬇︎</p><pre>Slider(<br>  value: (_currentSliderPrimaryValue != 0)<br>      ? _currentSliderPrimaryValue<br>      : age.toDouble(),<br>  label: _currentSliderPrimaryValue.round().toString(),<br>  max: 150,<br>  divisions: 150,<br>  onChanged: (double value) {<br>    setState(() {<br>      _currentSliderPrimaryValue = value;<br>    });<br>  },<br>),<br>Text(<br>  _currentSliderPrimaryValue.round().toString(),<br>  style: const TextStyle(fontSize: 20),<br>),</pre><p>◎<strong>使用到 ToggleButtons</strong> ⬇︎</p><pre>ToggleButtons(<br>  direction: Axis.horizontal,<br>  onPressed: (int index) {<br>    setState(() {<br>      // The button that is tapped is set to true, and the others to false.<br>      for (int i = 0; i &lt; _selectedsexual.length; i++) {<br>        _selectedsexual[i] = i == index;<br>      }<br>    });<br>  },<br>  borderRadius: const BorderRadius.all(Radius.circular(8)),<br>  selectedBorderColor: Colors.red[700],<br>  selectedColor: Colors.white,<br>  fillColor: Colors.red[200],<br>  color: Colors.red[400],<br>  constraints: const BoxConstraints(<br>    minHeight: 40.0,<br>    minWidth: 70.0,<br>  ),<br>  isSelected: _selectedsexual,<br>  children: sexual,<br>),</pre><p>◎<strong>使用到 dash_chat_2</strong> ⬇︎</p><pre>DashChat(<br>  typingUsers: typing,<br>  currentUser: user,<br>  onSend: _onSend,<br>  messages: messages,<br>  inputOptions: InputOptions(<br>      alwaysShowSend: true, sendButtonBuilder: _sendButtons),<br>  messageOptions: MessageOptions(<br>    showOtherUsersAvatar: true,<br>    currentUserContainerColor: const Color(0xff607DEF),<br>    showTime: true,<br>    avatarBuilder: (bot, onPressAvatar, onLongPressAvatar) {<br>      return DefaultAvatar(<br>          user: bot,<br>          fallbackImage:<br>              const AssetImage(&quot;assets/gemini_logo.png&quot;));<br>    },<br>  ),<br>  scrollToBottomOptions: ScrollToBottomOptions(<br>    scrollToBottomBuilder: _scrollToBottomBuilder,<br>  ),<br>),</pre><p>◎<strong>使用到 HideKeyboard</strong> ⬇︎</p><pre>GestureDetector(<br>  child: child,<br>  onTap: () {<br>    FocusScopeNode currentFocus = FocusScope.of(context);<br>    if (!currentFocus.hasPrimaryFocus &amp;&amp;<br>        currentFocus.focusedChild != null) {<br>      /// 取消焦点，相当于关闭键盘<br>      FocusManager.instance.primaryFocus!.unfocus();<br>    }<br>  },<br>);</pre><p>◎<strong>使用到 IconButton</strong> ⬇︎</p><pre>IconButton(<br>  icon: Icon(<br>      !_isObscure ? Icons.visibility : Icons.visibility_off),<br>  onPressed: () {<br>    setState(() {<br>      _isObscure = !_isObscure;<br>    });<br>  },<br>),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gJQO_BKoqLKa0pJXeIUx2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7jXKU9owQ5GPhQ3gFyIBcw.png" /><figcaption><strong>控制密碼能否被看見</strong></figcaption></figure><p>◎<strong>使用到 FilteringTextInputFormatter</strong> ⬇︎</p><pre>TextFormField(<br>  obscureText: _isObscure,<br>  controller: passwordController,<br>  decoration: InputDecoration(<br>    prefixIcon: const Icon(Icons.lock),<br>    suffixIcon: ・・・<br>    labelText: &quot;Password *&quot;,<br>    hintText: &quot;Only allow num 0-9&quot;,<br>  ),<br>  inputFormatters: [<br>    FilteringTextInputFormatter.allow(RegExp(&quot;[0-9.]&quot;))<br>  ],<br>),</pre><p>◎<strong>使用到 BackdropFilter</strong> ⬇︎</p><pre>BackdropFilter(<br>  filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),<br>  child: Container(<br>    width: 300.0,<br>    height: (widget.title == &#39;SIGN UP&#39;) ? 530 : 430,<br>    decoration: BoxDecoration(<br>        color: Colors.grey.shade200.withOpacity(0.5)),<br>    child: Center(<br>      child: (widget.title == &#39;SIGN UP&#39;)<br>          ? SignUp(title: widget.title)<br>          : Login(title: widget.title),<br>    ),<br>  ),<br>),</pre><p>◎<strong>包含其它欄位的註冊畫面</strong>⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*236HqUsSdQrpixzfCK-B6w.png" /></figure><p>◎<strong>動畫</strong>⬇︎</p><pre>_animationController = AnimationController(<br>  duration: const Duration(seconds: 1),<br>  vsync: this, // 使用 vsync<br>)..repeat(reverse: true);<br><br>_animation = Tween&lt;Offset&gt;(<br>  begin: const Offset(0, -0.1),<br>  end: const Offset(0, 0.1),<br>).animate(CurvedAnimation(<br>  parent: _animationController,<br>  curve: Curves.easeInOut,<br>));<br><br>SlideTransition(<br>  position: _animation,<br>  child: const Text(<br>    &#39;Unable to fetch data.\nPlease try again later.&#39;,<br>    style: TextStyle(<br>      fontSize: 18,<br>      color: Color.fromARGB(255, 59, 16, 16),<br>    ),<br>    textAlign: TextAlign.center,<br>  ),<br>),</pre><p>◎<strong>資料儲存</strong>⬇︎</p><pre>final prefs = await SharedPreferences.getInstance();<br>final userData = json.encode({<br>  &#39;token&#39;: token,<br>  &#39;userId&#39;: login,<br>  &#39;email&#39;: email,<br>});<br><br>debugPrint(&#39;sign up&#39;);<br>debugPrint(&#39;token: $token&#39;);<br>debugPrint(&#39;login: $login&#39;);<br>debugPrint(&#39;email: $email&#39;);<br><br>prefs.setString(&#39;userData&#39;, userData);</pre><p>◎<strong>自動登入</strong>⬇︎</p><pre>Future&lt;bool&gt; tryAutoLogin() async {<br>  final prefs = await SharedPreferences.getInstance();<br>  if (!prefs.containsKey(&#39;userData&#39;)) {<br>    return false; // 没有&#39;userData&#39;这一项，返回 false，自动登录失败<br>  }<br>  final extractedUserData = json.decode(prefs.getString(&#39;userData&#39;)!);<br>  token = extractedUserData[&#39;token&#39;].toString();<br>  login = extractedUserData[&#39;userId&#39;].toString();<br>  email = extractedUserData[&#39;email&#39;].toString();<br><br>  debugPrint(&#39;log in&#39;);<br>  debugPrint(&#39;token: $token&#39;);<br>  debugPrint(&#39;login: $login&#39;);<br>  debugPrint(&#39;email: $email&#39;);<br><br>  Navigator.of(context).pop();<br>  Navigator.push(<br>    context,<br>    MaterialPageRoute(<br>      builder: (context) =&gt; Home(<br>        email: email,<br>        name: login,<br>        token: token,<br>      ),<br>    ),<br>  );</pre><p>◎<strong>刪除登入</strong>⬇︎</p><pre>Future&lt;void&gt; logout() async {<br>  final prefs = await SharedPreferences.getInstance();<br>  prefs.clear();<br>}</pre><blockquote>心得：</blockquote><p>雖然這次Flutter的期末專案與IOS一樣是要串接API，但我覺得Flutter的難度似乎更高。這次除了原本的JSON檔外，我還嘗試用了XML檔，也接了上學期Peter推薦的Google Gemini API。在這次的App中我使用了很多很多的Package，發現到了Flutter的Package方便之處！像是Chat Room的UI部分便是由Package所製作出來的！感謝所有所有開發Package的開發者！</p><p>在整個學期過完後，深刻的體悟到了上學期SwiftUI的美好，以及製作遊戲真的好難啊！不過在學習完Flutter後，便能開發跨平台的App啦！</p><p>謝謝這學期Peter的教導，也祝大家都能有個充實的暑假～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d129676b7814" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-04-%E6%9C%9F%E6%9C%AB%E5%B0%88%E9%A1%8C-d129676b7814">【Flutter 跨平台 App 程式設計入門】#04 期末專題</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【Flutter 跨平台 App 程式設計入門】#03 快艇骰子 Yahtzee]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-03-%E5%BF%AB%E8%89%87%E9%AA%B0%E5%AD%90-yahtzee-1c84b334f3cc?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c84b334f3cc</guid>
            <category><![CDATA[dice]]></category>
            <category><![CDATA[flutter-app-development]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[yahtzee]]></category>
            <category><![CDATA[flutter-game]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Sun, 05 May 2024 14:44:47 GMT</pubDate>
            <atom:updated>2024-05-08T16:19:03.568Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>本次APP的主題是製作Yahtzee遊戲～</em></strong></p><blockquote>GitHub連結：</blockquote><p><a href="https://github.com/Fangyil/Flutter-HW3.git">GitHub - Fangyil/Flutter-HW3</a></p><blockquote>App使用影片：</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FTEG1M7dkJSA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DTEG1M7dkJSA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FTEG1M7dkJSA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea0de2a6f9246971543402bebd04f8a8/href">https://medium.com/media/ea0de2a6f9246971543402bebd04f8a8/href</a></iframe><blockquote>App頁面預覽：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Czq4Gl9-so0ulH1PS01Gkg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8H7wJxRpcrjmaXD2JTpruw.png" /><figcaption>左圖為初始畫面，右圖為點入 Friend 的歷史成績</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_rKWhjPNmo_XforWiuWbrg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpjxJCqyDdOeEOFAovHQqQ.png" /><figcaption>左圖為 點入 START的畫面，右圖為結算畫面</figcaption></figure><blockquote>使用到的功能：</blockquote><p>◎ 選擇 <strong><em>Flutter</em></strong> 技術開發。</p><p>◎ 跟朋友一起用同一隻手機 PK⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wYiIceH_DF3LzwtXJXxReA.png" /></figure><p>◎ 計分板有 26 格，一人 13 格。遊戲有 13 個回合，每回合玩家依骰子點數選擇格子填入分數，已填寫的格子不能再填寫。⬇︎</p><p>◎ 畫面上顯示目前是第幾回合⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*V0BAI6dyZDu5LFotx6F93Q.png" /></figure><p>◎ 遊戲規則和計分方式⬇︎</p><pre> //dice points<br>    HomePage.click.value = !HomePage.click.value;<br>    for (var i = 0; i &lt; diceList.length; i++) {<br>      ...<br>    }<br>    //score<br>    for (var i = player + 1; i &lt; blankList.length; i += 3) {<br>      if (i ~/ 3 == 0 ||<br>          i ~/ 3 == 2 ||<br>          i ~/ 3 == 4 ||<br>          i ~/ 3 == 6 ||<br>          i ~/ 3 == 8 ||<br>          i ~/ 3 == 10) {<br>        ...<br>      }<br>    }<br>    for (var i = 0; i &lt; pointList.length; i++) {<br>      if (pointList[i].times &gt;= 3) {<br>        ...<br>        if (pointList[0].times == 2 ||<br>            pointList[1].times == 2 ||<br>            pointList[2].times == 2 ||<br>            pointList[3].times == 2 ||<br>            pointList[4].times == 2 ||<br>            pointList[5].times == 2) {<br>          ...<br>      }<br>      if (pointList[i].times &gt;= 4) {<br>        tmp = diceList[0].point +<br>            diceList[1].point +<br>            diceList[2].point +<br>            diceList[3].point +<br>            diceList[4].point +<br>            5;<br>        ...<br>      }<br>      if (pointList[i].times == 5) {<br>        if (blankList[34].value == -1 ||<br>            blankList[35].value == -1) {<br>          ...<br>        }<br>      }<br>    }<br>    if ((pointList[0].times &gt; 0 &amp;&amp;<br>            pointList[1].times &gt; 0 &amp;&amp;<br>            pointList[2].times &gt; 0 &amp;&amp;<br>            pointList[3].times &gt; 0) ||<br>        (pointList[1].times &gt; 0 &amp;&amp;<br>            pointList[2].times &gt; 0 &amp;&amp;<br>            pointList[3].times &gt; 0 &amp;&amp;<br>            pointList[4].times &gt; 0) ||<br>        (pointList[2].times &gt; 0 &amp;&amp;<br>            pointList[3].times &gt; 0 &amp;&amp;<br>            pointList[4].times &gt; 0 &amp;&amp;<br>            pointList[5].times &gt; 0)) {<br>      ...<br>    }<br>    if ((pointList[0].times == pointList[1].times &amp;&amp;<br>            pointList[1].times == pointList[2].times &amp;&amp;<br>            pointList[2].times == pointList[3].times &amp;&amp;<br>            pointList[3].times == pointList[4].times &amp;&amp;<br>            pointList[0].times == 1) ||<br>        (pointList[5].times == pointList[1].times &amp;&amp;<br>            pointList[1].times == pointList[2].times &amp;&amp;<br>            pointList[2].times == pointList[3].times &amp;&amp;<br>            pointList[3].times == pointList[4].times &amp;&amp;<br>            pointList[5].times == 1)) {<br>      ...<br>    }<br>    ...<br>    if (player == 0) {<br>      blankList[40].tmpValue = tmp;<br>    } else {<br>      blankList[41].tmpValue = tmp;<br>    }<br>    HomePage.blankList.value = blankList;<br>    _times--;<br>    HomePage.click.value = !HomePage.click.value;<br>    for (var i = 0; i &lt; diceList.length; i++) {<br>      if (diceList[i].selectState) {<br>        diceList[i].selectTime = _times+1;<br>      }<br>    }<br>  },<br>)</pre><p>◎ 顯示目前輪到的玩家⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*V0BAI6dyZDu5LFotx6F93Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*uF8CacBg0DYymju_attXcA.png" /><figcaption>輪到 Player 1 或 Player 2</figcaption></figure><p>◎ 每回合最多可丟 3 次骰子，第一次丟 5 顆骰子，第 2 次和第 3 次可選擇要保留的骰子，只重丟部分的骰子⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z5LE22eftrQWiJC-xN5N4w.png" /><figcaption>尚未骰骰子的畫面</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fv5adaNPlgzIrAOIwTpE_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tf7-y3nuPfCxOwDAnoJPHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VwOhelgK8cRhmaJIdt5AEg.png" /><figcaption>依序為第一次骰、第二次骰、第三次骰</figcaption></figure><p>◎ 選擇尚未填寫的計分格填入分數⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7mKLTxe8JBqXGulR-LkEuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FWbhaTEqflHvVufHwWbg5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ueq40UdHQVYbhdjwtUD8g.png" /><figcaption>依序為 尚未選擇、選擇格子、成功填入</figcaption></figure><p>◎ 顯示還可以丟幾次骰子⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*Id0m7alq0npgsWiSPz5HwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*TcOZvXirrhEDKYZ-y-5Dsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*6aGk5U1N_SWkrwD5uZbDRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*FWK_vPXDHR2URjHa588Aqg.png" /><figcaption>當 0 時為白框無法骰</figcaption></figure><p>◎ 顯示目前的總分，並且依據骰子的點數在畫面的格子顯示提示的分數⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hBBwZzFUFh8e9a2WM89nvA.png" /></figure><p>◎ 顯示 1 ~ 6 分數的總合。總和大於等於 63 時可額外得 35 分⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*rzJw7dORhrXgUuY9V3tZCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*EdrlTZ8q-QHRRMN7W4jO8g.png" /><figcaption>John剛好是 204 + 24 + 35 = 263 分 （有 Bonus ）</figcaption></figure><p>◎ 顯示贏家的名字和雙方的分數，點選 Replay 可再玩一次⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpjxJCqyDdOeEOFAovHQqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_K5HKrDZ28AnWFTEtmw7wg.png" /><figcaption>左圖為結算畫面，右圖為點選 REPLAY 後的畫面</figcaption></figure><p>◎ 畫面上顯示累積的成績⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHS4uV52sv8ggoooZ1NI5g.png" /></figure><p>◎ 點選格子後，再點選按鈕完成輸入⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhWZpoQXJo9oyuKfLJrv1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B1Ib_Sxq9XTlt5uV99cuag.png" /><figcaption>點選格子➡️點選 PLAY ➡️分數填入</figcaption></figure><p>◎ 第一次 Yahtzee 得 50 分，之後每次丟出 Yahtzee 得 100 分⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-qslVD4wz_H_gHIaQBghsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WhaSaF6gAf5xm2s99qbfYg.png" /><figcaption>左圖為第一次，右圖為第二次</figcaption></figure><p>◎ ValueListenableBuilder4⬇︎</p><pre>class ValueListenableBuilder4&lt;A, B, C, D&gt; extends StatelessWidget {<br>  const ValueListenableBuilder4({<br>    required this.first,<br>    required this.second,<br>    required this.third,<br>    required this.fourth,<br>    super.key,<br>    required this.builder,<br>    this.child,<br>  });<br><br>  final ValueListenable&lt;A&gt; first;<br>  final ValueListenable&lt;B&gt; second;<br>  final ValueListenable&lt;C&gt; third;<br>  final ValueListenable&lt;D&gt; fourth;<br>  final Widget? child;<br>  final Widget Function(BuildContext context, A a, B b, C c, D d, Widget? child)<br>      builder;<br><br>  @override<br>  Widget build(BuildContext context) =&gt; ValueListenableBuilder&lt;A&gt;(<br>    valueListenable: first,<br>    builder: (_, a, __) {<br>      return ValueListenableBuilder&lt;B&gt;(<br>        valueListenable: second,<br>        builder: (context, b, __) {<br>          return ValueListenableBuilder&lt;C&gt;(<br>            valueListenable: third,<br>            builder: (context, c, __) {<br>              return ValueListenableBuilder&lt;D&gt;(<br>                valueListenable: fourth,<br>                builder: (context, d, __) {<br>                  return builder(context, a, b, c, d, child);<br>                },<br>              );<br>            },<br>          );<br>        },<br>      );<br>    },<br>  );<br>}</pre><p>◎ showDialog⬇︎</p><pre>showDialog(<br>  context: context,<br>  builder: (BuildContext context) {<br>    return SimpleDialog(<br>      title: const Text(&#39;CHOOSE YOUR PICTURE&#39;),<br>      children: &lt;Widget&gt;[<br>        SimpleDialogOption(<br>          onPressed: () {<br>            _takePhoto(click2);<br>          },<br>          child: const Padding(<br>            padding: EdgeInsets.symmetric(vertical: 6),<br>            child: Text(&#39;TAKE A PHOTO 📷&#39;),<br>          ),<br>        ),<br>        SimpleDialogOption(<br>          onPressed: () {<br>            _openGallery(click2);<br>          },<br>          child: const Padding(<br>            padding: EdgeInsets.symmetric(vertical: 6),<br>            child: Text(&#39;FROM YOUR ALBUM 🖼️&#39;),<br>          ),<br>        ),<br>      ],<br>    );<br>  },<br>);</pre><p>◎ ImagePicker⬇︎</p><pre>_takePhoto(String a) async {<br>  final image = await ImagePicker().pickImage(source: ImageSource.camera);<br>  setState(() {<br>    if (image != null) {<br>      ...<br>      Navigator.of(context).pop();<br>    }<br>  });<br>}<br><br>_openGallery(String a) async {<br>  final image = await ImagePicker().pickImage(source: ImageSource.gallery);<br>  setState(() {<br>    if (image != null) {<br>      ...<br>      Navigator.of(context).pop();<br>    }<br>  });<br>}</pre><p>◎ TextField⬇︎</p><pre>TextField(<br>  style: const TextStyle(<br>      ...<br>  textAlign: TextAlign.center,<br>  inputFormatters: [<br>    ...<br>  ],<br>  decoration: const InputDecoration(<br>    isCollapsed: true,<br>    ...<br>  ),<br>  controller: _controller2<br>    ..text = HomePage.playerScore.value[1].name,<br>  onSubmitted: (String value) async {<br>    await showDialog&lt;void&gt;(<br>      context: context,<br>      builder: (BuildContext context) {<br>        if (value == &#39;&#39;) {<br>          value = HomePage.playerScore.value[1].name;<br>          return AlertDialog(<br>            ...<br>          );<br>        }<br>        HomePage.playerScore.value[1].name = value;<br>        return AlertDialog(<br>          ...<br>        );<br>      },<br>    );<br>  },<br>),</pre><p>◎ Offstage⬇︎</p><pre>Offstage(<br>  offstage: ...,<br>  child: ...,<br>)</pre><blockquote>心得：</blockquote><p>這是第一次製作與遊戲相關的APP，在這次的製作過程中，不僅是只有 UI 的畫面調整，還更著重於邏輯上的思考。花了很久的時間在調整分數的出現、加總有沒有奇怪，總分的人名、頭像有沒有如預期，當 REPLAY 時分數是否有歸零。動態的畫面設計真的比靜態的難好多！！！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c84b334f3cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-03-%E5%BF%AB%E8%89%87%E9%AA%B0%E5%AD%90-yahtzee-1c84b334f3cc">【Flutter 跨平台 App 程式設計入門】#03 快艇骰子 Yahtzee</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【Flutter 跨平台 App 程式設計入門】#02 多頁面電子書 App]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-02-%E5%A4%9A%E9%A0%81%E9%9D%A2%E9%9B%BB%E5%AD%90%E6%9B%B8-app-c07ab1a8d140?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c07ab1a8d140</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[disney]]></category>
            <category><![CDATA[beauty-and-the-beast]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Sun, 07 Apr 2024 15:19:09 GMT</pubDate>
            <atom:updated>2024-04-08T03:05:06.602Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>本次APP的主題是與Beauty and the Beast！</em></strong></p><blockquote>GitHub連結：</blockquote><p><a href="https://github.com/Fangyil/Flutter-HW2.git">GitHub - Fangyil/Flutter-HW2</a></p><blockquote>App使用影片</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FF7lJJRQZl7g%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DF7lJJRQZl7g&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FF7lJJRQZl7g%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/555a83daa95074c04c9dbae1b3bc8e00/href">https://medium.com/media/555a83daa95074c04c9dbae1b3bc8e00/href</a></iframe><blockquote>使用到的功能：</blockquote><p>◎製作包含多個頁面的電子書 App ⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YcRVLbH2tjxD-wo3T-ivww.png" /><figcaption>Beauty and the Beast 電影展示</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OCav-5PH2mUe5XoyZpvUyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSBmhE_jnWyL5PhcPMyKww.png" /><figcaption>角色展示 &amp; 角色內容</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xWvJVTtRyUTjDcDLyPQRpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b3IfvmxVgBmR52aRenqdWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecn68G_fLoxXkJzlT6pzvA.png" /><figcaption>電影場景靈感發源地</figcaption></figure><p>◎每個頁面定義對應的 StatelessWidget ⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*KRd4sIXkLja4fWxYGm6uOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*bsp-7KSVXAC5bLK7FRQ5Ig.png" /><figcaption>詳情請見GitHub</figcaption></figure><p>◎定義資料的型別 ⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*X-Ml617xKB1D6zmY4mt7Bg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*dEh3bYqTvydco9zUaFy0ug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*DBtQclz_2u1auxCH4HvbJA.png" /></figure><p>◎使用 ListView.builder⬇︎</p><pre>ListView.builder(<br>      itemCount: versions.length,<br>      itemBuilder: (context, index) =&gt; InkWell(<br>        onTap: () {<br>          if (versions[index].year == &#39;1991&#39;) {<br>            ...<br>          }<br>          else {<br>            ...<br>          }<br>        },<br>        child: VersionCard(version: versions[index]),<br>      ),<br>    )</pre><p>◎使用 ListView.separated⬇︎</p><pre>ListView.separated(<br>          itemBuilder: (context, times) {<br>            ...<br>              },<br>              child: Text(<br>                placedatas[times].place,<br>                style: const TextStyle(fontSize: 18),<br>              ),<br>            );<br>          },<br>          separatorBuilder: (context, times) {<br>            return const Divider();<br>          },<br>          itemCount: placedatas.length,<br>        ),</pre><p>◎自訂 StatelessWidget 顯示 ListView 的資料⬇︎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*nlIFqZML5oDIibkKUydKrw.png" /></figure><p>◎使用 Navigator 切換頁面⬇︎</p><pre>Navigator.push(<br>              context,<br>              MaterialPageRoute(<br>                  builder: (context) =&gt; LList(placedatas: placedatas1991)),<br>            );</pre><p>◎使用 GestureDetector 偵測點擊⬇︎</p><pre>GestureDetector(<br>          onTap: () {<br>            ...<br>          },<br>          child: RoleTile(role: roles[index]),<br>        )</pre><p>◎使用 InkWell 偵測點擊⬇︎</p><pre>InkWell(<br>        onTap: () {<br>          if (versions[index].year == &#39;1991&#39;) {<br>            ...<br>          }<br>          else {<br>            ...<br>          }<br>        },<br>        child: VersionCard(version: versions[index]),<br>      ),</pre><p>◎使用 TextButton 偵測點擊⬇︎</p><pre>TextButton(<br>    onPressed: () {<br>      ...<br>    },<br>    child: ...<br>  )</pre><p>◎使用 GridView 製作格子狀排列的畫面⬇︎</p><pre>GridView.builder(<br>      padding: const EdgeInsets.fromLTRB(2.0, 0.0, 2.0, 0.0),<br>      itemCount: roles.length,<br>      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(<br>        ...<br>      ),<br>      itemBuilder: (context, index) {<br>        return ...;<br>      },<br>    )</pre><p>◎使用 DefaultTabController、TabBar、TabBarView 製作 tab 分頁⬇︎</p><pre>DefaultTabController(<br>        length: 3,<br>        child: Scaffold(<br>          appBar: AppBar(<br>            toolbarHeight: 45,<br>            bottom: const TabBar(<br>              ...<br>              ),<br>              tabs: [<br>                Tab(icon: Icon(Icons.movie, size: 33)),<br>                Tab(icon: Icon(Icons.groups_3, size: 36)),<br>                Tab(icon: Icon(Icons.castle, size: 33)),<br>              ],<br>            ),<br>            title: ...<br>          ),<br>          body: const TabBarView(<br>            children: [<br>              Movie(),<br>              Character(),<br>              Place(),<br>            ],<br>          ),<br>        ),<br>      ),</pre><p>◎使用 Card widget⬇︎</p><pre>Card(<br>      elevation: 15, //設置卡片陰影的深度<br>      shape: RoundedRectangleBorder(<br>        borderRadius: BorderRadius.circular(20),<br>      ),<br>      margin: const EdgeInsets.all(10), //設置卡片外邊距<br>      child: Column(<br>        ...<br>    )</pre><p>◎使用 ListTile⬇︎</p><pre>ListTile(<br>            leading: ClipOval(//設置圓形頭像<br>              ...<br>            ),<br>            title: Text(video.name),<br>            subtitle: Text(video.year),<br>          ),</pre><p>◎播放背景音樂 ⬇︎</p><pre>import &#39;package:audioplayers/audioplayers.dart&#39;;<br><br><br>  final player = AudioPlayer();<br><br>  void _toggleMusic() {<br>    ...<br>        player.play(AssetSource(&#39;batb.mp3&#39;));<br>    ...<br>        player.pause();<br>    ...<br>  }</pre><p>◎使用 IconButton⬇︎</p><pre>IconButton.outlined(<br>        onPressed: _toggleMusic,<br>        icon: ...,<br>      ),</pre><blockquote>心得</blockquote><p>這次的製作過程碰到了許多有趣的問題，幸好網路上有許多大神提供他們的解決方式，最大的困難點大概就是播放鍵會隨著使用者按而改變以及List產生的內容會有條件限制，不過好在最終有想到解決方式！</p><p>有一些Peter投影片上沒提到的功能也有嘗試製作看看，意外的成果還挺不錯的，StatefulWidget也有試著用，期待下次正式與它接觸！！</p><p>順帶一提，沒想到有個發自愛心的Disney Wiki，幫了很大的忙，非常謝謝他～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c07ab1a8d140" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-02-%E5%A4%9A%E9%A0%81%E9%9D%A2%E9%9B%BB%E5%AD%90%E6%9B%B8-app-c07ab1a8d140">【Flutter 跨平台 App 程式設計入門】#02 多頁面電子書 App</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【Flutter 跨平台 App 程式設計入門】#01 打造吸睛的 About 頁面]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-01-%E6%89%93%E9%80%A0%E5%90%B8%E7%9D%9B%E7%9A%84-about-%E9%A0%81%E9%9D%A2-13da994b40a0?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/13da994b40a0</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[first-time]]></category>
            <category><![CDATA[alice-in-wonderland]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Thu, 14 Mar 2024 17:07:25 GMT</pubDate>
            <atom:updated>2024-03-15T03:54:11.326Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>本次的主題是愛麗絲夢遊仙境~</em></strong></p><blockquote>GitHub連結：</blockquote><p><a href="https://github.com/Fangyil/Flutter-HW1.git">GitHub - Fangyil/Flutter-HW1</a></p><blockquote>頁面預覽：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fzmgp3k0hyaf680a54yzVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gTioe6wkgNah7g-AC7sZEw.png" /><figcaption>Alice in Wonderland!!</figcaption></figure><blockquote>使用到的功能：</blockquote><p>◎ Text &amp; Icon⬇︎</p><pre>Text(&#39;相關電影&#39;),<br><br>Icon(Icons.movie),</pre><p>◎ Image⬇︎</p><pre>Image.network(&#39;...&#39;,),<br><br>Image.asset(<br>            &#39;assets/AliceInWonderland.webp&#39;,<br>            fit: BoxFit.cover,<br>          ),</pre><p>◎ Column &amp; Row⬇︎</p><pre>Column(<br>      children: [<br>        ...<br>      ],<br>    ),<br><br>Row(<br>      mainAxisSize: MainAxisSize.min,<br>      children: [...],<br>    );</pre><p>◎ SafeArea &amp; SingleChildScrollView（上下滾動）⬇︎</p><pre>SafeArea(<br>        child: SingleChildScrollView(<br>          scrollDirection: Axis.vertical,<br>          child: Column(<br>            children: [<br>              ...<br>            ],<br>          ),<br>        ),<br>      ),</pre><p>◎定義多個 stateless widget 類別 &amp; SizeBox⬇︎</p><pre>class Movies extends StatelessWidget {<br>  const Movies({<br>    super.key,<br>  });<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Row(<br>      children: [<br>        ...<br>      ],<br>    );<br>  }<br>}<br><br>class bank extends StatelessWidget {<br>  const bank({<br>    super.key,<br>  });<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return SizedBox(<br>      ...<br>    );<br>  }<br>}</pre><p>◎ Container &amp; Color⬇︎</p><pre>Container(<br>          child: Icon(<br>            Icons.play_circle_outline,<br>            color: Colors.white,<br>            size: 50,<br>          ),<br>        ),</pre><p>◎ Transform &amp; Padding⬇︎</p><pre>Transform.rotate(<br>          angle: ...,<br>          child: ...,<br>        ),<br>        Padding(padding: const EdgeInsets.only(...)),</pre><p>◎ Expanded⬇︎</p><pre>Expanded(<br>        child: Image.network(<br>          &#39;...&#39;,<br>        ),<br>      ),</pre><p>◎ Stack &amp; Positioned⬇︎</p><pre>Stack(<br>      children: [<br>        ...<br>        Positioned(<br>          top: 10,<br>          left: 10,<br>          child: Container(<br>            ...<br>          ),<br>        ),<br>      ],<br>    );</pre><p>◎ AppBar &amp; Divider⬇︎</p><pre>AppBar(<br>      ...<br>      foregroundColor: Colors.white,<br>      backgroundColor: Colors.blue,<br>    ),<br><br>Divider(<br>      thickness: 2,<br>      height: 15,<br>      indent: 10,<br>      endIndent: 10,<br>    );</pre><p>◎ CircleAvatar &amp; ClipRRect⬇︎</p><pre>CircleAvatar(<br>          radius: 45,<br>          backgroundImage: NetworkImage(<br>              &#39;...&#39;),<br>        ),<br><br>ClipRRect(<br>        borderRadius: BorderRadius.circular(15),<br>        child: ...<br>      ),</pre><p>◎ Wrap⬇︎</p><pre><br>Wrap(<br>    spacing: 5,<br>    runSpacing: 5,<br>    children: [<br>       ...<br>       ],<br>    ),</pre><blockquote>心得：</blockquote><p>新的學期學習新的語言～第一次上手Flutter挺迅速的，跟SwiftUI比起來多了一些快速移除的功能，非常方便！不過在Icon的部分，圖示感覺搜尋起來有些麻煩，有些想要的圖案都找不到😢。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13da994b40a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/flutter-%E8%B7%A8%E5%B9%B3%E5%8F%B0-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88%E5%85%A5%E9%96%80-01-%E6%89%93%E9%80%A0%E5%90%B8%E7%9D%9B%E7%9A%84-about-%E9%A0%81%E9%9D%A2-13da994b40a0">【Flutter 跨平台 App 程式設計入門】#01 打造吸睛的 About 頁面</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【IOS 應用程式開發入門】#04 期末專題]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-04-%E6%9C%9F%E6%9C%AB%E5%B0%88%E9%A1%8C-9d577c6bf8ab?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d577c6bf8ab</guid>
            <category><![CDATA[nasa]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[art]]></category>
            <category><![CDATA[popular-science]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Sun, 31 Dec 2023 21:02:50 GMT</pubDate>
            <atom:updated>2024-01-01T03:50:17.541Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>本次APP的主題是與太空有關～</em></strong></p><blockquote>GitHub連結：</blockquote><p><a href="https://github.com/Fangyil/IOS-HW4.git">GitHub - Fangyil/IOS-HW4</a></p><blockquote>App使用影片：</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhIxPWs_zZJg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhIxPWs_zZJg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0949cc1ce219cb0735755d095d57d1e2/href">https://medium.com/media/0949cc1ce219cb0735755d095d57d1e2/href</a></iframe><blockquote>App Icon及頁面預覽：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*sIaQgroKKfiK4rEcaMi5Rw.png" /><figcaption>App Icon</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EMHGC-TJ17Q7gBS868UQMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ovSFvTIcgT9iWHvz1NaHnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UncFEzAGh7j-3Xo9MK90Wg.png" /></figure><blockquote>使用到的功能：</blockquote><p>◎<strong>使用 async / await 串接後台的 API 抓取 JSON 資料後以 List 顯示，點選 row 可到下一頁顯示 detail，使用到三個 API。</strong>⬇︎</p><pre>import Foundation<br>import SwiftUI<br><br>@Observable class APOD_DataFetcher {<br>    var items = [**]()<br>    <br>    enum FetchError: Error {<br>        case invalidURL<br>        case badRequest<br>    }<br>    <br>    func APOD_fetchData(date: String) async throws {<br>        let urlString = &quot;https://api.nasa.gov/planetary/apod?api_key=**&quot;<br>        guard let url = URL(string: urlString) else {<br>            throw FetchError.invalidURL<br>        }<br>        let (data, response) = try await URLSession.shared.data(from: url)<br>        guard (response as? HTTPURLResponse)?.statusCode == 200 else {<br>            throw FetchError.badRequest<br>        }<br>        <br>//        do {<br>//            let dog = try JSONDecoder().decode(AstronomyPictureoftheDay.self, from: data)<br>//            print(dog)<br>//        } catch DecodingError.keyNotFound(let key, let context) {<br>//            print(&quot;keyNotFound&quot;, key, context)<br>//        } catch DecodingError.typeMismatch(let type, let context) {<br>//            print(&quot;typeMismatch&quot;, type, context)<br>//        } catch DecodingError.valueNotFound(let value, let context) {<br>//            print(&quot;valueNotFound&quot;, value, context)<br>//        } catch DecodingError.dataCorrupted(let context) {<br>//            print(&quot;dataCorrupted&quot;, context)<br>//        } catch  {<br>//            print(error)<br>//        }<br>//        print(&quot;APOD&quot;)<br>        <br>        let astronomyPictureoftheDay = try JSONDecoder().decode(AstronomyPictureoftheDay.self, from: data)<br>        items = [**]<br>    }<br>}</pre><pre>import Foundation<br><br>@Observable class NEO_DataFetcher {<br>    var items = [**]()<br>    var item = **<br>    <br>    enum FetchError: Error {<br>        case invalidURL<br>        case badRequest<br>    }<br>    <br>    func NEO_fetchData() async throws {<br>        let urlString = &quot;https://api.nasa.gov/neo/rest/v1/neo/browse?**&quot;<br>        guard let url = URL(string: urlString) else {<br>            throw FetchError.invalidURL<br>        }<br>        let (data, response) = try await URLSession.shared.data(from: url)<br>        guard (response as? HTTPURLResponse)?.statusCode == 200 else {<br>            throw FetchError.badRequest<br>        }<br>        <br>//        do {<br>//            let dog = try JSONDecoder().decode(neos.self, from: data)<br>//            print(dog)<br>//        } catch DecodingError.keyNotFound(let key, let context) {<br>//            print(&quot;keyNotFound&quot;, key, context)<br>//        } catch DecodingError.typeMismatch(let type, let context) {<br>//            print(&quot;typeMismatch&quot;, type, context)<br>//        } catch DecodingError.valueNotFound(let value, let context) {<br>//            print(&quot;valueNotFound&quot;, value, context)<br>//        } catch DecodingError.dataCorrupted(let context) {<br>//            print(&quot;dataCorrupted&quot;, context)<br>//        } catch  {<br>//            print(error)<br>//        }<br>//        print(&quot;NEO&quot;)<br>        <br>        let neo = try JSONDecoder().decode(neos.self, from: data)<br>        items = **<br>    }<br>    <br>    func NEO2_fetchData(asteroid_id: String) async throws {<br>        let urlString = &quot;https://api.nasa.gov/neo/rest/v1/neo/**&quot;<br>        guard let url = URL(string: urlString) else {<br>            throw FetchError.invalidURL<br>        }<br>        let (data, response) = try await URLSession.shared.data(from: url)<br>        guard (response as? HTTPURLResponse)?.statusCode == 200 else {<br>            throw FetchError.badRequest<br>        }<br>        <br>//        do {<br>//            let dog = try JSONDecoder().decode(NearEarthObjects.self, from: data)<br>//            print(dog)<br>//        } catch DecodingError.keyNotFound(let key, let context) {<br>//            print(&quot;keyNotFound&quot;, key, context)<br>//        } catch DecodingError.typeMismatch(let type, let context) {<br>//            print(&quot;typeMismatch&quot;, type, context)<br>//        } catch DecodingError.valueNotFound(let value, let context) {<br>//            print(&quot;valueNotFound&quot;, value, context)<br>//        } catch DecodingError.dataCorrupted(let context) {<br>//            print(&quot;dataCorrupted&quot;, context)<br>//        } catch  {<br>//            print(error)<br>//        }<br>//        print(&quot;NEO2&quot;)<br>        <br>        _ = try JSONDecoder().decode(NearEarthObjects.self, from: data)<br>    }<br>}</pre><pre>import Foundation<br><br>@Observable class SERP_DataFetcher {<br>    var items = [**]()<br>    <br>    enum FetchError: Error {<br>        case invalidURL<br>        case badRequest<br>    }<br>    <br>    func SERP_fetchData(name: String) async throws {<br>        let urlString = &quot;https://serpapi.com/search.json?engine=google&amp;**&quot;<br>        guard let url = URL(string: urlString) else {<br>            throw FetchError.invalidURL<br>        }<br>        let (data, response) = try await URLSession.shared.data(from: url)<br>        guard (response as? HTTPURLResponse)?.statusCode == 200 else {<br>            throw FetchError.badRequest<br>        }<br>        <br>//        do {<br>//            let dog = try JSONDecoder().decode(SerpItem.self, from: data)<br>//            print(dog)<br>//        } catch DecodingError.keyNotFound(let key, let context) {<br>//            print(&quot;keyNotFound&quot;, key, context)<br>//        } catch DecodingError.typeMismatch(let type, let context) {<br>//            print(&quot;typeMismatch&quot;, type, context)<br>//        } catch DecodingError.valueNotFound(let value, let context) {<br>//            print(&quot;valueNotFound&quot;, value, context)<br>//        } catch DecodingError.dataCorrupted(let context) {<br>//            print(&quot;dataCorrupted&quot;, context)<br>//        } catch  {<br>//            print(error)<br>//        }<br>//        print(&quot;Serp&quot;)<br>        <br>        let serp = try JSONDecoder().decode(SerpItem.self, from: data)<br>        <br>        Task { @MainActor in<br>            items = serp.organicResult<br>        }<br>    }<br>    <br>}</pre><p>◎<strong>以 TabView 製作多頁面 App</strong>⬇︎</p><pre>TabView {<br>            ** <br>            **<br>            **<br><br>        }<br>        .ignoresSafeArea()</pre><p>◎<strong>以 NavigationStack 製作多頁面 App</strong>⬇︎</p><pre>NavigationLink {<br>    **<br>} label: {<br>    **<br>}</pre><p>◎<strong>定義 @Observable 的 class 串接網路 API 抓資料，使用到 environment</strong>⬇︎</p><pre>@Environment(A.self) var fetcher<br>@Environment(B.self) var fetcher<br>@Environment(C.self) var fetcher<br><br>ContentView()<br>  .environment(A())<br>  .environment(B())<br>  .environment(C())</pre><p>◎<strong>使用 ProgressView(2種) 和 ContentUnavailableView 顯示資料下載中</strong>⬇︎</p><pre>if fetcher.items.isEmpty {<br>    ContentUnavailableView(label: {<br>        **<br>            .progressViewStyle(.circular)<br>    }, description: {<br>        Text(&quot;Loading...&quot;)<br>        Text(&quot;\(progressValue*100, specifier: &quot;%.2f&quot;)%&quot;)<br>    }) //資料加載時顯示Loading畫面&amp;Loading加載數字<br>}</pre><pre> ContentUnavailableView(label: {<br>     ProgressView(value: progressValue)<br> }, description: {<br>     Text(&quot;Loading...&quot;)<br>     Text(&quot;\(progressValue*100, specifier: &quot;%.2f&quot;)%&quot;)<br> }) //資料加載時顯示Loading畫面</pre><p>◎<strong>沒有網路時使用 ContentUnavailableView 顯示錯誤</strong>⬇︎</p><pre>else if error?.localizedDescription == &quot;**&quot; {<br>    ContentUnavailableView(<br>        **<br>    ) //沒有網路時顯示的畫面<br>}</pre><p>◎<strong>使用 refreshable 實現下拉更新功能</strong>⬇︎</p><pre>.refreshable {<br>    **<br>}</pre><p>◎<strong>使用 searchable 實現 search 功能</strong>⬇︎</p><pre>var searchResults: [**] {<br>    let searchid = searchText<br>    <br>    if searchText == &quot;&quot; {<br>        **<br>        return fetcher.items //searchText為空時顯示所有資料<br>    } else {<br>        return searchid == nil ? fetcher.items : fetcher.items.filter{$0.id.contains(searchid)} //顯示含searchText的資料<br>    }<br>}<br>＊＊<br>.searchable(text: $searchText)</pre><p>◎<strong>使用 ContentUnavailableView 顯示沒有資料</strong>⬇︎</p><pre>if error?.localizedDescription == &quot;**&quot; {<br>    ContentUnavailableView(<br>        **<br>    ) //找不到資料時的畫面<br>}</pre><p>◎<strong>使用 ShareLink 實現分享功能</strong>⬇︎</p><pre>ShareLink(&quot;COPYRIGHT&quot;, item: item.copyright)</pre><p>◎<strong>使用 TipKit 顯示 App 的操作說明 </strong>⬇︎</p><pre>import TipKit<br><br>struct PopoverTip: Tip {<br>    **<br>}<br>**<br>TipView(tip,arrowEdge: .top)<br><br>**<br>.popoverTip(tip)</pre><p>◎<strong>使用 SPM 加入第三方套件</strong>⬇︎</p><pre>import MijickPopupView<br><br>struct TopCustomPopup: TopPopup {<br>    func createContent() -&gt; some View {<br>        HStack(spacing: 0) {<br>            **<br>        }<br>        **<br>    }<br>    func configurePopup(popup: TopPopupConfig) -&gt; TopPopupConfig {<br>        **<br>    }<br>    func createButton() -&gt; some View {<br>        **<br>    }<br>}<br><br>#Preview {<br>    TopCustomPopup()<br>        .implementPopupView()<br>}</pre><p>◎<strong>使用到多國語言</strong>⬇︎</p><pre>.environment(\.locale, .init(identifier: &quot;ch&quot;))<br>.environment(\.locale, .init(identifier: &quot;en&quot;))</pre><p>◎<strong>使用到Dragesture</strong>⬇︎</p><pre>@GestureState private var dragOffset = CGSize.zero<br>@State private var position: CGSize = .init(width: 150, height: -350)<br>**<br>.gesture(<br>    DragGesture( coordinateSpace: .global)<br>        .updating($dragOffset, body: { (value, state, transaction) in<br>            ** //可以肆意移動Button位置<br>        })<br>        .onEnded({ (value) in<br>            **<br>        }) // 手勢變化時更新按鈕位置<br>)</pre><p>◎<strong>毛玻璃效果</strong>⬇︎</p><pre>import SwiftUI<br><br>struct Glassmorphism: View {<br>    let gradientSurface = LinearGradient(colors: [.white.opacity(0.1), .clear], startPoint: .topLeading, endPoint: .bottomTrailing)<br>    let gradientBorder = LinearGradient(colors: [.white.opacity(0.5), .white.opacity(0.0), .white.opacity(0.0), .green.opacity(0.0), .green.opacity(0.5)], startPoint: .topLeading, endPoint: .bottomTrailing)<br>    let GlassWidth : CGFloat<br>    let Glassheight : CGFloat<br>    <br>    var body: some View {<br>        RoundedRectangle(cornerRadius: 15, style: .continuous)<br>            **<br>    }<br>}<br><br>#Preview {<br>    Glassmorphism(GlassWidth: 180, Glassheight: 300)<br>}</pre><p>◎<strong>使用到</strong>Timer.scheduledTimer⬇︎</p><pre>Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { timer in<br>    withAnimation {<br>        **<br>    }<br>} //loading時進度條的動畫</pre><p>◎<strong>使用到replacingOccurrences</strong>⬇︎</p><pre>Text(item.copyright.replacingOccurrences(of: &quot;\n&quot;, with: &quot;&quot;))<br>    .italic()</pre><p>◎<strong>使用到swipeActions</strong>⬇︎</p><pre>.swipeActions(edge: .trailing) {<br>    Button(&quot;Unread&quot;, systemImage: &quot;envelope.badge&quot;, action: {<br>        **<br>    })<br>    .tint(.blue)<br>}</pre><blockquote>心得：</blockquote><p>這次的App製作很特別，Peter要求我們使用網路API串接自己的App，這在以往接觸的課程都不曾遇到，但又是一個實用性很高的功能。因為串接的API是讓我們自己挑選，因此苦惱了好長一段時間，在決定好後研究Decode的過程雖然也挺痛苦的，但在理解上手後變得有趣許多，也對於串接API這件事有更多的好奇。</p><p>在這個學期很謝謝Peter的指導，讓我對於SwiftUI產生了濃厚的興趣，也變得很喜歡閱讀官方網站去學習新技能，希望以後還有機會能夠學習到更多跟SwiftUI相關的課程。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d577c6bf8ab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-04-%E6%9C%9F%E6%9C%AB%E5%B0%88%E9%A1%8C-9d577c6bf8ab">【IOS 應用程式開發入門】#04 期末專題</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【IOS 應用程式開發入門】#03 使用 SwiftUI 的 UI 元件 & data binding 創作有趣的 App]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-03-%E4%BD%BF%E7%94%A8-swiftui-%E7%9A%84-ui-%E5%85%83%E4%BB%B6-data-binding-%E5%89%B5%E4%BD%9C%E6%9C%89%E8%B6%A3%E7%9A%84-app-unfinished-073fdd17bfae?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/073fdd17bfae</guid>
            <category><![CDATA[harry-potter]]></category>
            <category><![CDATA[hogwarts]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Fri, 17 Nov 2023 14:51:40 GMT</pubDate>
            <atom:updated>2023-12-06T08:46:49.191Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>本次的主題是Hogwarts School～</em></strong></p><blockquote>GitHub連結：</blockquote><p><a href="https://github.com/Fangyil/iOS-HW3.git">GitHub - Fangyil/iOS-HW3</a></p><blockquote>App使用影片：</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFK7P-5DbeH0%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFK7P-5DbeH0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFK7P-5DbeH0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0cd2f9b108fdcca774e16314dc5510c1/href">https://medium.com/media/0cd2f9b108fdcca774e16314dc5510c1/href</a></iframe><blockquote>App Icon及頁面預覽：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*wjOirseQ6P0Ry2SPtEvyGA.png" /><figcaption>App Icon</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*df8Wji9Q0ohpgfrvwXc0sw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BmeGgCEjDXxLdkeQEaZkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JYPWdwM-un-OsJ60C5Os2A.png" /><figcaption>App頁面初始畫面</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*0_DwoqxFCL-8nl7W3f2KlA.gif" /><figcaption>動態背景</figcaption></figure><blockquote>使用到的功能：</blockquote><p>◎使用 PhotosUI 的 PhotosPicker 選照片⬇︎</p><pre>@State private var selectedPhoto: PhotosPickerItem?<br>@State private var image: Image?<br>・・・<br>NavigationStack{<br>  ・・・<br>  .overlay {<br>      image?<br>          .resizable()<br>          .scaledToFill()<br>          .clipShape(Circle())<br>  }<br>  .toolbar {<br>      PhotosPicker(<br>          selection: $selectedPhoto,<br>          matching: .images<br>      ) {<br>          Image(systemName: &quot;pencil&quot;)<br>      }<br>  }<br>  .task(id: selectedPhoto) {<br>      image = try? await selectedPhoto?.loadTransferable(type: Image.self)<br>  }<br>  ・・・<br>}</pre><p>◎使用Button &amp; 亂數與顯示 Alert⬇︎⬇︎</p><pre>@State private var showAlert = false<br>@State private var alertTitle = &quot;&quot;<br>・・・<br>Button {<br>    showAlert = true<br>    alertTitle = [&quot;Gryffindor&quot;, &quot;Hufflepuff&quot;, &quot;Ravenclaw&quot;, &quot;Slytherin&quot;].randomElement()!<br>} label: {<br>    ZStack{<br>    Image(&quot;ClassificationHat&quot;)<br>        .resizable()<br>        .scaledToFit()<br>        .frame(width: 250)<br>    }<br>}<br>.alert(alertTitle, isPresented: $showAlert) {<br>    ・・・<br>}</pre><p>◎使用DatePicker⬇︎</p><pre>@State private var Birthday = Date()<br>・・・<br>DatePicker(&quot;生日&quot;, selection: $Birthday, in: ...Date(), displayedComponents: .date)</pre><p>◎使用 Form⬇︎</p><pre>Form{<br>    Group{<br>        HStack{<br>            Spacer()<br>            Circle()<br>                .stroke(lineWidth: 6)<br>                .foregroundStyle(Gradient(colors: [<br>                    Color(red: 254/255, green: 235/255, blue: 152/255),<br>                    Color(red: 202/255, green: 171/255, blue: 98/255)<br>                ]))<br>                ・・・<br>        }<br>    }<br>}</pre><p>◎使用 Slider⬇︎</p><pre>@State private var Sexual: Double = 0<br>・・・<br>Slider(value: $Sexual, in: 0...10, step: 1) {<br>    Text(&quot;age&quot;)<br>} minimumValueLabel: {<br>    Text(&quot;男&quot;)<br>} maximumValueLabel: {<br>    Text(&quot;女&quot;)<br>}<br>.tint(.orange)<br>.padding(.leading)</pre><p>◎使用 TextField&amp; FocusState 收鍵盤（鍵盤有不同種類）⬇︎</p><pre>@State private var name = &quot;&quot;<br>@FocusState private var NameIsFocused: Bool<br>@State private var LuckyNumber = &quot;&quot;<br>・・・<br>TextField(&quot;Your Name&quot;, text: $name)<br>  .textFieldStyle(.roundedBorder)<br>  .overlay(.blue, in: .rect(cornerRadius: 9).stroke(lineWidth: 3))<br>  .padding(.leading)<br>  .focused($NameIsFocused)<br>  .onTapGesture {<br>      NameIsFocused = false<br>  }<br>・・・<br>TextField(&quot;Lucky Number&quot;, text: $LuckyNumber)<br>  .textFieldStyle(.roundedBorder)<br>  .keyboardType(.numberPad)</pre><p>◎使用 Toggleon &amp;Change modifier &amp; confirmationDialog</p><p>(當音樂切換時音樂會自動暫停)⬇︎</p><pre>@State private var showingOptions = false<br>@State private var selection = &quot;Hedwigs Theme&quot;<br>@State private var AudioisPlay = false<br>@State private var isPresenting = false<br>@State private var audioplayer = AVPlayer(url: Bundle.main.url(/service/forresource: &quot;Hedwigs Theme&quot;, withExtension: &quot;mp3&quot;)!)<br>・・・<br>Section(header: Text(&quot;主題曲&quot;)){<br>    Toggle(selection, isOn: $AudioisPlay)<br>        .onChange(of: AudioisPlay) { oldValue, newValue in<br>            ・・・<br>        }<br>    Button(action: {<br>        showingOptions = true<br>        if(AudioisPlay){<br>            AudioisPlay.toggle()<br>        }<br>    }) {<br>        Text(&quot;Which Do You Wanna Listen ?&quot;)<br>            .font(.custom(&quot;JMH Mummy Fill&quot;, size: 15))<br>    }<br>    .confirmationDialog(&quot;Choose A Song&quot;, isPresented: $showingOptions, titleVisibility: .visible) {<br>        ・・・<br>}</pre><p>◎使用 SwiftUI 的 @State &amp; ＠Binding ＆ContextMenu（圖形會改變）⬇︎</p><pre>@Binding var site : Site<br>@State private var show = false<br>@State private var mark = false<br><br>var body: some View {<br>    HStack{<br>        Text(site.Name)<br>            .font(.custom(&quot;JMH Mummy Fill&quot;, size: 15))<br>            .contextMenu{<br>                Button(action: {<br>                    if(show){<br>                        show = false<br>                    }else{<br>                        show = true<br>                    }<br>                }) {<br>                    Text(site.CName)<br>                    if(show){<br>                        Image(systemName: &quot;suit.heart.fill&quot;)<br>                    }else{<br>                        Image(systemName: &quot;suit.heart&quot;)<br>                    }<br>                }<br>          ・・・<br>          if(show){<br>          Image(systemName: &quot;star.fill&quot;)<br>              .foregroundColor(.yellow)<br>          }<br>      }<br>  }</pre><p>◎利用 sheet 切換頁面 &amp; presentationDetents 控制新頁面的高度⬇︎</p><pre>Glassmorphism(GlassWidth: 180, Glassheight: 300)<br>   ・・・<br>          Button(colleges[3].Name) {<br>               self.showSecondViewS = true<br>           }<br>          .foregroundColor(.black)<br>          .font(.custom(&quot;JMH Mummy Fill&quot;, size: 22))<br>          .sheet(isPresented: $showSecondViewS) {<br>              College_Detail(Colleges: colleges[3])<br>                  .presentationDetents([.height(210)])<br>           }<br>      }<br>  }</pre><p>◎利用 fullScreenCover 切換頁面⬇︎</p><pre>Button(action: {<br>    ・・・<br>.fullScreenCover(isPresented: $isPresenting,<br>                 onDismiss: didDismiss){<br>    ・・・<br>    .onTapGesture {<br>        isPresenting.toggle()<br>    }<br>    ・・・<br>}</pre><p>◎使用 ColorPicker 選顏色並顯示在長方形上⬇︎</p><pre>@State private var bgColor = Color.brown<br>・・・<br>ColorPicker(&quot;幸運色&quot;, selection: $bgColor)<br>Rectangle()<br>    .foregroundColor(bgColor)<br>    .frame(width: 195, height: 25)<br>    .cornerRadius(15)</pre><p>◎使用Map (地圖)&amp;地圖上有Mark(自製的與原本的)⬇︎</p><pre>@State private var showingOptions = false<br>private var region: MKCoordinateRegion {<br>    MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 51.53161004604319, longitude: -0.12359780269004013), latitudinalMeters: 1000, longitudinalMeters: 1000)<br>}<br>・・・<br>if(showingOptions){<br>    Map(initialPosition: .region(region)){<br>        Annotation(&quot;King&#39;s Cross Station&quot;, coordinate: .KingsCrossStation) {<br>            Image(systemName: &quot;crown&quot;)<br>                ・・・<br>        }<br>        Marker(&quot;Platform 9¾&quot;, coordinate: .Platform9¾)<br>    }<br>}</pre><p>◎利用 DisclosureGroup 控制 Form 裡有些欄位顯示 / 隱藏⬇︎</p><pre>@State private var isExpanded = true<br>・・・<br>DisclosureGroup {<br>    ForEach($sitesH, id: \.Name) { $sites in<br>        SiteView(site: $sites)<br>    }<br>}label: {<br>    Text(&quot;活米村&quot;)<br>}<br>DisclosureGroup(isExpanded: $isExpanded) {<br>    ForEach($sitesG, id: \.Name) { $sites in<br>        SiteView(site: $sites)<br>    }<br>}label: {<br>    Text(&quot;關於政府&quot;)<br>}</pre><p>◎使用Stepper調整影片大小⬇︎</p><pre>@State private var Widthvalue : CGFloat = 350<br>@State private var Heightvalue : CGFloat = 100<br>let player = AVPlayer()<br>let url = Bundle.main.url(/service/forresource: &quot;Introduce&quot;, withExtension: &quot;mp4&quot;)!<br>var stepHeight : CGFloat = 10<br>・・・<br>Stepper( value: $Heightvalue, in: 100...340, step: stepHeight){<br>    Text(&quot;調整影片大小&quot;)<br>}<br>VideoPlayer(player: AVPlayer(url: url))<br>    .scaledToFit()<br>    .frame(width: Widthvalue, height: Heightvalue)</pre><p>◎使用 MultiDatePicker 選擇多個日期(日期有範圍限制 ＆ 顏色不同)⬇︎</p><pre>@State var dates: Set&lt;DateComponents&gt; = []<br>@Environment(\.calendar) var calendar<br>@Environment(\.timeZone) var timeZone<br>var dateRange: Range&lt;Date&gt; {<br>    let start = calendar.date(from: DateComponents(<br>        timeZone: timeZone, year: 2024, month: 7, day: 18))!<br>    let end = calendar.date(from: DateComponents(<br>        timeZone: timeZone, year: 2024, month: 7, day: 31))!<br>    return start ..&lt; end<br>    }<br>・・・<br>MultiDatePicker(&quot;Select your preferred dates&quot;, selection: $dates, in: dateRange)<br>  .colorInvert()<br>  .colorMultiply(Color(red: 115/255, green: 135/255, blue: 114/255))</pre><p>◎背景為漸變的顏色&amp;動畫⬇︎</p><pre>let bgGradient = LinearGradient(colors: [Color(red: 124/255, green: 175/255, blue: 181/255), Color(red: 68/255, green: 87/255, blue: 120/255)], startPoint: animateGradient ? .top : .bottom, endPoint: animateGradient ? .bottom : .top)<br>・・・<br>.scrollContentBackground(.hidden)<br>        .background(bgGradient.animation(Animation.linear(duration: 5.0).repeatForever(autoreverses: true), value: animateGradient))<br>        .ignoresSafeArea()<br>        .onAppear {<br>            animateGradient.toggle()<br>        }<br>    }<br>    func didDismiss() {/* Handle the dismissing action.*/}</pre><p>◎金屬效果邊框⬇︎</p><pre>Circle()<br>  .stroke(lineWidth: 6)<br>  .foregroundStyle(Gradient(colors: [<br>      Color(red: 254/255, green: 235/255, blue: 152/255),<br>      Color(red: 202/255, green: 171/255, blue: 98/255)<br>  ]))<br>  .frame(width: 180)</pre><p>◎毛玻璃效果⬇︎</p><pre>struct Glassmorphism: View {<br>    let gradientSurface = LinearGradient(colors: [.white.opacity(0.1), .clear], startPoint: .topLeading, endPoint: .bottomTrailing)<br>    let gradientBorder = LinearGradient(colors: [.white.opacity(0.5), .white.opacity(0.0), .white.opacity(0.0), .green.opacity(0.0), .green.opacity(0.5)], startPoint: .topLeading, endPoint: .bottomTrailing)<br>    let GlassWidth : CGFloat<br>    let Glassheight : CGFloat<br>    <br>    var body: some View {<br>        RoundedRectangle(cornerRadius: 15, style: .continuous)<br>            .foregroundStyle(gradientSurface)<br>            .background(.ultraThinMaterial)<br>            .mask( RoundedRectangle(cornerRadius: 15, style: .circular).foregroundColor(.black) )<br>            .overlay(<br>                RoundedRectangle(cornerRadius: 15, style: .circular)<br>                    .stroke(lineWidth: 1.5)<br>                    .foregroundStyle(gradientBorder)<br>                    .opacity(0.8)<br>            )<br>            .frame(width: GlassWidth, height: Glassheight)<br>            .shadow(color: .black.opacity(0.25), radius: 5, x: 0, y: 8)<br>    }<br>}</pre><blockquote>心得：</blockquote><p>這次的App製作過程我覺得挺有趣的，用到了許多不同的功能，使得畫面的互動性相比之前更加強。這次在畫面的背景呈現上也與之前不同，使用了Image與背景漸層加上動畫，使得像是動態背景一樣。我也增添了一些在上個作業沒使用到的功能，來使自己更加熟悉SwiftUI。</p><p>這次做起來算是挺得心應手的，但很可惜的是段考完後才開工，導致製作過程略顯倉促，因此，畫面間的細緻度較不足。在製作時，也與上次相同，仍然對動畫十分不熟悉；不過，透過這次的撰寫經驗，使我對@State與@Binding變得比之前熟悉了。</p><p>還有個有趣的一點，這次的作業壓縮檔超過了25MB，在上傳GitHub時，被告知檔案太大無法上傳。但我上網查到了利用終端機的方式可以上傳，因此便嘗試看看，沒想到竟然成功了，又學到一項新方法！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=073fdd17bfae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-03-%E4%BD%BF%E7%94%A8-swiftui-%E7%9A%84-ui-%E5%85%83%E4%BB%B6-data-binding-%E5%89%B5%E4%BD%9C%E6%9C%89%E8%B6%A3%E7%9A%84-app-unfinished-073fdd17bfae">【IOS 應用程式開發入門】#03 使用 SwiftUI 的 UI 元件 &amp; data binding 創作有趣的 App</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【IOS 應用程式開發入門】#02 製作電子書App]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-02-%E8%A3%BD%E4%BD%9C%E9%9B%BB%E5%AD%90%E6%9B%B8app-2785f0f20977?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2785f0f20977</guid>
            <category><![CDATA[disneysea]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Wed, 25 Oct 2023 17:28:47 GMT</pubDate>
            <atom:updated>2023-10-26T01:41:25.951Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>這次做的主題是<em>Duffy and his friends</em>！</strong></p><p><em>GitHub連結：</em></p><p><a href="https://github.com/Fangyil/IOS-HW2.git">GitHub - Fangyil/IOS-HW2</a></p><blockquote>App使用影片：</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fw0GQQGP188M%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dw0GQQGP188M&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fw0GQQGP188M%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe4dcc3ddaaddd93c58ace97777840f6/href">https://medium.com/media/fe4dcc3ddaaddd93c58ace97777840f6/href</a></iframe><h4>介紹製作到的功能：</h4><p>設定<strong><em>App名稱</em></strong>＆<strong><em>App Icon</em></strong>（在Assets中的AppIcon改）⬇️</p><pre>import SwiftUI<br><br>@main<br>struct Duffy_and_FriendsApp: App {<br>    var body: some Scene {<br>        WindowGroup {<br>            ContentView()<br>        }<br>    }<br>}</pre><p>以<strong><em>TabView</em></strong>＆<strong><em>Tab bar</em></strong>區隔並搭配<strong><em>SF Symbol</em></strong>，分別表：首頁、角色、送禮⬇️</p><pre>TabView{<br>            // 第一個選項卡 Home，使用 Home() 視圖<br>            Home()<br>                .tabItem {<br>                    // 使用 Label 顯示標籤文字和系統圖示 &quot;house.lodge&quot;<br>                    Label(&quot;首頁&quot;, systemImage: &quot;house.lodge&quot;)<br>                }<br>            // 第二個選項卡 Characters，使用 Characters() 視圖<br>            Characters()<br>                .tabItem {<br>                    // 使用 Label 顯示標籤文字和系統圖示 &quot;person.fill&quot;<br>                    Label(&quot;角色&quot;, systemImage: &quot;person.fill&quot;)<br>                }<br>            // 第三個選項卡 Shop，使用 Shop() 視圖<br>            Shop()<br>                .tabItem {<br>                    // 使用 Label 顯示標籤文字和系統圖示 &quot;gift.fill&quot;<br>                    Label(&quot;送禮&quot;, systemImage: &quot;gift.fill&quot;)<br>                }<br>        }</pre><p>利用<strong><em>Tabview</em></strong>以<strong><em>page</em></strong>的形式實現分頁照片瀏覽（底部有小白點喔）⬇️</p><pre>TabView{<br>                ForEach(0..&lt;7){ index in<br>                    HomeRow(homerole: HomeRoles[index])<br>                }<br>            }<br>            .tabViewStyle(.page)<br>            .frame(height: 210)<br>            .listRowSeparator(.hidden)<br>            .listRowBackground(Color(red: 253/255, green: 241/255, blue: 224/255))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*89r7vGH4cadAq_mT-MgeAA.png" /></figure><p>製作<strong><em>打開連結的Link按鈕</em></strong>與<strong><em>炫酷動畫</em></strong>⬇️</p><pre>Link(destination: URL(string: &quot;https://www.tokyodisneyresort.jp/treasure/duffy/&quot;)!, label: {<br>                Image(&quot;HomeFamily&quot;)<br>                    .resizable()<br>                    .scaledToFit()<br>                    .listRowSeparator(.hidden)<br>                    .rotationEffect(.degrees(rotateDegree))<br>                    .animation(<br>                        .linear(duration: 5)<br>                        .repeatCount(1, autoreverses: true),<br>                        value: rotateDegree<br>                    )<br>                    .onAppear {rotateDegree = 360}<br>            })<br>            .listRowBackground(Color(red: 253/255, green: 241/255, blue: 224/255))</pre><p>使用<strong><em>VideoPlayer</em></strong>播放影片⬇️</p><pre>let player = AVPlayer()<br>let url = Bundle.main.url(/service/forresource: &quot;summer night melody&quot;, withExtension: &quot;mp4&quot;)!<br>            VStack{<br>                VideoPlayer(player: AVPlayer(url: url))<br>                    .cornerRadius(50)<br>                    .frame(height: 250)<br>                    .padding()<br>                <br>                // 創建超連結，連接至東京迪士尼的影片頁面<br>                Link(destination: URL(string: &quot;https://www.tokyodisneyresort.jp/treasure/duffy/movie/&quot;)!, label: {<br>                        ZStack{<br>                            Rectangle()<br>                                .cornerRadius(20)<br>                                .frame(width: 200)<br>                                .foregroundColor(.white)<br>                            Text(&quot;MORE&quot;)<br>                                .foregroundColor(.gray)<br>                                .bold()<br>                            Image(systemName: &quot;greaterthan&quot;)<br>                                .foregroundColor(.gray)<br>                                .bold()<br>                                .offset(x:80)<br>                        }<br>                })<br>            }<br>            .listRowSeparator(.hidden)<br>            .listRowBackground(Color(red: 253/255, green: 241/255, blue: 224/255))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*07a7EseDSPjS3hQX1ePzRA.png" /></figure><p>使用<strong><em>List</em></strong>製作表格⬇️</p><pre>List{<br>       TabView{<br>           ・・・<br>        }<br>        .listStyle(.plain)<br>        .background(Color(red: 253/255, green: 241/255, blue: 224/255))<br>    }</pre><p><strong><em>View模組化 </em></strong>/ HomeRow模組化</p><pre>struct HomeRole {<br>    let HomePic: String<br>}<br>struct HomeRow: View {<br>    let homerole: HomeRole<br>    <br>    var body: some View {<br>        // 顯示具有角色圖片的圖像視圖<br>        Image(homerole.HomePic)<br>            .resizable()<br>            .scaledToFit()<br>    }<br>}</pre><p><strong><em>List</em></strong>使用到<strong><em>Section</em></strong>分類表格⬇️</p><pre>List{<br>                // 男性角色部分<br>                Section {<br>                    ・・・<br>                }header: {<br>                    Text(&quot;Male&quot;)<br>                }<br>                <br>                // 女性角色部分<br>                Section {<br>                    ・・・<br>                    }<br>                    .listRowBackground(Color(red: 255/255, green: 226/255, blue: 225/255))<br>                }header: {<br>                    Text(&quot;Female&quot;)<br>                }<br>                <br>            }<br>            .listStyle(.plain)<br>            .background(<br>                LinearGradient(gradient: Gradient(colors: [Color(red: 253/255, green: 241/255, blue: 224/255),Color(red: 255/255, green: 226/255, blue: 225/255)]), startPoint: .top, endPoint: .bottom)<br>                    )<br>}</pre><p>使用 <strong><em>NavigationStack </em></strong>&amp;<strong><em> NavigationLink</em></strong> 切換頁面與傳資料到下一頁，且<strong><em>navigation bar 顯示標題</em></strong>（角色名稱）⬇️</p><pre>NavigationStack{<br>・・・<br>         NavigationLink {<br>                            RoleDetail(role: Maleroles[index])<br>                                .background(<br>                                    LinearGradient(gradient: Gradient(colors: [Color(red: 253/255, green: 241/255, blue: 224/255),Color(red: 252/255, green: 217/255, blue: 192/255)]), startPoint: .top, endPoint: .bottom)<br>                                        )<br>                        } label: {<br>                            RoleRow(role: Maleroles[index])<br>                        }<br>                        .listRowSeparator(.hidden)<br>}</pre><p>資料儲存在<strong><em>array</em></strong>中⬇️</p><pre> let Maleroles = [・・・]<br> let Femaleroles = [・・・]</pre><p>使用<strong><em>ScrollView</em></strong>與<strong><em>LazyVStack</em></strong>製作<strong><em>subview⬇️</em></strong></p><pre> ScrollView{ // 使用ScrollView來支持滾動<br>            LazyVStack{ // 使用LazyVStack進行垂直排列，以支持懶加載視圖<br>                Image(role.name) // 顯示角色圖片<br>                    .resizable()<br>                    .scaledToFit()<br>                Text(role.CName + &quot; (&quot; + role.name + &quot;)&quot;) // 顯示角色的中文名稱和英文名稱<br>                    .font(.largeTitle) // 設置字體大小<br>                Text(&quot;性別：&quot; + role.Gender) // 顯示性別信息<br>                Text(&quot;特徵：&quot; + role.Characteristic) // 顯示特徵描述<br>                Text(&quot;性格：&quot; + role.Disposition) // 顯示性格描述<br>                Text(&quot;愛好：&quot; + role.Hobby) // 顯示愛好描述<br>                Image(role.TitleStory) // 顯示標題故事的圖片<br>                    .resizable()<br>                    .scaledToFit()<br>                    .frame(width: 350)  // 設置圖片寬度<br>                Text(role.Story) // 顯示角色故事描述<br>            }<br>            .navigationTitle(role.name) // 將導航標題設置為角色名稱<br>        }</pre><p>上下捲動 <strong><em>List </em></strong>裡有水平捲動 <strong><em>ScrollView</em></strong> ➕</p><p>使用<strong><em>格子狀排列</em></strong>的 <strong><em>LazyVGrid</em></strong> 實現照片牆⬇️</p><pre>let columns = Array(repeating: GridItem(), count: 2)  // 創建具有2列的網格布局<br><br>        List {  // 使用List來顯示內容，支持滾動<br>            ScrollView(.horizontal) {  // 水平滾動的ScrollView<br>                LazyHStack(pinnedViews: [.sectionHeaders]) {  // 使用LazyHStack來懶加載橫向視圖<br>                    ・・・<br>                }<br>            }<br>            ・・・<br>            ScrollView {  // 垂直滾動的ScrollView<br>                LazyVGrid(columns: columns) {  // 使用網格布局來顯示商品圖像<br>                    ・・・<br>                }<br>            }<br>            ・・・<br>         }<br>        ・・・</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XYBf7G9vp_aw00W_FHm4_Q.png" /></figure><p><strong><em>漸變背景⬇️</em></strong></p><pre>.background(<br>                LinearGradient(gradient: Gradient(colors: [Color(red: 253/255, green: 241/255, blue: 224/255),Color(red: 255/255, green: 226/255, blue: 225/255)]), startPoint: .top, endPoint: .bottom)<br>                    )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBbUyxP9HBNlv4CEQiix_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JGqWGGzD8rt8S2aIjrE3-Q.png" /></figure><p>使用<strong><em>clipShape</em></strong>裁切特別形狀⬇️</p><pre>.clipShape(Circle())  // 將圖像裁剪為圓形</pre><p>將<strong><em>list的背景</em></strong>及每個<strong><em>列之間背景</em></strong>改色⬇️</p><pre>.listRowBackground(Color(red: 253/255, green: 241/255, blue: 224/255))<br>.background(Color(red: 253/255, green: 241/255, blue: 224/255))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*89r7vGH4cadAq_mT-MgeAA.png" /></figure><p>支援 <strong><em>dark mode </em>&amp;<em> light mode</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IK0LXdeImv_aShvFoSA7Qw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6XydHBN03NaMnmYZAkzvIQ.png" /><figcaption>左圖為Light mode &amp; 又右圖為Dark mode</figcaption></figure><h4>心得：</h4><p>真的好趕好趕！在製作的過程中感覺自己做了好多東西，但在模擬時看起來卻好少好少😢。</p><p>寫程式時有碰到一些奇怪的事情，比如：transition寫入程式後卻沒執行，或一些animation跑不出來🆘，查了很多方法，最後還是用了Peter的文章介紹才有成功。</p><p>不過最終看到App做出來還是很有成就感啦🥹！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2785f0f20977" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-02-%E8%A3%BD%E4%BD%9C%E9%9B%BB%E5%AD%90%E6%9B%B8app-2785f0f20977">【IOS 應用程式開發入門】#02 製作電子書App</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[【IOS 應用程式開發入門】#01 模仿App Store上架App]]></title>
            <link>https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-01-%E6%A8%A1%E4%BB%BFapp-store%E4%B8%8A%E6%9E%B6app-caf0fab090c5?source=rss-e357f14564d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/caf0fab090c5</guid>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Fang]]></dc:creator>
            <pubDate>Tue, 03 Oct 2023 10:02:26 GMT</pubDate>
            <atom:updated>2023-10-03T13:24:40.825Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>GitHub連結：</blockquote><blockquote><a href="https://github.com/Fangyil/IOS-HW1.git">HW1.githttps://github.com/Fangyil/IOS-HW1.git</a></blockquote><p><em>以下是圖片展示效果</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*CFMIh0hScKK9QXuoxVeAyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*z2y0BCWADI3bX1HaUNJO7Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWoFt-pn-zhI_yGE_kmGkA.png" /><figcaption>上圖依序分別為：發票載具App的頁面截圖、App頁面在Xcode Content View中的呈現方式、App頁面在Simulator中的樣子（最上面會被覆蓋）</figcaption></figure><h4><strong>心得：</strong></h4><p>在製作App的過程中，最耗費時間的便是在尋找SF Symbols中的圖形，以及調整各個圖形之間的位置關係，除此之外便是更改圖形的顏色。</p><p>很謝謝Peter提供我們<a href="https://yangcha.github.io/iview/iview.html"><em>iview</em></a>可以尋找圖形位置與顏色！</p><p>在製作App頁面中也會遇到各式各樣的問題，大多數都是靠著Peter在Medium中的文章來解惑。</p><p>不過有個比較特別的經驗是，我在製作途中，曾不小心將Assets中的所有內容刪除，導致App無法運作。但值得慶信的是，我從<a href="https://stackoverflow.com/questions/52489500/command-compileassetcatalog-failed-with-a-nonzero-exit-code"><em>stackoverflow</em></a>中找到了解決方案，成功將檔案救了回來！</p><p><a href="https://stackoverflow.com/questions/52489500/command-compileassetcatalog-failed-with-a-nonzero-exit-code">https://stackoverflow.com/questions/52489500/command-compileassetcatalog-failed-with-a-nonzero-exit-code</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caf0fab090c5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88/ios-%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E9%96%8B%E7%99%BC%E5%85%A5%E9%96%80-01-%E6%A8%A1%E4%BB%BFapp-store%E4%B8%8A%E6%9E%B6app-caf0fab090c5">【IOS 應用程式開發入門】#01 模仿App Store上架App</a> was originally published in <a href="https://medium.com/%E6%B5%B7%E5%A4%A7-ios-app-%E7%A8%8B%E5%BC%8F%E8%A8%AD%E8%A8%88">海大 SwiftUI iOS / Flutter App 程式設計</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>