flutter已经上手接近一个月,也码了5000行左右的代码了,相比一开始写的”乱来“已经好了几分,下面记录下一些感受和技巧。
目录
问题
- 入门第一个门槛,就是安装环境
- 不得不说,配置安卓的开发环境属实折磨人,其中大部分原因是网络的问题,因为谷歌被墙,所以刚创建好项目后,经常会卡在 ”Running Gradle task 'assembleDebug'…“,如果等了一段时间还是失败,可以试试用手机开流量,然后开WIFI给电脑。在学校就经常校园网会失败,然后用手机流量连vpn都不用就可以下载成功。
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-1.png)
- 在高版本的安卓中,默认是不允许http请求的
- 需要使用加密的https;但可以在配置文件中修改让它放行http:
- 修改配置文件android/app/src/main/AndriodManifest.xml:
![](https://blog.coolight.cool/wp-content/uploads/2022/11/image-1.png)
- -
- 在application标签的属性中添加:android:usesCleartextTraffic="true"
- 注意是 <application 这里></application> ,而不是 <application>不是这里</application>
![](https://blog.coolight.cool/wp-content/uploads/2022/11/image-2.png)
- 安卓debug时在控制台没有日志?
- 这个很可能是安卓的开发者模式里的日志没有开启
- 首先在手机的设置里打开开发者模式(默认是隐藏的,可以在 关于手机-版本号 连续点击5次后显示)
- 然后开发者模式就因手机而异,可能会在设置的首页,也可能在辅助功能里,需要自己找或者搜索
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-2.png)
- -
- 然后找到开发者选项,可以直接搜索设置,输入 ”开发者“ 应该就有了:
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-6.png)
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-3.png)
- -
- 在开发者选项中,找到 日志记录器缓冲区大小 的设置:
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-4.png)
- -
- 只要不是关闭,选哪个应该都行了,一般就选1M的那个
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-5.png)
第三方库
- 当仁不让的当然是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)
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-7.png)
- -
- 那如果我们的需求是判断条件为true则使用组件,false则不做任何操作呢?
- 这时就要请Sizedbox出场了:
![](https://blog.coolight.cool/wp-content/uploads/2022/12/image-8.png)
- -
- 如图,isEdit如果为true,则返回const SizedBox(),这个sizedbox由于没有传参,只是个占位的东西,在界面上高度是0,宽度也是0,因此相当于什么也没有
- 而当isEdit为false,则返回MyBtn()组件
- 不过我们其实有更简单的写法,在[]中是可以直接写 if 的:
- 但要注意这里的if不能加上花括号 {}
![](https://blog.coolight.cool/wp-content/uploads/2023/01/image-1.png)
- 注意,[ if (bool) widget ] 和 [ (bool) ? widget : const sizedBox() ] 并不等价
- 尤其可以证明的就是如上面的代码中的Row的children内
- Row的水平对其方式是spaceEvenly,即将子组件放在两端且和边界留有空隙,当子组件只有一个时,水平居中。
- 如果是 [ if (bool) widget ] ,当bool = false时,Row的子组件只有一个MyBtn(),因此在界面上会呈现只有一个水平居中的按钮:
![](https://blog.coolight.cool/wp-content/uploads/2023/01/image-5.png)
![](https://blog.coolight.cool/wp-content/uploads/2023/01/image-2.png)
- -
- 如果是 [ (bool) ? widget : const sizedBox() ] ,即使bool = false, Row内仍然是有两个组件,但sizedBox()不在界面上显示,因此,在界面上会显示一个被放在右边的按钮。
![](https://blog.coolight.cool/wp-content/uploads/2023/01/image-4.png)
![](https://blog.coolight.cool/wp-content/uploads/2023/01/image-3.png)
An impressive share! I have just forwarded this onto a co-worker who was conducting a little homework on this. And he in fact ordered me lunch simply because I stumbled upon it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanks for spending the time to talk about this matter here on your internet site.
I have been browsing online more than three hours today yet I never found any interesting article like yours It is pretty worth enough for me In my view if all website owners and bloggers made good content as you did the internet will be a lot more useful than ever before
Hi there! I simply would like to give you a huge thumbs up for your great info you’ve got here on this post. I’ll be returning to your blog for more soon.
This is a topic which is close to my heart… Many thanks! Where are your contact details though?
Normally I do not read article on blogs however I would like to say that this writeup very forced me to try and do so Your writing style has been amazed me Thanks quite great post
It’s very trouble-free to find out any matter on net as compared to books, as I found this piece of writing at this web site.
https://main7.top/
Temp Mail I do not even understand how I ended up here, but I assumed this publish used to be great
I blog frequently and I genuinely appreciate your content. This great article has really peaked my interest. I am going to bookmark your website and keep checking for new information about once a week. I subscribed to your RSS feed too.
I simply could not go away your web site prior to suggesting that I really enjoyed the standard info a person supply on your guests Is going to be back incessantly to investigate crosscheck new posts
Greetings, I do think your blog could be having browser compatibility issues. When I take a look at your blog in Safari, it looks fine however, if opening in Internet Explorer, it’s got some overlapping issues. I simply wanted to give you a quick heads up! Other than that, excellent blog.
Very good article! We will be linking to this particularly great content on our website. Keep up the great writing.
Aw, this was an exceptionally nice post. Spending some time and actual effort to make a very good article… but what can I say… I procrastinate a lot and never manage to get nearly anything done.
What i do not realize is in fact how you are no longer actually much more wellfavored than you might be right now Youre very intelligent You recognize thus considerably in relation to this topic made me in my view believe it from numerous numerous angles Its like men and women are not fascinated until it is one thing to do with Lady gaga Your own stuffs excellent All the time handle it up
I was recommended this website by my cousin I am not sure whether this post is written by him as nobody else know such detailed about my trouble You are amazing Thanks
프라 그마 틱 슬롯 사이트
수도 전체에서 아무도 그런 손글씨를 가지고 있지 않은 것이 두렵습니다.
Very interesting topic, regards for posting.?
hey there and thank you for your info – I’ve definitely
picked up anything new from right here. I did however expertise several technical points using this website, as I experienced to reload the website a lot of times previous to
I could get it to load properly. I had been wondering if your web host is OK?
Not that I am complaining, but slow loading instances times will sometimes affect your
placement in google and could damage your high quality score if advertising and marketing with Adwords.
Well I am adding this RSS to my email and could look out for much more of your respective interesting content.
Make sure you update this again soon.. Escape roomy lista
슬롯 보증
그러나 한 내시가 급히 들어와 말했다.
how much amoxicillin for a dog
how much amoxicillin for a dog
톰 오브 매드니스
Fang Jifan은 “우리가 떠나려고 할 때 그가 부엌으로 가는 것을 보았다”고 말했다.
doxycycline used for
doxycycline used for
metformin class
metformin class
how long do side effects of keflex last
how long do side effects of keflex last
side effects of lisinopril and amlodipine taken together
side effects of lisinopril and amlodipine taken together
is nolvadex a good pct
is nolvadex a good pct
can i drink alcohol while taking cephalexin
can i drink alcohol while taking cephalexin
pregabalin 25 mg capsule
pregabalin 25 mg capsule
provigil similar medications
provigil similar medications
canadian mail order pharmacies to usa
ciprofloxacin vs amoxicillin for uti
ciprofloxacin vs amoxicillin for uti
valacyclovir 500 mg used for
valacyclovir 500 mg used for
warfarin and cotrimoxazole interaction
warfarin and cotrimoxazole interaction
how long does it take for trazodone to kick in for sleep
how long does it take for trazodone to kick in for sleep
gabapentin for sleep
gabapentin for sleep
trusted overseas pharmacies
us online pharmacy
mail order prescription drugs from canada
foreign online pharmacy
geinoutime.com
“질문을 해결하세요!” Fang Jifan은 지붕 타일을 진동시키는 그의 목소리로 유창하게 말했습니다.
geinoutime.com
먹고 은화 세 냥의 표값을 냈으니 가볼까요?
tipobet
geinoutime.com
Jinshen Hall에서 Hongzhi 황제는 오랫동안이 두 위대한 영웅을 기다리기 위해 모든 관리를 소집했습니다.
geinoutime.com
Zhu Houzhao는 그의 어깨를 두드렸다.
pcinxOdQukZmTg
k8 カジノ アフィリエイト
この記事から多くを学びました。引き続きフォローします。
BLOOD+ 二人の女王(V2.2)
このブログのすべての記事が大好きです。いつも素晴らしい内容をありがとう。
戦国パチスロ花の慶次~戦極めし傾奇者の宴~(自动转)
この記事から多くのことを学び、非常に感謝しています。
吉宗
ユニークな視点で、非常に啓発されました。ありがとうございます。
Valvrave the Liberator
この記事はとても有益で、読むのが楽しみです。
I loved as much as youll receive carried out right here The sketch is tasteful your authored material stylish nonetheless you command get bought an nervousness over that you wish be delivering the following unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this hike