flutter note

project types

application
a whole new application
plugin
exposing an android or ios api for developers
package
creating a pure dart component, like a new widget
module
creating a flutter component to add to an android app

commonly used commands

  • Upgrade
    $ flutter upgrade

  • switch channel (stable recommended)
    $ fultter channel beta/dev/master/stable

  • check environment
    $ flutter doctor

flutter for web (in progress)

for details, check article Hummingbird: Building Flutter for the Web

flutter for desktop

Desktop Embedding for Flutter
by google
Feather Apps
by a 3rd party company, commercial license, check article 使用 Flutter 开发 macOS App

problem notes

debug app with blank screen

One possible reason is your environment variable http_proxy/https_proxy has block the communication between flutter compiler and flutter vm on the remote device. If this is the case, we just set an environment variable no_proxy with 127.0.0.1 included to solve this problem.

Memo

Releationships between Widget, Element and RenderObject

[todo] - refer to Flutter, what are Widgets, RenderObjects and Elements?

Cocoapods

You can install Cocoapods via two ways: homebrew and rubygems

by homebrew

$ brew install cocoapods

for details, refer to Homebrew Formulae

by rubygems

$ sudo gem install cocoapods

for details, refer to Getting Started

rubygems

replace source with chinese mirror

$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l

Json and Serialization

  • For small project - decode manually
  • For medium to large projects - code generation
    • json_serializable
      • add a dev dependency - build_runner: ^1.0.0
      • one-time code generation - $ flutter pub run build_runner build
      • generating code continuously - $ flutter pub run build_runner watch
      • this lib will generate a new file named xxx.g.dart with all generated utility functions, however, you’ll need to write the below boilerplate functions
        • factory XXX.fromJson(Map<String, dynamic> json) => _$XXXFromJson(json);
        • Map<String, dynamic> toJson() => _$XXXToJson(this);
    • built_value
  • Flutter does not support runtime reflection, that is why you cannot find a GSON/Jackson/Moshi equivalent in flutter.
    • Runtime reflection interferes with tree shaking. With tree shaking, you can “shake off” unused code from your release builds. This optimizes the app’s size significantly.

For details, refer to JSON and serialization

Hot restart/reload and debugging dart code for flutter module

Execute the following command under flutter module root directory,

$ flutter attach

Then, launch your application in debug mode from Android Studio or Xcode.

it seems there’s a problem in attaching a ios emulator, refer to flutter attach - Oops; flutter has exited unexpectedly.
resolved in new version (1.7.8+hotfix.3)

References

  1. Mac终端的Cocoapods的安装及使用
  2. RubyGems 镜像
  3. cocoaPods的安装和使用
  4. Mac 从零安装cocoapods
  5. MAC OS Cocoapods安装更新实战
  6. Add Flutter to existing apps
  7. JSON and serialization

study resources

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值