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
- or, you can use the following online tool to help you generate the serialization logic
- 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);
- add a dev dependency -
- built_value
- json_serializable
- 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
- Mac终端的Cocoapods的安装及使用
- RubyGems 镜像
- cocoaPods的安装和使用
- Mac 从零安装cocoapods
- MAC OS Cocoapods安装更新实战
- Add Flutter to existing apps
- JSON and serialization

2011

被折叠的 条评论
为什么被折叠?



