安装
下载
https://storage.googleapis.com/flutter_infra/releases/stable/macos/flutter_macos_2.0.3-stable.zip
设置环境变量
export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
设置环境变量
vim ~/.bash_profile
export FLUTTER_HOME=/Users/zhangzw/Documents/workspace-android/flutter
export PATH=FLUTTER_HOME/bin
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
测试
flutter doctor 测试
flutter project
flutter plugins
flutter module
flutter package 的区别
https://blog.csdn.net/BUG_delete/article/details/105275195
androidstudio
设置==》plugin==〉 安装 flutter 然后重启
创建第一个app
flutter 创建app很慢
build.gradle做以下修改
增加以下内容
maven { url "https://storage.flutter-io.cn" }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
可以增常运行了
好的项目快速开发
https://github.com/iampawan/FlutterExampleApps
试运行官方空项目
在androidstudio里通过创建flutter 工程会有4个模版我们选择第一个 flutter 工程来创建项目
然后点击运行
在第一次创建项目的时候会等待很长时间,是在下载相关 依赖 ios android的.
确保有设置代理环境变量.
创建一个搜索框
我们首先会用到的一些类是
row column icon 。 image 。 text 。 button padding
一些体会
优势
1 首先是代码 不再区分xml 和 java 类了 ,统一在dart代码里编写,
2 结构嵌套一层层 很想 vue的模板 .
3 每次保存就会动态更新到手机上, 还可以一键切换 ios 和android 体验
4 语法类似于 js+ java 结合体
劣势
需要学习一门dart语言 ,其实 dart 和java 还是很像的 ,参杂了js 的语法而已
由于每次保存改代码都会同步到手机上 idea 会有点卡,需要大内存.
怎么http请求
创建一个api模块所有的url都放在这里
创建一个xxxxLoader 继承Loader
实现Future> loadData
接口
如果要存到数据库里 创建一个XXxxDao
窗口的宽度
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height ,
很奇怪一个问题 。 跳到一个页面有延迟 然后迅速的返回了主页,在点一次就跳过去了, 但是返回主页要点两次 而且主页是一个红的页面了
====================================================================================================
E/flutter (17213): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter (17213): At this point the state of the widget's element tree is no longer stable.
E/flutter (17213): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
E/flutter (17213): #0 Element._debugCheckStateIsActiveForAncestorLookup.
E/flutter (17213): #1 Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3878:6)
E/flutter (17213): #2 Element.visitAncestorElements (package:flutter/src/widgets/framework.dart:3964:12)
E/flutter (17213): #3 Notification.dispatch (package:flutter/src/widgets/notification_listener.dart:138:13)
E/flutter (17213): #4 ScrollActivity.dispatchScrollEndNotification (package:flutter/src/widgets/scroll_activity.dart:104:63)
E/flutter (17213): #5 ScrollPosition.didEndScroll (package:flutter/src/widgets/scroll_position.dart:877:15)
E/flutter (17213): #6 ScrollPosition.beginActivity (package:flutter/src/widgets/scroll_position.dart:846:9)
E/flutter (17213): #7 ScrollPositionWithSingleContext.beginActivity (package:flutter/src/widgets/scroll_position_with_single_context.dart:114:11)
E/flutter (17213): #8 ScrollPositionWithSingleContext.goIdle (package:flutter/src/widgets/scroll_position_with_single_context.dart:129:5)
E/flutter (17213): #9 ScrollPositionWithSingleContext.goBallistic (package:flutter/src/widgets/scroll_position_with_single_context.dart:148:7)
E/flutter (17213): #10 DrivenScrollActivity._end (package:flutter/src/widgets/scroll_activity.dart:639:14)
E/flutter (17213): #11 _rootRun (dart:async/zone.dart:1346:47)
E/flutter (17213): #12 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (17213): #13 _FutureListener.handleWhenComplete (dart:async/future_impl.dart:176:18)
E/flutter (17213): #14 Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:674:39)
E/flutter (17213): #15 Future._propagateToListeners (dart:async/future_impl.dart:730:37)
E/flutter (17213): #16 Future._completeWithValue (dart:async/future_impl.dart:539:5)
E/flutter (17213): #17 Future._asyncCompleteWithValue.
E/flutter (17213): #18 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (17213): #19 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (17213): #20 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (17213): #21 _CustomZone.bindCallbackGuarded.
E/flutter (17213): #22 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (17213): #23 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (17213):
======== Exception caught by animation library =====================================================
Looking up a deactivated widget's ancestor is unsafe.
====================================================================================================
V/AudioManager(17213): querySoundEffectsEnabled...
======== Exception caught by widgets library =======================================================
The following assertion was thrown building _EffectiveTickerMode(effective mode: disabled):
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2060 pos 12: '_elements.contains(element)': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was:
MaterialApp file:///Users/zhangzw/Documents/workspace-android/flutter_app1/flutter_module/lib/main.dart:48:12
When the exception was thrown, this was the stack:
2 _InactiveElements.remove (package:flutter/src/widgets/framework.dart:2060:12)
3 Element._retakeInactiveElement (package:flutter/src/widgets/framework.dart:3498:30)
... Normal element mounting (4 frames)
7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
8 Element.updateChild (package:flutter/src/widgets/framework.dart:3303:20)
...
====================================================================================================
======== Exception caught by widgets library =======================================================
The following assertion was thrown building _EffectiveTickerMode(effective mode: disabled):
'package:flutter/src/widgets/framework.dart': Failed assertion: line 2060 pos 12: '_elements.contains(element)': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was:
MaterialApp file:///Users/zhangzw/Documents/workspace-android/flutter_app1/flutter_module/lib/main.dart:48:12
When the exception was thrown, this was the stack:
2 _InactiveElements.remove (package:flutter/src/widgets/framework.dart:2060:12)
3 Element._retakeInactiveElement (package:flutter/src/widgets/framework.dart:3498:30)
... Normal element mounting (4 frames)
7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3541:14)
8 Element.updateChild (package:flutter/src/widgets/framework.dart:3303:20)
flutter k线图
https://www.jianshu.com/p/3e7cde50258a
https://github.com/gwhcn/flutter_k_chart
https://github.com/GitHubYhb/HBLineChart
https://guides.cocoapods.org/using/getting-started.html#installation
https://docs.flutter.dev/get-started/install/macos