1.命令行運行flutter run之后iOS報錯:
Could not install build/ios/iphones/Runner.app on XXXXX. try lunching Xcode and
selecting "Project > Run" to fix the problem open ios/Runner.xworkspace.......
這個惡心的報錯,我一直以為是我Xcode的問題,因為早上一直好的,代碼未動.而下午什么都沒做,就是Xcode升級了下.然后就不行了.可以使用Xcode直接運行.但是命令行不行.最后發現我手機在充電,於是拔了,然后再命令行運行flutter run之后,好了!!!fuck.這報錯信息也忒能了....
2.今天在學Flutter時,寫一個基本的push功能時,發現代碼無誤,但是報個錯'package: XXXX:error:Unexpected tag 128(SepecialiedVariableGet) in ?,expected a procedure,a constructor or a function node',發現在test文件夾里面有個錯誤,修改好之后,再次r,還是不行.沒辦法只能重新R.再次重新運行就好了.和當時視頻中有這點區別.記錄一下.
3.開發中,有時候在flutter packeages get 或者 flutter create XXX等過程中,程序中斷,再次打開時,會出現Waiting for another flutter command to relsease the startup lock...
此時打開 flutter的sdk安裝目錄,關閉ide, 刪除文件 bin/cache/lockfile即可.如下:
4.升級Flutter時,出現:Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
重現: 在flutter1.0升級flutter1.2時,中途卡住.聽網友的中斷再升級,運行 flutter upgrade 之后就報這錯誤了.
解決: 刪除 flutter SDK中 bin/cache 文件夾 再 flutter upgrade就好了
5.升級flutter后,之前好的項目就不行了.這時重新 flutter packages get 獲取下三方庫.然后再運行就好了. why???
6.在 flutter packages get時,pub get failed:
我的原因是:版本號前面未加一個空格.
7.最近上傳代碼到github老是報錯,Failed to connect to 127.0.0.1 port 1080: Connection refused .....
不管FQ與否,藍☺燈不行,ss不行,Cla☺shX不行,V☺2☺ra☺yU也不行,還整天封端口fuck....按照網上的取消git代理也不行(git config --global --unset http.proxy)
實在煩得很,直接去gitconfig刪除字段!!!
第一步
在終端輸入
defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder
這行命令可以顯示電腦的隱形文件
第二步
在Finder里面個人賬號的文件夾里找到gitconfig這個隱藏文件,右擊打開,然后把里面的代理proxy整行刪掉

8.最近在寫一個Flutter項目時,發現點擊跳轉詳情頁面,底部tabbar竟然還在?!這什么鬼,出現這個情況記得3年前寫iOS原生代碼出現過,但那個可以配置.兩年前寫RN也出現過,那個只是加載順序問題,現在寫Flutter又是什么毛病,其實只是我復制代碼忘記刪除MaterialApp....了.一個工程只能有一個MaterialApp.不過這個bug也讓我知道了一個偏方,flutter怎么寫push之后還有tabbar的效果....呵呵,年紀大了,就越會安慰自己.
9.出現類似 The argument type '_BottomContainerState' can't be assigned to the parameter type 'TickerProvider'.dart(argument_type_not_assignable)
如:
這是需要混入 with SingleTickerProviderStateMixin即可.
10. children 直接遍歷返回一個數組Widget:
如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
// 視頻標簽
Widget videoTag() {
return
Container(
child: Wrap(
spacing: 8.0,
// 主軸(水平)方向間距
runSpacing: 4.0,
// 縱軸(垂直)方向間距
children: tag()),
);
}
List<Widget> tag() {
List<Widget> list = [];
infoData[
'videoTag'
].forEach((val) {
list.add(
ClipRRect(
borderRadius: BorderRadius.circular(100.0),
child: Container(
padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 15.0),
color: Colors.black26,
child: Text(val),
),
),
);
});
return
list;
}
|
10.運行出現
ideviceinfo returned an error:
ERROR: Could not connect to lockdownd, error code -8
連接着外接設備.移除即可
11.add widget時,出現the method 'add' was called on null.Receiver: null.
我的錯誤是數組忘記初始化......
11. Cannot provide both a color and adecoration.the color argument is just a shortthand for "decoration:new BoxDecoration(color: color)".
顧名思義, 意思就是這倆不能一起使用. 需要把color寫入BoxDecoration里面.
12.在json轉model的各種工具上報格式錯誤........
平時使用vscode擼.使用https://javiercbk.github.io/json_to_dart/ 在線轉換比較多,但是格式錯誤不提示...
所以,都是先使用格式化工具格式(http://www.bejson.com/) 格式正確了在轉.
常見的錯誤有:
a.
b.
13.在拉取新庫時,長時間拉取不了來.可以試試git的方式.
dependencies: fluro: git: git://github.com/theyakka/fluro.git
14.出現類似
flutter: The following assertion was thrown building SimpleDialogDemo(dirty, dependencies:
flutter: [_LocalizationsScope-[GlobalKey#61da8], _InheritedTheme], state: _SimpleDialogDemoState#4de71):
flutter: setState() or markNeedsBuild() called during build.
flutter: This Overlay widget cannot be marked as needing to build because the framework is already in the
......
錯誤只是在調用方法時,多寫了一個()導致........果然996太久腦子容易死機.算了,記錄一下.該休息一下了.

15.flutter的尺寸單位是dp.不是px
16.放置2X,3X圖片.
如:根目錄下有images文件夾,里面有2.0x文件夾,3.0x文件夾.在images下存放1X圖:xxx.png,然后在2.0x文件夾和3.0x文件夾里面也放置相應文件即可.
在pubspec.yaml直接引入 -images/xxx.png即可,flutter本身就自動識別使用2X,3X.
17.Android端出現:Android dependncy 'android.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath.You should manually set the same version.
我的解決辦法是:
先在項目根目錄下的build.gradle下把
classpath 'com.android.tools.build:gradle:3.2.1'
改為
classpath 'com.android.tools.build:gradle:3.3.1'
然后刪除
ext.kotlin_version = '1.3.31'
在grable.properties 下添加
1
2
|
android.useAndroidX=
true
android.enableJetifier=
true
|
之后sync 即可.
記得要FQ
文件如圖所示:
其他方案: https://github.com/flutter/flutter/issues/27254
18.分別在iOS平台和Android平台各自添加啟動圖之后,啟動會發生 啟動圖 --> 黑屏 --> 界面.
試了好多方法均無效,最后試了下把debug改為release,好了.......艹,學藝不精就是坑
19.圖片注冊只需要注冊到文件夾即可,不用注冊到圖片.如:
20. android 模擬器出現
Package install error: Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]
Error launching application on Android SDK built for x86.
最簡單的方法就是刪除幾個模擬器上的app即可.
21.突然之間,Android模擬器死了.啟動起來,點了點不動.flutter run -d all只有iOS起來,Android好像死了一樣啥也不動,終端也不輸出錯誤.....
之前是重新關閉,再重啟模擬器就好了,最近重啟模擬器也沒有用,重啟mac也是一樣沒反應. 無奈只能卸載,重新安裝一個新的模擬器就好了...
22.使用輸入框時,在對輸入框長按操作,iOS報紅,Android好的,這個惡心的問題是官方的bug,缺少對中文的支持.
我的解決辦法是:
項目中添加下面這個dart文件.
common_localizations_delegate.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
import
'package:flutter/cupertino.dart'
;
import
'package:flutter/foundation.dart'
;
///語言(主要解決cupertino控件不能顯示中文的問題)
class
CommonLocalizationsDelegate
extends LocalizationsDelegate<CupertinoLocalizations> {
const
CommonLocalizationsDelegate();
@
override
bool
isSupported(Locale locale) =>
<String>[
'zh'
,
'CN'
].contains(locale.languageCode);
@
override
SynchronousFuture<_DefaultCupertinoLocalizations> load(Locale locale) {
return
SynchronousFuture<_DefaultCupertinoLocalizations>(
_DefaultCupertinoLocalizations(locale.languageCode));
}
@
override
bool
shouldReload(CommonLocalizationsDelegate old) =>
false
;
}
class
_DefaultCupertinoLocalizations extends CupertinoLocalizations {
_DefaultCupertinoLocalizations(
this
._languageCode)
: assert(_languageCode !=
null
);
final String _languageCode;
static
const
List<String> _shortWeekdays = <String>[
'周一'
,
'周二'
,
'周三'
,
'周四'
,
'周五'
,
'周六'
,
'周日'
,
];
static
const
List<String> _shortMonths = <String>[
'一月'
,
'二月'
,
'三月'
,
'四月'
,
'五月'
,
'六月'
,
'七月'
,
'八月'
,
'九月'
,
'十月'
,
'十一月'
,
'十二月'
,
];
static
const
List<String> _months = <String>[
'一月'
,
'二月'
,
'三月'
,
'四月'
,
'五月'
,
'六月'
,
'七月'
,
'八月'
,
'九月'
,
'十月'
,
'十一月'
,
'十二月'
,
];
@
override
String
get
alertDialogLabel =>
'提醒'
;
@
override
String
get
anteMeridiemAbbreviation =>
"上午"
;
@
override
String
get
postMeridiemAbbreviation =>
"下午"
;
@
override
String
get
copyButtonLabel =>
"復制"
;
@
override
String
get
cutButtonLabel =>
"剪切"
;
@
override
String
get
pasteButtonLabel =>
"粘貼"
;
@
override
String
get
selectAllButtonLabel =>
"全選"
;
@
override
DatePickerDateOrder
get
datePickerDateOrder => DatePickerDateOrder.ymd;
@
override
DatePickerDateTimeOrder
get
datePickerDateTimeOrder =>
DatePickerDateTimeOrder.date_time_dayPeriod;
@
override
String datePickerDayOfMonth(
int
dayIndex) => dayIndex.toString();
@
override
String datePickerHour(
int
hour) => hour.toString();
@
override
String datePickerHourSemanticsLabel(
int
hour) => hour.toString();
@
override
String datePickerMediumDate(DateTime date) {
return
'${_shortWeekdays[date.weekday - DateTime.monday]} '
'${_shortMonths[date.month - DateTime.january]} '
'${date.day.toString().padRight(2)}'
;
}
@
override
String datePickerMinute(
int
minute) => minute.toString().padLeft(2,
'0'
);
@
override
String datePickerMinuteSemanticsLabel(
int
minute) {
if
(minute == 1)
return
'1 分鍾'
;
return
minute.toString() +
' 分鍾'
;
}
@
override
String datePickerMonth(
int
monthIndex) => _months[monthIndex - 1];
@
override
String datePickerYear(
int
yearIndex) => yearIndex.toString();
@
override
String timerPickerHour(
int
hour) => hour.toString();
@
override
String timerPickerHourLabel(
int
hour) =>
'時'
;
@
override
String timerPickerMinute(
int
minute) => minute.toString();
@
override
String timerPickerMinuteLabel(
int
minute) =>
'分'
;
@
override
String timerPickerSecond(
int
second) => second.toString();
@
override
String timerPickerSecondLabel(
int
second) =>
'秒'
;
@
override
// TODO: implement todayLabel
String
get
todayLabel =>
"今天"
;
}
|
然后,在main.dart文件中添加
主要是 添加 CommonLocalizationsDelegate(),

我是在輸入的時候操作setState導致的,需要加一個延時即可.如:
24.之前使用vscode擼,最近卡到飛起來,比as,xcode還卡...換回as開發,但是反括號不顯示了.....
如圖所示,修改一下就好了
25.https://github.com/GigaDroid/flutter_udid 的使用: 項目中需要使用到UDID,網上找了個庫,但是該庫完全沒有使用說明.....
該庫需要iOS集成SAMKeychain. 我通過pod集成了.之后會報錯:
The following Swift pods cannot yet be integrated as static libraries:
The Swift pod `flutter_udid` depends upon `SAMKeychain`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
這個錯誤需要在Podfile中,
添加 use_frameworks!
然后終端會顯示版本警告,要求使用8.0.
添加 platform :ios, '8.0'
最后又會報swift version版本問題,我的是Xcode10.1(swift是4.2.1)
The target “flutter_udid” contains source code developed with Swift 2.x. This version of Xcode does not support building or migrating Swift 2.x targets.
Use Xcode 8.x to migrate the code to Swift 3.
我根據我的Xcode版本添加了
config.build_settings['SWIFT_VERSION'] = '4.2.1' # added this
之前的終於好了. 但是又會出現一個問題.問題是啥忘了.只記得解決辦法是聽朋友的執行 pod update.之后好了.
貼一下podfile吧
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# Uncomment this line to define a global platform for your project
platform :ios,
'8.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV[
'COCOAPODS_DISABLE_STATS'
] =
'true'
project
'Runner'
, {
'Debug'
=> :debug,
'Profile'
=> :release,
'Release'
=> :release,
}
def parse_KV_file(file, separator=
'='
)
file_abs_path = File.expand_path(file)
if
!File.exists? file_abs_path
return
[];
end
pods_ary = []
skip_line_start_symbols = [
"#"
,
"/"
]
File.
foreach
(file_abs_path) { |line|
next
if
skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if
plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path(
"#{path}"
, file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts
"Invalid plugin specification: #{line}"
end
}
return
pods_ary
end
target
'Runner'
do
use_frameworks!
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system(
'rm -rf .symlinks'
)
system(
'mkdir -p .symlinks/plugins'
)
# Flutter Pods
generated_xcode_build_settings = parse_KV_file(
'./Flutter/Generated.xcconfig'
)
if
generated_xcode_build_settings.empty?
puts
"Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
end
generated_xcode_build_settings.map { |p|
if
p[:name] ==
'FLUTTER_FRAMEWORK_DIR'
symlink = File.
join
(
'.symlinks'
,
'flutter'
)
File.symlink(File.dirname(p[:path]), symlink)
pod
'Flutter'
, :path => File.
join
(symlink, File.basename(p[:path]))
end
}
pod
'SAMKeychain'
# Plugin Pods
plugin_pods = parse_KV_file(
'../.flutter-plugins'
)
plugin_pods.map { |p|
symlink = File.
join
(
'.symlinks'
,
'plugins'
, p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.
join
(symlink,
'ios'
)
}
end
post_install
do
|installer|
installer.pods_project.targets.each
do
|target|
target.build_configurations.each
do
|config|
config.build_settings[
'ENABLE_BITCODE'
] =
'NO'
config.build_settings[
'SWIFT_VERSION'
] =
'4.2.1'
# added
this
end
end
end
|
26.flutter: Another exception was thrown: setState() or markNeedsBuild() called during build.
我的解決方案是把setState稍微延遲一下子
Future.delayed(Duration(milliseconds: 200)).then((e) { setState(() { ... }); });
27.iOS真機出現Could not launch engine with configuration
解決方案是 : https://github.com/flutter/flutter/issues/21221
雖然感覺有點不對門,但是總之解決了就行.......
28.XXXXX is a SingleTickerProviderStateMixin but multiple tickers were created.
原因是多個地方調用setState請求重繪,但是state使用的是SingleTickerProviderStateMixin ,將其改成TickerProviderStateMixin即可。
29.使用fluro管理路由時,在傳輸參數時出現傳輸特殊字符,會被自動截取.就像下面傳輸+12345過去,那邊只能收到12345......
這個時候需要被傳輸的數據進行特殊處理,編碼一下就可以
30.
Error on line 52, column 4 of pubspec.yaml: Expected a key while parsing a block mapping.
╷
│ assets:
│ ^
這個問題就是一個智障問題了:
assets前面多了個空格,去除就好....
31. Text的換行屬性 :softWrap: true
在其他組件中,使用Text需要換行,其外面最好加一個Expanded

32.想要在Column中使用ListView.
如果想要在Column中使用ListView.需要對ListView的外面包裹一層:Expanded
如:
Column( children: <Widget>[ Text('3456789'), Expanded( child: ListView( children: <Widget>[ ], ), ), ] )
33.返回 Future<bool>:
需要使用 Future.value(false); 如
/* * Android 物理鍵返回 */ Future<bool> _showToast() { if (_lastPressedAt == null || DateTime.now().difference(_lastPressedAt) > Duration(seconds: 1)) { //兩次點擊間隔超過1秒則重新計時 _lastPressedAt = DateTime.now(); Fluttertoast.showToast( msg: "連續雙擊退出APP", toastLength: Toast.LENGTH_LONG, ); return Future.value(false); } return Future.value(true); }
34.設置Drawer的寬度.
直接在Drawer的外面包裹一層Container.然后設置Container的寬度即可.:
如
35.使用Flutter自帶的CircularProgressIndicator 繪制圓環進度時.出現一瞬間的錯誤UI.原因很小學知識.因為我的進度是兩數相除所得.默認都是0.除數不能為0!!!!!!!!!!!!
36.網絡請求有時放在 initState 太早了. 會發生異常:
如我的這個,需要先獲取兩個本地化的值,然后才能請求網絡,但是常常太晚了.於是awiat 取值,網絡請求. 不行!如警告所說放在 didChangeDependencies 里面.同時對所有需要等待的程序awiat即可.
37.之前在上傳TestFlight的時候,下載之后打開app發現黑屏了...
有時Xcode還輸出: Failed to find snapshot: XXXX Engline run configyation was inavalid. Could not launch engine with configuration.
找了下,這樣可以解決:
38.Android添加啟動頁並全屏.
39.AS之前取消了版本更新,現在需要更新下.但是檢測不到版本.
如下所示,點擊1處.刪除其中的版本信息.然后點擊2處即可.
40. 手機只能豎屏.
1
2
3
4
5
|
import
'package:flutter/services.dart'
;
// 強制只能豎屏
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
|
41. A類 想要調用B類的方法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
import
'package:flutter/material.dart'
;
void
main() => runApp(MyApp());
class
MyApp extends StatelessWidget {
// This widget is the root of your application.
@
override
Widget build(BuildContext context) {
return
MaterialApp(
title:
'Flutter Demo'
,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class
MyHomePage extends StatefulWidget {
@
override
_MyHomePageState createState() => _MyHomePageState();
}
class
_MyHomePageState extends State<MyHomePage> {
@
override
Widget build(BuildContext context) {
return
Scaffold(
appBar: AppBar(
title: Text(
'調用其他類的方法'
),
),
body: FlatButton(
child: Text(
'調用其他類的方法'
),
onPressed: _btnAction,
),
);
}
_btnAction() {
Two two = Two();
two.twoAction();
Three three = Three();
three.createState().threeAction();
}
}
class
Two extends StatelessWidget {
twoAction() {
print(
'twoActiontwoActiontwoAction'
);
}
@
override
Widget build(BuildContext context) {
return
Container();
}
}
class
Three extends StatefulWidget {
@
override
_ThreeState createState() => _ThreeState();
}
class
_ThreeState extends State<Three> {
threeAction() {
print(
'threeActionthreeActionthreeActionthreeAction'
);
}
@
override
Widget build(BuildContext context) {
return
Container();
}
}
|
42.進入一家新公司,拉取代碼后模擬器好的.真機會出現: 'ios/Runner/Runner.entitlements' could not be opened. Verify the value of the CODE_SIGN_ENTITLEMETS build setting for target 'RUNNER' and build configuration "Debug" is correct and that the file exists on the disk.(in taget 'Runner')
我的問題是沒有打開推送通知的開關.
43.上傳app store或者Test Flight時.一直不顯示版本包,出現: TMS-90338: Non-public API usage -The app references non-public symbols in Frameworks/Flutter.framework/Flutter: _ptrace 的郵件信息.
解決方案: https://github.com/flutter/flutter/issues/37850
https://blog.csdn.net/xudailong_blog/article/details/101268214
44.android 的AS 出現 Add Configuration....
我出現這個問題是因為導入一個庫,但是這個庫是用不了,我再次去除時,AS就變這樣了.....尷尬.搞了一下午.最后發現只需要修改一下版本就好了,
解決方案如下:
45.卸載cocoapods之后再重新安裝,運行pod setup無效,但是pod --version可以看到版本.flutter doctor報cocoapods壓根不存在.pod install讓我pod setup.pod setup又無效.....惡心死了.....百度一下午沒有...老大說用谷00歌.答案一下子就出來了===> https://github.com/CocoaPods/CocoaPods/issues/9184
馬丹.百度真惡心.政策真惡心.
46.iOS啟動報錯:VM snapshot invalid and could not be inferred form settings等字樣
解決方案是修改Edit Scheme...為release. 參考如下鏈接
https://github.com/flutter/flutter/issues/24641
47.跳轉界面傳值出現 :
flutter: The following ArgumentError was thrown while handling a gesture:
flutter: Invalid argument(s): Illegal percent encoding in URI
原因是傳的值不能包含中文. 需要轉一下碼: Uri.encodeComponent("漢字")
48.flutter build ios 出現 Using 'ARCHS' setting to build architectures of target 'Pods-Runner':('')
看圖識字,修改一下 iOS目錄下的Podfile文件.添加一行 platform :ios, '9.0'
即可.
49. android打包出現 Could not resolve com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+.
解決方案:翻 00牆00
惡心00的00牆.惡00心的土 00匪
50.使用了Flutter json_serializable這個插件運行flutter packages pub run build_runner build:出現pub finished with exit code 78.
解決辦法:運行 flutter packages pub run build_runner build --delete-conflicting-outputs 即可.
51. iOS在上傳App Store時,出現GeoJSON無效:您的路由App覆蓋地區文件失效......
原因: 圖片文件或者路徑包含了中文字符.修改即可.
52. iOS 打包在Archive的時候出現 could not find an option named "track-widget-creation"
解決辦法: 在Archive之前先執行
flutter build ios --release
參考: https://github.com/flutter/flutter/issues/26279
53. Android真機出現NoSuchMethodError: The method 'tabLabel' was called on null.Receiver null Tried calling: tabLabel().
如圖
或者出現:
出現這個問題,我這邊是因為代碼里面一開始使用了國際化,配置了
supportedLocales: [
//此處
const Locale('zh', 'CH'),
const Locale('en', 'US'),
],
后來沒用國際化了.這個代碼我就懶得刪除......就是這個玩意造成的.iOS可以,Android就不行. 刪除這個就好了...惡心我半個小時
54. 最近換電腦,一樣的代碼,一樣的開發環境,但是新電腦就是運行不起來。舊電腦鍵盤還廢了。。。。草
出現
Using `ARCHS` setting to build architectures of target `Pods-Sample`: (``)
同時 pod install也也不行,原因一樣。。
看來是pod的問題,於是升級到最新1.8.4 不行,降級1.8.3不行。還是必須降級到1.7.5
55. Android報 A proglem occured configuring root project 'android'
搞了好久。最后發現需要翻696牆。。。。。惡心的土匪。建你 媽媽 的 牆
56.在對項目flutter clean出現‘FileSystemException: Delation ,path = 'build' (OS Error: Permission denied,rrror =13)’....
解決辦法:可以 sudo flutter clean一下。但是感覺不嚴謹。容易出事。
應該在選中根目錄文件夾 右鍵 顯示簡介 共享與權限 找到自己的當前賬戶 點擊鎖 輸入密碼解開 點擊應用到包含的項目。稍等一下即可。
57. 在使用
_pageController.animateToPage(widget.index,
duration: const Duration(milliseconds: 2), curve: Curves.ease);時報錯:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building Builder:
flutter: ScrollController not attached to any scroll views.
flutter: 'package:flutter/src/widgets/scroll_controller.dart':
flutter: Failed assertion: line 110 pos 12: '_positions.isNotEmpty'
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
其實,只需要延時一下而已,需要先等待界面初始化好再滑動.
58.出現 setState() called after dispose()
顧名思義,在dispose()之后調用了setState().解決辦法:
1
2
3
4
5
|
if
(mounted) {
setState(() {
..........
});
}
|
59.TextField 需要加個背景色.filled必須為true
60.需要在initstate里面使用context.
比如:需要在initstate方法里面獲取到屏幕的高來做一個動畫的話,可以像這樣:
@override void initState() { // TODO: implement initState super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { _controller = new AnimationController( duration: const Duration(milliseconds: 300), vsync: this); _animation = new Tween(begin: 0.0, end: MediaQuery.of(context).size.height) .animate(_controller) ..addListener(() { setState(() {}); }); }); }
關鍵點就是使用
1
2
|
WidgetsBinding.instance.addPostFrameCallback((_) {
.....這里可以獲取到context
|
1
|
});
|
61.使用Center的注意點:
使用Center會對包裹Center的組件發生類似Expanded 的作用.
62.model的判斷
可以直接?判斷是否為空,不為空才會取后面的值.比如:
63.在最近幾日,flutter build ios時,經常被牆.翻了牆也不行,換手機網絡也不行.報錯:
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60
這個錯誤,當初在做iOS原生開發遇到過.都是翻下牆就好了.但是現在不行.只能換源了.還必須有兩個源才行.一個默認自帶的,一個天朝這邊的....真是夠了...
如果這樣還是不行.可以讓終端也走代理設置. (或者Mac下載一個ITerm代替終端使用亦可)
64.在使用fluwx分享時,因為分享有點慢,就加了個loading圖,需要同時在微信回調和界面返回時,控制loading的顯示與否.回調控制是好的,但是如果用戶點擊的是系統返回.就不行了.只能借助flutter官方的生命周期監聽了.
但是呢,只有在 AppLifecycleState.resumed 下才能修改state. 如果是其余狀態修改的話,分享的剩余狀態就會失敗了....
這里的修改state最好是在外面加一層延時,延時之后再setState,保證萬無一失.
65.界面出現多次請求或者多次渲染情況.比如多次切換Tab,或者一個界面使用了其他封裝的圖片class.在上下滑動時,出現圖片再次渲染現象.或者在寫一個列表時,對其中的class小部件也做下保持狀態,防止小部件為class的時候,上下滑動時,界面重置. 這個情況需要配置切換tab和混入其他類:AutomaticKeepAliveClientMixin.詳見當初學習時寫的項目.
https://github.com/pheromone/flutter_shop
https://github.com/pheromone/flutter_video_audio_news
66.showModalBottomSheet切圓角
https://blog.csdn.net/cpcpcp123/article/details/97660036
67.點擊空白縮回鍵盤.類似於原生的取消第一響應者功能.
https://segmentfault.com/a/1190000021314427
https://www.cnblogs.com/LiuPan2016/p/10347423.html
68. 點擊其他按鈕彈出鍵盤,調起第一響應者.
// Initialise outside the build method FocusNode nodeOne = FocusNode(); FocusNode nodeTwo = FocusNode(); // Do this inside the build method TextField( focusNode: nodeOne, ), TextField( focusNode: nodeTwo, ), RaisedButton( onPressed: () { FocusScope.of(context).requestFocus(nodeTwo); }, child: Text("Next Field"), ),
https://www.jianshu.com/p/f6b994fdb9fb
69. ios Undefined symbols for architecture armv7:
https://www.jianshu.com/p/c37831cef020
70.最近,代碼被搞丟了.於是重新拉取庫,build的時候iOS出現: flutter unable to open file (in project "Runner") (in target 'Runner')
解決辦法:
1. cd 根目錄
2. flutter clean
3. flutter create .
4.重新打開Xcode.clean即可
https://github.com/flutter/flutter/issues/22886
71.最近,代碼被搞丟了.於是重新拉取庫,build的時候Android出現:SSL peer shut down incorrectly
https://www.jianshu.com/p/194b57cf7162
ps:惡心的某個組織.艹
72. 修改TextField的高度,以及無邊框圓角
https://www.cnblogs.com/ChengYing-Freedom/p/10304959.html
73. TextField提示語hintText不居中
https://blog.csdn.net/ly410726/article/details/102698351
74.textField設置圓形邊框並且改變邊框顏色,如果不修改會顯示主題顏色
https://blog.csdn.net/xiaoqi307/article/details/95169874
75.BottomNavigationBar設置4個BottomNavigationBarItem無效問題
需要加一個 type: BottomNavigationBarType.fixed,
https://www.jianshu.com/p/363b66358de1
76. iOS打包出現: WARNING ITMS-90725:“SDK Version issue”.this app was build the iOS 12.4 SDK.Starting April 2020.all iOS apps submitted to the APP store must be build with the ios 13SDK or later,inclured in Xcode 11 or later
使用AS運行出現 Flutter Device doesn't support wireless sync
因為我的是Xcode10.3. flutter v1.9.1+hotfix.2 .我這邊的方案是: channel master
如果報錯說需要git pull, 那就 執行 git pull.之后會升級到最新的master版本.
記得翻個牆牆.避開土匪干擾.
之后通常就好了.flutter clean 之后再flutter build ios試試看三方庫是否需要升級.如果需要它會提示.升級之后就可以正常運行真機和打包了
77.命令flutter build apk 出現 AndroidX incompatibilities may have caused this build to fai
https://www.zhulou.net/post/2366.html
78.為了適配iOS13+升級了flutter,使用AS運行真機項目會一直卡在 Installing and launching...導致無法調試??????
百度幾條,屁都沒有,谷歌幾條.試了也沒啥用....模擬器是好的,真機不行....只能先模擬器測試了
a.https://github.com/flutter/flutter/issues/43570
沒用....
b.https://github.com/flutter/flutter/issues/46705
.
沒用.
c.https://github.com/flutter/flutter/issues/37699
c.
只能熱重啟,無法看到日志輸出.....雞肋..
最終,只能升級到最新才行.....
79. flutter packages get 之后長時間沒有反應(飯牆也一樣,AS也一樣.到底為何???)
可以在.bash_profile文件中添加
export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
然后
source ~/.bash_profile
然后打開飯牆,直接運行 flutter packages get 拉取
白天可以了.但是晚上還是會慢