{"id":90782,"date":"2020-05-10T14:58:26","date_gmt":"2020-05-10T06:58:26","guid":{"rendered":"http:\/\/4563.org\/?p=90782"},"modified":"2020-05-10T14:58:26","modified_gmt":"2020-05-10T06:58:26","slug":"flutter-%e9%80%9a%e6%a0%8f%e6%b2%89%e6%b5%b8%e7%8a%b6%e6%80%81%e6%9d%a1flutter-%e8%87%aa%e5%ae%9a%e4%b9%89%e5%ba%95%e9%83%a8%e5%87%b8%e8%b5%b7%e5%af%bc%e8%88%aa%e6%a0%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=90782","title":{"rendered":"flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiaoyan2017 <\/span>  <span><i><\/i> 11<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<h2>Flutter \u5b9e\u73b0\u900f\u660e\u6c89\u6d78\u5f0f\u72b6\u6001\u680f<\/h2>\n<p>\u5982\u4e0b\u56fe\uff1a\u72b6\u6001\u680f\u662f\u6307 android \u624b\u673a\u9876\u90e8\u663e\u793a\u624b\u673a\u72b6\u6001\u4fe1\u606f\u7684\u4f4d\u7f6e\u3002android \u81ea 4.4 \u5f00\u59cb\u65b0\u52a0\u5165\u900f\u660e\u72b6\u6001\u680f\u529f\u80fd\uff0c\u72b6\u6001\u680f\u53ef\u4ee5\u81ea\u5b9a\u4e49\u989c\u8272\u80cc\u666f\uff0c\u4f7f titleBar \u80fd\u591f\u548c\u72b6\u6001\u680f\u878d\u4e3a\u4e00\u4f53\uff0c\u589e\u52a0\u6c89\u6d78\u611f\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec1889f29408.png\" alt=\"flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f\" \/><\/p>\n<p>\u5982\u4e0a\u56fe\uff1aFlutter \u72b6\u6001\u680f\u9ed8\u8ba4\u4e3a\u9ed1\u8272\u534a\u900f\u660e\uff0c\u90a3\u4e48\u5982\u4f55\u53bb\u6389\u8fd9\u4e2a\u72b6\u6001\u680f\u7684\u9ed1\u8272\u534a\u900f\u660e\u80cc\u666f\u8272\uff0c\u8ba9\u5176\u548c\u6807\u9898\u680f\u989c\u8272\u4e00\u81f4\uff0c\u901a\u680f\u6c89\u6d78\u5f0f\uff0c\u5b9e\u73b0\u5982\u4e0b\u56fe\u6548\u679c\u5462\uff1f<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec188a445671.png\" alt=\"flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f\" \/> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec188a763825.png\" alt=\"flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f\" \/><\/p>\n<p>\u9700\u8981\u5728 flutter \u9879\u76ee\u76ee\u5f55\u4e0b\u627e\u5230 android \u4e3b\u5165\u53e3\u9875\u9762 MainActivity.kt \u6216 MainActivity.java\uff0c\u5224\u65ad\u4e00\u4e0b\u7248\u672c\u53f7\u7136\u540e\u5c06\u72b6\u6001\u680f\u989c\u8272\u4fee\u6539\u8bbe\u7f6e\u6210\u900f\u660e\uff0c\u56e0\u4e3a\u4ed6\u672c\u8eab\u662f\u9ed1\u8272\u534a\u900f\u660e\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec188aa86abe.png\" alt=\"flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f\" \/><\/p>\n<p>\u4fee\u6539 MainActivity.kt \u4ee3\u7801\u5982\u4e0b<\/p>\n<pre><code>package com.example.flutter_app  import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugins.GeneratedPluginRegistrant  \/\/\u5f15\u5165 import android.os.Build; import android.os.Bundle;  class MainActivity: FlutterActivity() {     override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {         GeneratedPluginRegistrant.registerWith(flutterEngine);     }      \/\/\u8bbe\u7f6e\u72b6\u6001\u680f\u6c89\u6d78\u5f0f\u900f\u660e\uff08\u4fee\u6539 flutter \u72b6\u6001\u680f\u9ed1\u8272\u534a\u900f\u660e\u4e3a\u5168\u900f\u660e\uff09     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState);         if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {             window.statusBarColor = 0         }     } } <\/code><\/pre>\n<p>\u6ce8\u610f\uff1aflutter \u9879\u76ee\u9ed8\u8ba4\u662f\u4f7f\u7528 Kotlin \u8bed\u8a00<\/p>\n<p>\u5728 Google I\/O 2017 \u4e2d\uff0cGoogle \u5ba3\u5e03 Kotlin \u53d6\u4ee3 Java \u6210\u4e3a Android \u5b98\u65b9\u5f00\u53d1\u8bed\u8a00\u3002<\/p>\n<p>\u901a\u8fc7 <code>flutter create flutter_app<\/code> \u547d\u4ee4\u521b\u5efa flutter \u9879\u76ee\u65f6\uff0c\u9ed8\u8ba4\u662f Kotlin \u8bed\u8a00\u6a21\u5f0f\uff0c\u5982\u679c\u60f3\u8981\u4fee\u6539\u6210 Java \u8bed\u8a00\uff0c\u5219\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4\u521b\u5efa\u9879\u76ee\u5373\u53ef<\/p>\n<p><code>flutter create -a java flutter_app<\/code><\/p>\n<p>\u5982\u679c\u662f java \u8bed\u8a00\u6a21\u5f0f\u4e0b\uff0c\u4fee\u6539\u6c89\u6d78\u5f0f\u72b6\u6001\u680f\u65b9\u6cd5\u548c\u4e0a\u9762\u540c\u7406<\/p>\n<p>\u5728 MainActivity.java \u9875\u9762\u65b0\u589e\u5982\u4e0b\u4ee3\u7801<\/p>\n<pre><code>package com.example.demo1;  import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine; import io.flutter.plugins.GeneratedPluginRegistrant;  \/\/ \u5f15\u5165 import android.os.Build; import android.os.Bundle;  public class MainActivity extends FlutterActivity {   @Override   public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {     GeneratedPluginRegistrant.registerWith(flutterEngine);   }    \/\/ \u8bbe\u7f6e\u72b6\u6001\u680f\u6c89\u6d78\u5f0f\u900f\u660e\uff08\u4fee\u6539 flutter \u72b6\u6001\u680f\u9ed1\u8272\u534a\u900f\u660e\u4e3a\u5168\u900f\u660e\uff09   @Override   protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.LOLLIPOP) {       getWindow().setStatusBarColor(0);     }   } } <\/code><\/pre>\n<h2>Flutter \u5b9e\u73b0\u54b8\u9c7c\u5e95\u90e8\u51f8\u8d77\u51f9\u9677\u5bfc\u822a\u6548\u679c<\/h2>\n<p>\u5982\u4e0b\u56fe\uff1aBottomNavigationBar \u7ec4\u4ef6\u4eff\u54b8\u9c7c\u51f8\u8d77\u5bfc\u822a\u680f\u914d\u7f6e<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200517_5ec188ae63481.png\" alt=\"flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f\" \/><\/p>\n<pre><code>int _selectedIndex = 0; \/\/ \u521b\u5efa\u6570\u7ec4\u5f15\u5165\u9875\u9762 List pglist = [HomePage(), FindPage(), CartPage(), ZonePage(), UcenterPage(),];  ...  Scaffold(     body: pglist[_selectedIndex],          \/\/ \u62bd\u5c49\u83dc\u5355     \/\/ drawer: new Drawer(),      \/\/ \u666e\u901a\u5e95\u90e8\u5bfc\u822a\u680f     bottomNavigationBar: BottomNavigationBar(         fixedColor: Colors.red,         type: BottomNavigationBarType.fixed,         elevation: 5.0,         unselectedFontSize: 12.0,         selectedFontSize: 18.0,         items: [             BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),             BottomNavigationBarItem(icon: Icon(Icons.search), title: Text('Find')),             BottomNavigationBarItem(icon: Icon(null), title: Text('Cart')),             BottomNavigationBarItem(icon: Icon(Icons.photo_filter), title: Text('Zone')),             BottomNavigationBarItem(icon: Icon(Icons.face), title: Text('Ucenter')),         ],         currentIndex: _selectedIndex,         onTap: _onItemTapped,     ),          floatingActionButton: FloatingActionButton(         backgroundColor: _selectedIndex == 2 ? Colors.red : Colors.grey,         child: Column(             mainAxisAlignment: MainAxisAlignment.center,             children: [                 Icon(Icons.add)             ]         ),         onPressed: (){             setState(() {                 _selectedIndex = 2;             });         },     ),     floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, )  void _onItemTapped(int index) {     setState(() {         _selectedIndex = index;     }); } <\/code><\/pre>\n<p>\u5982\u4e0b\u56fe\uff1aBottomAppBar \u7ec4\u4ef6\u51f8\u8d77\u51f9\u9677\u5bfc\u822a\u680f\u914d\u7f6e<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec373ac560bf.png\" alt=\"flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|flutter \u81ea\u5b9a\u4e49\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f\" \/><\/p>\n<pre><code>int _selectedIndex = 0; \/\/ \u521b\u5efa\u6570\u7ec4\u5f15\u5165\u9875\u9762 List pglist = [HomePage(), FindPage(), CartPage(), ZonePage(), UcenterPage(),];  ...  Scaffold(     body: pglist[_selectedIndex],          \/\/ \u62bd\u5c49\u83dc\u5355     \/\/ drawer: new Drawer(),      \/\/ \u5e95\u90e8\u51f8\u8d77\u51f9\u9677\u5bfc\u822a\u680f     bottomNavigationBar: BottomAppBar(         color: Colors.white,         shape: CircularNotchedRectangle(),         child: Row(             mainAxisAlignment: MainAxisAlignment.spaceAround,             children: &lt;Widget&gt;[                 IconButton(                     icon: Icon(Icons.home),                     color: _selectedIndex == 0 ? Colors.red : Colors.grey,                     onPressed: (){                         _onItemTapped(0);                     },                 ),                 IconButton(                     icon: Icon(Icons.search),                     color: _selectedIndex == 1 ? Colors.red : Colors.grey,                     onPressed: (){                         _onItemTapped(1);                     },                 ),                                  SizedBox(width: 50,),                                  IconButton(                     icon: Icon(Icons.photo_filter),                     color: _selectedIndex == 3 ? Colors.red : Colors.grey,                     onPressed: (){                         _onItemTapped(3);                     },                 ),                 IconButton(                     icon: Icon(Icons.face),                     color: _selectedIndex == 4 ? Colors.red : Colors.grey,                     onPressed: (){                         _onItemTapped(4);                     },                 ),             ],         ),     ), )  void _onItemTapped(int index) {     setState(() {         _selectedIndex = index;     }); } <\/code><\/pre>\n<p>\u81f3\u6b64 flutter \u5b9e\u73b0\u6c89\u6d78\u5f0f\u72b6\u6001\u680f+\u4eff\u54b8\u9c7c\u5e95\u90e8\u51f8\u8d77\u5bfc\u822a\u680f\u5c31\u5206\u4eab\u5b8c\u4e86\uff0c\u5e0c\u671b\u80fd\u6709\u4e9b\u5e2e\u52a9\uff01      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1312259\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : putaozhenhaochi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9ed8\u8ba4\u8bed\u8a00\u4e0d\u662f Dart \u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312260\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wobuhuicode <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @putaozhenhaochi \u8fd9\u91cc\u8bf4\u7684\u662f\u539f\u751f\u5c42\u7684\u4ee3\u7801\u3002\u8bdd\u8bf4\u641e\u72b6\u6001\u6761 \u8fd8\u771f\u662f\u5b89\u5353\u6052\u4e45\u4e0d\u53d8\u7684\u8bdd\u9898\u2026\u2026\u56fd\u4ea7\u624b\u673a\u7684\u79c1\u6709 API \u4e5f\u8981\u8003\u8651\u5230\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312261\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CommandZi <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5199 Dart \u7684\u662f\u4e0d\u662f\u90fd\u6709\u4e00\u4e2a\u8d85\u9ad8\u7684\u663e\u793a\u5668\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312262\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : treizeor <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6c89\u6d78\u5f0f\u53ea\u9700\u8981\u5728 main()\u91cc\u9762\u52a0\u5165\u8fd9\u6bb5\u4ee3\u7801\u3002\u4e0d\u9700\u8981\u6539\u539f\u751f<br \/>&#8220;` if (Platform.isAndroid) {<br \/> SystemUiOverlayStyle systemUiOverlayStyle =<br \/> SystemUiOverlayStyle(statusBarColor: Colors.transparent);<br \/> SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);<br \/> }&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312263\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dingyp <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @treizeor \u6b63\u89e3                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312264\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : NewTab12138 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @treizeor \u7eaf flutter \u9879\u76ee\u786e\u5b9e\u662f\u8fd9\u6837,\u4f46\u662f\u5982\u679c\u4f60\u662f\u4f5c\u4e3a\u63d2\u4ef6\u96c6\u6210\u5230\u539f\u751f\u9879\u76ee\u5c31\u4e0d\u6b62\u5199\u8fd9\u4e48\u591a\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1312265\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kazeik <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6c89\u6d78\u5f0f\u72b6\u6001\u680f\u7528 4 \u7684\u5373\u53ef\uff0c\u8fd8\u5230\u539f\u751f\u7aef\u6539\u4ee3\u7801\uff0c\u517c\u5bb9\u6027\u5c31\u5dee\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>flutter \u901a\u680f\u6c89\u6d78\u72b6\u6001\u6761|f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/90782"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=90782"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/90782\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=90782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=90782"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=90782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}