记录 Flutter
开发过程中遇到的一些问题和相关的解决方案~
1. --no-sound-null-safety 错误 on vscode
上面是VSCode
编辑器中空校验错误。解决方案如下:
// vscode 编辑器项目根目录中创建文件 .vscode/launch.json
// 添加内容
"args": [
"--no-sound-null-safety"
]
// 完整的文件代码示例
{
"configurations":[
{
"name": "jimmy flutter demo",
"program": "lib/main.dart",
"request": "launch",
"type": "dart",
"args": [
"--no-sound-null-safety"
]
}
]
}
// 之后重新运行项目即可
2. 设置 flutter_screenutil 报错
直接引用包 flutter_screenutil
去使用,会报错使用不了 ScreenUtil().setWidth(width)
等方法。
这个错误就是我们并没有按照官网进行使用。需要根据官网逐步进行。
这里我使用方式一 -- 在app中使用它一次。
代码语言:javascript复制void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
//填入设计稿中设备的屏幕尺寸,单位dp
return ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: (context , child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'First Method',
// You can use the library anywhere in the app even in theme
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp),
),
home: child,
);
},
child: const HomePage(title: 'First Method'),
);
}
}
3. 构建安卓应用包出错
在应用开发完成之后,构建安卓的图标文件,可能会出现报错:
代码语言:javascript复制✗ ERROR: InvalidConfigException
Cannot not find minSdk from android/app/build.gradle or android/local.propertiesSpecify minSdk in either android/app/build.gradle or android/local.properties
#0 createIconsFromConfig (package:flutter_launcher_icons/main.dart:96:7)
#1 createIconsFromArguments (package:flutter_launcher_icons/main.dart:60:7)
#2 main (file:///Users/jimmy/Documents/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.9.3/bin/main.dart:7:26)
#3 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
可以在android/local.properties
文件中添加内容:
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=30
在应用开发完成之后,针对安卓应用去打包,可能会出现报错:
Execution failed for task ':app:processReleaseMainManifest'. Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library
这是因为minSdkVersion
的问题,我们更改下相关的文件版本即可:
// 解决方案
// android/app/build.gradle
defaultConfig {
// // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
// applicationId "com.example.jimmy_flutter_demo"
// // You can update the following values to match your application needs.
// // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
// minSdkVersion flutter.minSdkVersion
// targetSdkVersion flutter.targetSdkVersion
// versionCode flutterVersionCode.toInteger()
// versionName flutterVersionName
applicationId "com.example.jimmy_flutter_demo"
minSdkVersion 21 // 更改最小的版本
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
如果构建成功,你会看到输出目录提示内容类似下面:
代码语言:javascript复制✓ Built build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk (7.5MB).
目前暂时遇到这些Bug
,后续会持续更新... 欢迎关注收藏