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()不在界面上显示,因此,在界面上会显示一个被放在右边的按钮。
งานที่น่าทึ่ง! บทความนี้เป็นผลงานชิ้นเอกในการถ่ายทอดข้อมูลในรูปแบบการเล่าเรื่องที่น่าสนใจ
I quite like reading through a post that can make people think. Also, many thanks for permitting me to comment.
Профессиональный сервисный центр по ремонту ноутбуков и компьютеров.дронов.
Мы предлагаем:ремонт ноутбуков в москве
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Fourweekmba Great information shared.. really enjoyed reading this post thank you author for sharing this post .. appreciated
Профессиональный сервисный центр по ремонту ноутбуков, imac и другой компьютерной техники.
Мы предлагаем:ремонт imac в москве
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Greetings! Very useful advice in this particular article! It is the little changes that will make the most significant changes. Thanks for sharing!
You ought to take part in a contest for one of the highest quality blogs on the web. I’m going to highly recommend this site!
Real Estate There is definately a lot to find out about this subject. I like all the points you made
Профессиональный сервисный центр по ремонту квадрокоптеров и радиоуправляемых дронов.
Мы предлагаем:сервис квадрокоптеров
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту сотовых телефонов, смартфонов и мобильных устройств.
Мы предлагаем: мастер по ремонту телефонов
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Профессиональный сервисный центр по ремонту сотовых телефонов, смартфонов и мобильных устройств.
Мы предлагаем: ремонт телефонов поблизости
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
ремонт телевизоров с выездом
Профессиональный сервисный центр по ремонту ноутбуков, макбуков и другой компьютерной техники.
Мы предлагаем:ремонт apple macbook в москве
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Good post. I learn something totally new and challenging on sites I stumbleupon on a daily basis. It’s always helpful to read through articles from other writers and practice something from their websites.
I was more than happy to uncover this website. I want to to thank you for ones time due to this fantastic read!! I definitely loved every little bit of it and I have you saved to fav to look at new stuff on your web site.
Real Estate Pretty! This has been a really wonderful post. Many thanks for providing these details.
Real Estate Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
Hi, I do believe this is an excellent web site. I stumbledupon it 😉 I will come back once again since I book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to help others.
I am not sure where you are getting your info, but good topic.
I needs to spend a while learning much more or working out more.
Thank you for wonderful info I used to be on the lookout for this info for my mission.
ремонт айфона в москве недорого рядом
Good post. I’m experiencing many of these issues as well..
I would like to thank you for the efforts you’ve put in penning this blog. I am hoping to check out the same high-grade blog posts by you later on as well. In truth, your creative writing abilities has motivated me to get my very own website now 😉
It’s hard to come by experienced people about this subject, but you seem like you know what you’re talking about! Thanks
Business dicker Pretty! This has been a really wonderful post. Many thanks for providing these details.
After I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the same comment. Perhaps there is a way you can remove me from that service? Kudos.
Your style is so unique compared to other folks I’ve read stuff from. Thanks for posting when you’ve got the opportunity, Guess I will just book mark this blog.
I blog often and I genuinely thank you for your content. Your article has truly peaked my interest. I’m going to take a note of your site and keep checking for new details about once a week. I subscribed to your RSS feed too.
You’ve made some really good points there. I looked on the internet for additional information about the issue and found most people will go along with your views on this website.
An impressive share! I’ve just forwarded this onto a co-worker who has been conducting a little homework on this. And he actually bought me dinner due to the fact that I stumbled upon it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending time to discuss this matter here on your blog.
There’s definately a lot to find out about this issue. I like all of the points you have made.
I’d like to thank you for the efforts you’ve put in writing this blog. I really hope to check out the same high-grade blog posts from you later on as well. In fact, your creative writing abilities has encouraged me to get my own website now 😉
Squirrel Kombat is a tap-to-earn game on The Open Network
(TON) that offers players
the chance to earn in-game currency and participate in a vibrant online community.
With
its playful design and engaging gameplay, Squirrel Kombat is
set to become a major player
in the Telegram gaming ecosystem.
Greetings! Very useful advice within this article! It is the little changes which will make the most significant changes. Many thanks for sharing!
I used to be able to find good information from your articles.
Greetings! Very useful advice in this particular article! It’s the little changes that make the largest changes. Thanks for sharing!
Hi! I simply want to give you a big thumbs up for your great information you’ve got here on this post. I’ll be returning to your site for more soon.
This is a very good tip particularly to those fresh to the blogosphere. Simple but very accurate info… Thanks for sharing this one. A must read article!
This is a topic which is close to my heart… Best wishes! Where are your contact details though?
Pretty! This has been a really wonderful post. Thank you for supplying this info.
Excellent article! We will be linking to this particularly great article on our website. Keep up the good writing.
Greetings! Very useful advice within this article! It is the little changes that make the most significant changes. Many thanks for sharing!
Can I just say what a relief to uncover an individual who actually understands what they’re talking about over the internet. You certainly know how to bring a problem to light and make it important. More and more people ought to read this and understand this side of your story. I can’t believe you aren’t more popular because you most certainly have the gift.
Hello there! I could have sworn I’ve visited this blog before but after looking at a few of the posts I realized it’s new to me. Anyhow, I’m definitely pleased I stumbled upon it and I’ll be bookmarking it and checking back frequently.
You are so interesting! I do not suppose I’ve read anything like that before. So great to discover someone with some genuine thoughts on this topic. Really.. many thanks for starting this up. This site is one thing that’s needed on the internet, someone with a bit of originality.
Nice post. I learn something new and challenging on websites I stumbleupon on a daily basis. It will always be exciting to read through articles from other writers and use something from other sites.
Hi, I do believe this is a great site. I stumbledupon it 😉 I’m going to revisit once again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to guide others.
I really like it whenever people come together and share views. Great website, keep it up!
I would like to thank you for the efforts you’ve put in penning this blog. I really hope to view the same high-grade content by you later on as well. In truth, your creative writing abilities has inspired me to get my very own blog now 😉
Excellent site you’ve got here.. It’s hard to find excellent writing like yours these days. I honestly appreciate people like you! Take care!!
Next time I read a blog, Hopefully it won’t disappoint me as much as this particular one. After all, I know it was my choice to read through, nonetheless I really thought you’d have something interesting to say. All I hear is a bunch of whining about something you can fix if you were not too busy looking for attention.