{"id":6181,"date":"2023-10-07T17:25:33","date_gmt":"2023-10-07T09:25:33","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=6181"},"modified":"2023-10-07T17:25:33","modified_gmt":"2023-10-07T09:25:33","slug":"flutter%e6%90%ad%e5%bb%ba%e4%b8%80%e4%b8%aaapp%e6%9e%b6%e6%9e%84%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/6181\/","title":{"rendered":"flutter\u642d\u5efa\u4e00\u4e2aapp\u67b6\u6784\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"

Flutter\u662f\u4e00\u6b3e\u7531Google\u5f00\u53d1\u7684\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u901a\u8fc7\u4e00\u5957\u4ee3\u7801\u5e93\u6784\u5efa\u9ad8\u6027\u80fd\u3001\u7f8e\u89c2\u7684\u5e94\u7528\u7a0b\u5e8f\u3002Flutter\u662f\u4e00\u79cd\u8de8\u5e73\u53f0\u7684\u5f00\u53d1\u6846\u67b6\uff0c\u53ef\u4ee5\u5728iOS\u548cAndroid\u7b49\u591a\u4e2a\u5e73\u53f0\u4e0a\u8fd0\u884c\u3002<\/p>\n

\u5728\u642d\u5efa\u4e00\u4e2aFlutter\u5e94\u7528\u7a0b\u5e8f\u7684\u67b6\u6784\u4e4b\u524d\uff0c\u9700\u8981\u5148\u4e86\u89e3Flutter\u7684\u4e00\u4e9b\u57fa\u672c\u6982\u5ff5\u548c\u6280\u672f\u3002<\/p>\n

1. Widget<\/p>\n

\u5728Flutter\u4e2d\uff0c\u4e00\u5207\u90fd\u662fWidget\u3002Widget\u662fFlutter\u5e94\u7528\u7a0b\u5e8f\u7684\u57fa\u672c\u6784\u5efa\u5757\uff0c\u53ef\u4ee5\u662f\u6587\u672c\u3001\u6309\u94ae\u3001\u56fe\u50cf\u7b49\u3002Flutter\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684Widget\uff0c\u53ef\u4ee5\u901a\u8fc7\u7ec4\u5408\u8fd9\u4e9bWidget\u6765\u6784\u5efa\u590d\u6742\u7684\u7528\u6237\u754c\u9762\u3002<\/p>\n

2. StatefulWidget\u548cStatelessWidget<\/p>\n

Flutter\u4e2d\u7684Widget\u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1aStatefulWidget\u548cStatelessWidget\u3002StatefulWidget\u662f\u6709\u72b6\u6001\u7684Widget\uff0c\u53ef\u4ee5\u6839\u636e\u7528\u6237\u7684\u64cd\u4f5c\u800c\u6539\u53d8\u5176\u72b6\u6001\u3002StatelessWidget\u662f\u65e0\u72b6\u6001\u7684Widget\uff0c\u4e00\u65e6\u521b\u5efa\u5c31\u4e0d\u4f1a\u518d\u6539\u53d8\u3002<\/p>\n

3. Material Design\u548cCupertino Design<\/p>\n

Flutter\u63d0\u4f9b\u4e86\u4e24\u79cd\u4e0d\u540c\u7684\u8bbe\u8ba1\u8bed\u8a00\uff1aMaterial Design\u548cCupertino Design\u521b\u5efa\u5feb\u6377app<\/a>\u3002Material Design\u662f\u4e00\u79cd\u73b0\u4ee3\u5316\u7684\u8bbe\u8ba1\u8bed\u8a00\uff0c\u7528\u4e8eAndroid\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u3002Cupertino Design\u662f\u4e00\u79cd\u7c7b\u4f3c\u4e8eiOS\u7684\u8bbe\u8ba1\u8bed\u8a00\uff0c\u7528\u4e8eiOS\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u3002<\/p>\n

\u6709\u4e86\u8fd9\u4e9b\u57fa\u672c\u6982\u5ff5\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u642d\u5efa\u4e00\u4e2aFlutter\u5e94\u7528\u7a0b\u5e8f\u7684\u67b6\u6784\u4e86\u3002<\/p>\n

1. \u4f7f\u7528Flutter\u7684UI\u6846\u67b6<\/p>\n

Flutter\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684UI\u6846\u67b6\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u6784\u5efa\u590d\u6742\u7684\u7528\u6237\u754c\u9762\u3002\u5728\u642d\u5efa\u4e00\u4e2aFlutter\u5e94\u7528\u7a0b\u5e8f\u7684\u67b6\u6784\u4e4b\u524d\uff0c\u9700\u8981\u5148\u9009\u62e9\u4f7f\u7528Flutter\u7684UI\u6846\u67b6\u3002<\/p>\n

2. \u521b\u5efa\u4e00\u4e2a\u65b0\u9879\u76ee<\/p>\n

\u4f7f\u7528Flutter\u7684UI\u6846\u67b6\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Flutter\u9879\u76ee\u3002Flutter\u63d0\u4f9b\u4e86\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177\u6765\u521b\u5efa\u65b0\u7684Flutter\u9879\u76ee\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Flutter\u9879\u76ee\uff1a<\/p>\n

“`<\/p>\n

flutter create myapp<\/p>\n

“`<\/p>\n

\u8fd9\u4e2a\u547d\u4ee4\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3amyapp\u7684\u65b0Flutter\u9879\u76ee\u3002<\/p>\n

3. \u521b\u5efa\u4e00\u4e2a\u4e3b\u754c\u9762<\/p>\n

\u5728Flutter\u4e2d\uff0c\u4e3b\u754c\u9762\u662f\u4e00\u4e2aWidget\u3002\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aStatefulWidget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u754c\u9762\u3002\u5728\u8fd9\u4e2aWidget\u4e2d\uff0c\u53ef\u4ee5\u7ec4\u5408\u5176\u4ed6\u7684Widget\u6765\u6784\u5efa\u590d\u6742\u7684\u7528\u6237\u754c\u9762\u3002<\/p>\n

\u4f8b\u5982\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aMyHomePage\u7684StatefulWidget\uff1a<\/p>\n

“`<\/p>\n

class MyHomePage extends StatefulWidget {<\/p>\n

MyHomePage({Key key, this.title}) : super(key: key);<\/p>\n

final String title;<\/p>\n

@overrideapp\u52a0h5<\/a><\/p>\n

_MyHomePageState createState() => _MyHomePageState();<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2aWidget\u4e2d\uff0c\u53ef\u4ee5\u7ec4\u5408\u5176\u4ed6\u7684Widget\u6765\u6784\u5efa\u590d\u6742\u7684\u7528\u6237\u754c\u9762\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2aScaffold Widget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u754c\u9762\uff1a<\/p>\n

“`<\/p>\n

class _MyHomePageState extends State {<\/p>\n

@override<\/p>\n

Widget build(BuildContext context) {<\/p>\n

return Scaffold(<\/p>\n

appBar: AppBar(<\/p>\n

title: Text(widget.title),<\/p>\n

),<\/p>\n

body: Center(<\/p>\n

child: Text(‘Hello, World!’),<\/p>\n

),<\/p>\n

);<\/p>\n

<\/figure>\n<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2aWidget\u4e2d\uff0c\u4f7f\u7528\u4e86\u4e00\u4e2aAppBar Widget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u6807\u9898\u680f\uff0c\u4f7f\u7528\u4e86\u4e00\u4e2aCenter Widget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u4f53\u5185\u5bb9\u3002<\/p>\n

4. \u6dfb\u52a0\u8def\u7531\u548c\u5bfc\u822a<\/p>\n

\u5728Flutter\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Navigator Widget\u6765\u5b9e\u73b0\u5e94\u7528\u7a0b\u5e8f\u7684\u5bfc\u822a\u529f\u80fd\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u4e3b\u754c\u9762\u4e2d\u6dfb\u52a0Navigator Widget\u6765\u5b9e\u73b0\u5e94\u7528\u7a0b\u5e8f\u7684\u5bfc\u822a\u529f\u80fd\u3002<\/p>\n

\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728MyHomePage Widget\u4e2d\u6dfb\u52a0\u4e00\u4e2aNavigator Widget\uff1a<\/p>\n

“`<\/p>\n

class _MyHomePageState extends State {<\/p>\n

…<\/p>\n

@override<\/p>\n

Widget build(BuildContext context) {<\/p>\n

return Scaffold(<\/p>\n

appBar: AppBar(<\/p>\n

title: Text(widget.title),<\/p>\n

),<\/p>\n

body: Center(<\/p>\n

child: RaisedButton(<\/p>\n

child: Text(‘Go to Second Page’),<\/p>\n

onPressed: () {<\/p>\n

Navigator.push(<\/p>\n

context,<\/p>\n

MaterialPageRoute(builder: (context) => SecondPage()),<\/p>\n

);<\/p>\n

},<\/p>\n

),<\/p>\n

),<\/p>\n

);<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2aWidget\u4e2d\uff0c\u6dfb\u52a0\u4e86\u4e00\u4e2aRaisedButton Widget\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u8fd9\u4e2a\u6309\u94ae\u65f6\uff0c\u4f1a\u8df3\u8f6c\u5230\u4e00\u4e2a\u540d\u4e3aSecondPage\u7684\u65b0\u754c\u9762\u3002<\/p>\n

5. \u521b\u5efa\u5176\u4ed6\u754c\u9762<\/p>\n

\u53ef\u4ee5\u521b\u5efa\u5176\u4ed6\u7684StatefulWidget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u5176\u4ed6\u754c\u9762\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aSecondPage\u7684StatefulWidget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u7b2c\u4e8c\u4e2a\u754c\u9762\u3002<\/p>\n

“`<\/p>\n

class SecondPage extends StatefulWidget {<\/p>\n

SecondPage({Key key}) : super(key: key);<\/p>\n

@override<\/p>\n

_SecondPageState createState() => _SecondPageState();<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2aWidget\u4e2d\uff0c\u53ef\u4ee5\u7ec4\u5408\u5176\u4ed6\u7684Widget\u6765\u6784\u5efa\u590d\u6742\u7684\u7528\u6237\u754c\u9762\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2aScaffold Widget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u754c\u9762\uff1a<\/p>\n

“`<\/p>\n

class _SecondPageState extends State {<\/p>\n

@override<\/p>\n

Widget build(BuildContext context) {<\/p>\n

return Scaffold(<\/p>\n

appBar: AppBar(<\/p>\n

title: Text(‘Second Page’),<\/p>\n

),<\/p>\n

body: Center(<\/p>\n

child: Text(‘This is the second page.’),<\/p>\n

),<\/p>\n

);<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5728\u8fd9\u4e2aWidget\u4e2d\uff0c\u4f7f\u7528\u4e86\u4e00\u4e2aAppBar Widget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u6807\u9898\u680f\uff0c\u4f7f\u7528\u4e86\u4e00\u4e2aCenter Widget\u6765\u8868\u793a\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u4f53\u5185\u5bb9\u3002<\/p>\n

6. \u603b\u7ed3<\/p>\n

\u642d\u5efa\u4e00\u4e2aFlutter\u5e94\u7528\u7a0b\u5e8f\u7684\u67b6\u6784\u9700\u8981\u7406\u89e3Flutter\u7684\u4e00\u4e9b\u57fa\u672c\u6982\u5ff5\u548c\u6280\u672f\u3002\u9700\u8981\u9009\u62e9\u4f7f\u7528Flutter\u7684UI\u6846\u67b6\uff0c\u521b\u5efa\u4e00\u4e2a\u4e3b\u754c\u9762\uff0c\u6dfb\u52a0\u8def\u7531\u548c\u5bfc\u822a\uff0c\u521b\u5efa\u5176\u4ed6\u754c\u9762\u7b49\u7b49\u3002\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u51fa\u4e00\u4e2a\u9ad8\u6027\u80fd\u3001\u7f8e\u89c2\u7684Flutter\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Flutter\u662f\u4e00\u6b3e\u7531Google\u5f00\u53d1\u7684\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u6846\u67b6\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u901a\u8fc7\u4e00\u5957\u4ee3\u7801\u5e93\u6784\u5efa\u9ad8\u6027\u80fd\u3001\u7f8e\u89c2\u7684\u5e94\u7528\u7a0b\u5e8f\u3002Flutter\u662f\u4e00\u79cd\u8de8\u5e73\u53f0\u7684\u5f00\u53d1\u6846\u67b6\uff0c\u53ef\u4ee5\u5728iOS\u548cAndroid\u7b49\u591a\u4e2a\u5e73\u53f0\u4e0a\u8fd0\u884c\u3002<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[2325,11303,12,185,11304],"topic":[],"class_list":["post-6181","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-2325","tag-app","tag-12","tag-185","tag-11304"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/6181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=6181"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/6181\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=6181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=6181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=6181"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=6181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}