flutter已经上手接近一个月,也码了5000行左右的代码了,相比一开始写的”乱来“已经好了几分,下面记录下一些感受和技巧。
目录
问题
- 入门第一个门槛,就是安装环境
- 不得不说,配置安卓的开发环境属实折磨人,其中大部分原因是网络的问题,因为谷歌被墙,所以刚创建好项目后,经常会卡在 ”Running Gradle task 'assembleDebug'…“,如果等了一段时间还是失败,可以试试用手机开流量,然后开WIFI给电脑。在学校就经常校园网会失败,然后用手机流量连vpn都不用就可以下载成功。
- 在高版本的安卓中,默认是不允许http请求的
- 需要使用加密的https;但可以在配置文件中修改让它放行http:
- 修改配置文件android/app/src/main/AndriodManifest.xml:
- -
- 在application标签的属性中添加:android:usesCleartextTraffic="true"
- 注意是 <application 这里></application> ,而不是 <application>不是这里</application>
- 安卓debug时在控制台没有日志?
- 这个很可能是安卓的开发者模式里的日志没有开启
- 首先在手机的设置里打开开发者模式(默认是隐藏的,可以在 关于手机-版本号 连续点击5次后显示)
- 然后开发者模式就因手机而异,可能会在设置的首页,也可能在辅助功能里,需要自己找或者搜索
- -
- 然后找到开发者选项,可以直接搜索设置,输入 ”开发者“ 应该就有了:
- -
- 在开发者选项中,找到 日志记录器缓冲区大小 的设置:
- -
- 只要不是关闭,选哪个应该都行了,一般就选1M的那个
第三方库
- 当仁不让的当然是Getx,这个真的牛,一个库就包含了状态管理、路由、主题皮肤、多语言等支持
- 在pub.dev中搜索 get 即可找到
- crypto,加解密函数库,和js中的一样,包含md5、sha1、sha256等等各种算法,在加密、验证等会经常用。
- dio,http网络库,相当于js中axios
经验
- GetX的使用
- 虽然官方文档说了很多,但还是有很多得自己摸索
- 尤其是状态管理相关的Getx,GetBuilder、Obx、GetxController这一家
- 首先分清楚,GetxController是保存,控制数据用的,它有点像前端的vuex和pinia。
- 而Getx、Obx、GetBuilder是让我们写的静态组件(StatelessWidget)能和动态组件(StatefulWidget)一样,可以随着数据的更新而更新页面展示。
- 然后GetBuilder和StatefulWidget类型,修改数据后,需要使用update()函数来通知它更新界面。
- 而Getx和Obx则是修改数据后,界面会自动更新,但他们使用的内存会比GetBuilder多。
- Obx大多是用于要绑定一个.obx的变量给我们的组件时使用,它并不需要GetxController,当然你把GetxController里面定义的.obx变量绑定过来用也是可以的
- Getx则大多是需要一个GetxController配合使用的,但你不写init也不写Getx<T>的T类型也是可以的,只要被Getx包裹的组件有使用到.obx变量即可
- 也就是说,Obx和Getx可以使用的前提并不是你给了他们GetxController,而是被包裹的组件有使用到.obx变量
- if / 三目运算符 bool ?A :B
- 在build()函数中,经常会使用三目运算符来判断这个位置使用的组件或其样式
- 比如:
- 这里就判断了(item.img.isEmpty)即item的img属性是否为空
- 若true,则加载本地图片const AssetImage(...)
- 若false,则加载网络图片NetworkImage(item.img)
- -
- 那如果我们的需求是判断条件为true则使用组件,false则不做任何操作呢?
- 这时就要请Sizedbox出场了:
- -
- 如图,isEdit如果为true,则返回const SizedBox(),这个sizedbox由于没有传参,只是个占位的东西,在界面上高度是0,宽度也是0,因此相当于什么也没有
- 而当isEdit为false,则返回MyBtn()组件
- 不过我们其实有更简单的写法,在[]中是可以直接写 if 的:
- 但要注意这里的if不能加上花括号 {}
- 注意,[ if (bool) widget ] 和 [ (bool) ? widget : const sizedBox() ] 并不等价
- 尤其可以证明的就是如上面的代码中的Row的children内
- Row的水平对其方式是spaceEvenly,即将子组件放在两端且和边界留有空隙,当子组件只有一个时,水平居中。
- 如果是 [ if (bool) widget ] ,当bool = false时,Row的子组件只有一个MyBtn(),因此在界面上会呈现只有一个水平居中的按钮:
- -
- 如果是 [ (bool) ? widget : const sizedBox() ] ,即使bool = false, Row内仍然是有两个组件,但sizedBox()不在界面上显示,因此,在界面上会显示一个被放在右边的按钮。
You ought to take part in a contest for one of the greatest sites online. I’m going to recommend this site!
It’s nearly impossible to find well-informed people for this subject, but you seem like you know what you’re talking about! Thanks
I like it whenever people come together and share thoughts. Great website, stick with it!
The next time I read a blog, I hope that it does not fail me just as much as this one. After all, Yes, it was my choice to read, however I actually thought you’d have something interesting to talk about. All I hear is a bunch of complaining about something you can fix if you were not too busy looking for attention.
I have to thank you for the efforts you’ve put in penning this site. I really hope to view the same high-grade content from you in the future as well. In fact, your creative writing abilities has encouraged me to get my own, personal site now 😉
bookmarked!!, I really like your blog!
Hi, I do believe this is a great web site. I stumbledupon it 😉 I’m going to return once again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to help others.
Howdy! I just would like to offer you a big thumbs up for your excellent info you’ve got here on this post. I’ll be returning to your web site for more soon.
After looking over a number of the blog articles on your web site, I truly appreciate your technique of writing a blog. I book marked it to my bookmark webpage list and will be checking back soon. Please visit my website as well and tell me how you feel.
You made some really good points there. I looked on the internet to find out more about the issue and found most people will go along with your views on this web site.
Hi! I just want to give you a big thumbs up for the great information you’ve got right here on this post. I will be coming back to your blog for more soon.
Great article. I will be dealing with a few of these issues as well..
Link pyramid, tier 1, tier 2, tier 3
Level 1 – 500 hyperlinks with positioning contained in pieces on content sites
Secondary – 3000 domain Forwarded references
Level 3 – 20000 connections blend, remarks, posts
Using a link pyramid is advantageous for online directories.
Require:
One reference to the domain.
Search Terms.
Correct when 1 query term from the content topic.
Observe the supplementary service!
Crucial! Top connections do not coincide with Secondary and Tier 3-order hyperlinks
A link structure is a tool for increasing the flow and referral sources of a digital property or online community
Right here is the perfect webpage for anybody who really wants to understand this topic. You realize so much its almost tough to argue with you (not that I really would want to…HaHa). You definitely put a fresh spin on a topic that’s been written about for a long time. Excellent stuff, just great.
I was able to find good info from your blog posts.
Nice post. I learn something new and challenging on blogs I stumbleupon every day. It will always be interesting to read through content from other writers and practice something from their web sites.
Your style is really unique compared to other folks I have read stuff from. Thanks for posting when you have the opportunity, Guess I’ll just book mark this site.
This page certainly has all the information and facts I needed about this subject and didn’t know who to ask.
I could not resist commenting. Perfectly written!
I’m amazed, I have to admit. Seldom do I encounter a blog that’s equally educative and engaging, and without a doubt, you have hit the nail on the head. The issue is something which too few people are speaking intelligently about. I’m very happy I came across this in my search for something relating to this.
There’s certainly a lot to learn about this subject. I like all of the points you have made.
This is the right blog for everyone who wants to find out about this topic. You realize so much its almost tough to argue with you (not that I actually will need to…HaHa). You certainly put a new spin on a subject that has been written about for many years. Wonderful stuff, just great.
Your style is unique in comparison to other folks I have read stuff from. Many thanks for posting when you have the opportunity, Guess I’ll just book mark this page.
Spot on with this write-up, I honestly believe that this site needs a great deal more attention. I’ll probably be returning to see more, thanks for the advice.
Good information. Lucky me I discovered your site by chance (stumbleupon). I’ve bookmarked it for later!
Saved as a favorite, I really like your website.
There’s certainly a lot to learn about this topic. I really like all of the points you have made.
I blog often and I really thank you for your information. The article has truly peaked my interest. I am going to book mark your site and keep checking for new details about once per week. I opted in for your Feed as well.
Simply wish to say your article is as amazing The clearness in your post is just nice and i could assume youre an expert on this subject Well with your permission let me to grab your feed to keep updated with forthcoming post Thanks a million and please carry on the gratifying work
Hi, I do believe this is a great website. I stumbledupon it 😉 I will come back once again since I bookmarked it. Money and freedom is the best way to change, may you be rich and continue to help others.
Spot on with this write-up, I honestly believe that this site needs a great deal more attention. I’ll probably be back again to see more, thanks for the information!
Hi there! I simply wish to give you a big thumbs up for your excellent info you have here on this post. I am returning to your web site for more soon.
Hello there! I could have sworn I’ve visited this site before but after looking at some of the articles I realized it’s new to me. Anyhow, I’m certainly delighted I came across it and I’ll be book-marking it and checking back often.
Very good article. I certainly appreciate this site. Thanks!
An intriguing discussion is definitely worth comment. I do think that you ought to publish more about this issue, it may not be a taboo subject but typically people do not talk about such issues. To the next! All the best!
Hi i think that i saw you visited my web site thus i came to Return the favore I am attempting to find things to improve my web siteI suppose its ok to use some of your ideas
Oh my goodness! Impressive article dude! Thank you, However I am having troubles with your RSS. I don’t understand why I can’t join it. Is there anybody else having similar RSS problems? Anyone that knows the answer can you kindly respond? Thanks.
Good post! We will be linking to this particularly great content on our site. Keep up the great writing.
Good information. Lucky me I discovered your website by accident (stumbleupon). I’ve book marked it for later.
Good web site you have got here.. It’s difficult to find excellent writing like yours these days. I truly appreciate individuals like you! Take care!!
I used to be able to find good advice from your blog posts.
Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous roommate! He continually kept talking about this. I am going to forward this article to him. Pretty sure he will have a great read. Thanks for sharing!
Aw, this was a really nice post. Finding the time and actual effort to produce a superb article… but what can I say… I put things off a lot and never seem to get anything done.
I do believe all the ideas youve presented for your post They are really convincing and will certainly work Nonetheless the posts are too short for novices May just you please lengthen them a little from subsequent time Thanks for the post
Simply wish to say your article is as amazing The clearness in your post is just nice and i could assume youre an expert on this subject Well with your permission let me to grab your feed to keep updated with forthcoming post Thanks a million and please carry on the gratifying work
Temp Mail I am truly thankful to the owner of this web site who has shared this fantastic piece of writing at at this place.
Vitazen Keto This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!
A fascinating discussion is worth comment. I do believe that you need to publish more about this subject, it might not be a taboo matter but typically people do not discuss such issues. To the next! Best wishes.
Excellent article. I will be going through many of these issues as well..
bookmarked!!, I really like your website.