1、Waiting for another flutter command to release the startup lock...
打开新的项目或者使用Flutter Packages get时出现: Waiting for another flutter command to release the startup lock...
解决方案:
先打开任务管理器,结束掉所有dart.exe即可,如果依然提示就打开你的flutter安装文件夹,找到\bin\cache中的lockfile文件删除。之后重启项目。
2、The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app
Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution
解决方案一:
设法通过添加这样的代码片段来修复错误
在项目 android > build.gradle 文件中 buildscript { } 中添加此代码片段
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "27.1.1"
}
if (details.requested.group == 'androidx.core'
&& !details.requested.name.contains('androidx') ) {
details.useVersion "1.0.1"
}
}
}
}
解决方案二:
1.android/gradle/wrapper/gradle-wrapper.properties里面
distributionUrl=https\:
2.android/build.gradle
dependencies { classpath 'com.android.tools.build:gradle:3.3.0' }
3.android/gradle.properties
加入
android.enableJetifier=true
android.useAndroidX=true
4.android/app/build.gradle 修改版本号:
make sure compileSdkVersion and targetSdkVersion are at least 28.
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
5.android/app/build.gradle /defaultConfig加上
multiDexEnabled true
3、Error connecting to the service protocol: HttpException: Connection closed before full header was...
最后是使用安卓系统版本是9.1 Android版本太高,换8.1就好了
查看 Android Studio Sdk Manager 版本
查看项目App目录下 compileSdkVersion
4、type 'List' is not a subtype of type 'List'
Wrap(
children:item['casts'].map<Widget>((casts){
return Text('data');
}).toList(),
)
更复杂的答案是,虽然类型children是List<Widget>,该信息不会回流到map调用。这可能是因为map后面是toList因为没有办法输入注释闭包的返回。
5、chewie插件在ios下播放失败的问题
<!-- 在项目根目录 > ios > Runner > info.plist 文件中
<dict>尾部
添加视频播放需要的nsapp传输安全的key
-->
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
6、snackBar报错的问题无法弹出,Scaffold.of() called with a context that does not contain a Scaffold.
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
return new Scaffold(
key: _scaffoldkey,
........
),
.......
)
onPressed: (){
_scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text("这是一个SnackBar"),
duration: Duration(
milliseconds: 1
),
action: SnackBarAction(
label: "别点我",
onPressed: () {
print("SnackBar上面的按钮被点击了");
}
),
)
);
},
)
7、脚手架sliver、scaffold中设置appbar、tabbar的高度或者背景色
SliverPersistentHeader(
pinned: true,
delegate: StickyTabBarDelegate(
child:PreferredSize(
preferredSize: Size.fromHeight(40),
child: Material(
color: Colors.grey[200],
child: TabBar(
labelColor: Colors.black,
controller: this._tabController,
indicatorColor: Colors.black,
tabs: <Widget>[
Tab(text: '评论'),
Tab(text: '话题区'),
],
),
),
),
),
),
8、去掉状态栏代码实现
做Flutter做屏效果显示的时候,调用SystemChrome.setEnabledSystemUIOverlays([]); 这个方法把状态栏和虚拟按键隐藏掉
跳转到其他页面后需要调用把状态栏显示出来,调用SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);
需要一起调用底部虚拟按键(华为系列某些手机有虚拟按键),则SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top, SystemUiOverlay.bottom]);
9、Image.File 加载图像时文件内容变化但图像不变
新创建一个类
class FileImageEx extends FileImage {
int fileSize;
FileImageEx(File file, { double scale = 1.0 })
: assert(file != null),
assert(scale != null),
super(file, scale: scale) {
fileSize = file.lengthSync();
}
@override
bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType)
return false;
final FileImageEx typedOther = other;
return file?.path == typedOther.file?.path
&& scale == typedOther.scale && fileSize == typedOther.fileSize;
}
}
接下来,直接使用下面的代码来加载图像:
Image(image: FileImageEx(File(_fileName)));
10、Inkell 去掉水波纹的方法
InkWell(
highlightColor:Colors.transparent,
radius: 0.0,
onTap: (){
},
child: Text('跳过 ${_time}s'),
),
11、打包release版本安卓apk包真机无法请求网络
在项目目录android\app\src\profile\AndroidManifest.xml manifest 里添加这段代码
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
在项目目录 android/src/main/AndroidManifest.xml 里也有一个 AndroidManifest.xml文件!跟之前的只不过是文件夹位置不同而已,同样在manifest标签下加入相同配置就行了,不要放到application里
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
重新打包即可
12、setstate() called after dispose() ,setstate导致的内存泄漏
if(mounted){
setState(() {
_movie = res.data;
_themeColor = paletteGenerator.colors.toList()[1];
_detailThemeColor = paletteGenerator.colors.toList()[0];
});
}
13、xCode打包提示:Could not find included file 'Generated.xcconfig' in search paths (in target 'Runner')
14、更新showDialog以及showModalBottomSheet中的状态中的内容
showDialog(
context: context,
builder: (context) {
String label = 'test';
return StatefulBuilder(
builder: (context, state) {
print('label = $label');
return GestureDetector(
child: Text(label),
onTap: () {
label = 'test8';
print('onTap:label = $label');
state(() {});
},
);
},
);
}
);
showModalBottomSheet(context:context, builder:(BuildContext context){
return StatefulBuilder(
builder:(context1, state) {
return Container(
child:OutlineButton(
onPressed: (){
state(() {
btnState=!btnState;
});
},
child:Stack(
children: <Widget>[
Opacity(
opacity: btnState ? 0.0 : 1.0,
child: Text("aa"),
),
Opacity(
opacity: btnState ? 1.0 : 0.0,
child: Text("bb"),
)
],
),
),
),
}
)
})
15、SliverPersistentHeader 组件内状态更新,但UI未更新
SliverPersistentHeader(
pinned: true,
delegate: SliverBarDelegate(
PreferredSize(
preferredSize: Size.fromHeight(ScreenAdapter.height(80)),
child:_headActions()
),
),
),
class SliverBarDelegate extends SliverPersistentHeaderDelegate {
final widget;
SliverBarDelegate(this.widget);
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(
child: widget,
);
}
@override
bool shouldRebuild(SliverBarDelegate oldDelegate) {
return true;
}
@override
double get maxExtent => widget.preferredSize.height;
@override
double get minExtent => widget.preferredSize.height;
}
16、packages get 慢的解决方案
具体环境变量的值 需要看该网址 [Using Flutter in China](https:
17、如何将String类型的颜色转化为Color所需要的int类型的颜色
Color(int.parse('0xff'+color)
18、is a SingleTickerProviderStateMixin but multiple tickers were created.
I/flutter ( 4025): A SingleTickerProviderStateMixin can only be used as a TickerProvider once. If a State is used for
I/flutter ( 4025): multiple AnimationController objects, or if it is passed to other objects and those objects might
I/flutter ( 4025): use it more than one time in total, then instead of mixing in a SingleTickerProviderStateMixin, use
I/flutter ( 4025): a regular TickerProviderStateMixin.
大概翻译意思:单个TickerProviderStateMixin,但创建了多个Ticker,单个statemixin 只能供一个TickerProvider使用,如果一个状态用于多个对象,它可能被传递给其他对象。
19、动画释放报错
e following assertion was thrown while finalizing the widget tree:
I/flutter ( 3776): _CustomScrollFooterState#3df1f(ticker active) was disposed with an active Ticker.
I/flutter ( 3776): _CustomScrollFooterState created a Ticker via its SingleTickerProviderStateMixin, but at the time
I/flutter ( 3776): dispose() was called on the mixin, that Ticker was still active. The Ticker must be disposed before
I/flutter ( 3776): calling super.dispose(). Tickers used by AnimationControllers should be disposed by calling
I/flutter ( 3776): dispose() on the AnimationController itself. Otherwise, the ticker will leak.
I/flutter ( 3776): The offending ticker was: Ticker(created by _CustomScrollFooterState#3df1f(lifecycle state:
I/flutter ( 3776): created))
controller.dispose()放在了 super.dispose()的后面:
@override
void dispose() {
controller.dispose();
super.dispose();
}
20、Could not resolve all files for configuration ':app:lintClassPath'.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Could not resolve all files for configuration ':app:lintClassPath'.
> Could not download groovy-all.jar (org.codehaus.groovy:groovy-all:2.4.12)
> Could not get resource 'https://jcenter.bintray.com/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar'.
> Could not GET 'https://jcenter.bintray.com/org/codehaus/groovy/groovy-all/2.4.12/groovy-all-2.4.12.jar'.
> Remote host closed connection during handshake
在app的build.gradle中的android部分添加如下代码块即可
lintOptions {
checkReleaseBuilds false
abortOnError false
}
21、设置沉浸式状态栏,取消android状态栏阴影
if (Platform.isAndroid) {
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
22、更改文件名或删除名称时报错,were declared as an inputs, but did not exist. Check the definition of target:kernel_snapshot for errors
C:\Users\Admin\Desktop\flutter_jahn_douban\lib\pages\tabs\book_movie\movie\movieTop\movieTopAll\movie_top_all.dart, C:\Users\Admin\Desktop\flutter_jahn_douban\lib\pages\tabs\book_movie\movie\movieTop\movieTopAll\movie.dart were declared as an inputs, but did not exist. Check the definition of target:kernel_snapshot for errors
#0 Node.computeChanges (package:flutter_tools/src/build_system/build_system.dart:777:7)
<asynchronous suspension>
#1 _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:517:20)
<asynchronous suspension>
#2 _BuildInstance.invokeTarget.<anonymous closure> (package:flutter_tools/src/build_system/build_system.dart:481:35)
删除.dart_tool文件夹,然后重新运行即可。
23、修改版本号不生效
Flutter的App版本号设置在pubspec.yaml中,+号前面是版本名称,后面是版本号,在此修改会自动应用到Android和IOS项目对应版本号中,修改完安装发现并未生效,解决方法:
1、flutter get
2、flutter clean
重新 build ios 安装就能生效了
24、Fluro中传递中文参数失败
无效的参数:URI中的非法编码百分比
通过Uri.encodeComponent(Text)转化
25、TextField组件,报错解决:The following assertion was thrown while handling a gesture
WidgetsBinding.instance.addPostFrameCallback((_) => controller.clear());
26、TabController的监听在点击Tab后会执行两次
_tabController.addListener((){
if(_tabController.indexIsChanging){
}
});
27、判断页面渲染完毕,获取指定元素的位置和大小
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(_onAfterRendering);
}
void _onAfterRendering(Duration timeStamp){
RenderBox renderBox = _notUsed.currentContext.findRenderObject();
double width = renderBox.size.width;
double height = renderBox.size.height;
double x = renderBox.localToGlobal(Offset.zero).dx;
setState(() {
_currentHeight = height;
_currentWidth = width;
_currentLeft = x;
_currentIndex = 1;
});
}
28、Cannot fit requested classes in a single dex file.
在app > build.gradle文件的defaultConfig默认配置里面增加:
multiDexEnabled true
dependencies里面添加
implementation 'com.android.support:multidex:1.0.3'
29、A failure occurred while executing com.android.build.gradle.tasks.MergeResources$FileGenerationWorkA
在app > build.gradle文件的defaultConfig默认配置里面添加:
vectorDrawables.useSupportLibrary = true