携手创作,一起成长!这是我参与「日新计划 8 月更文挑战」的第4天,点击查看活动详情
记载 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中运用它一次。
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. 构建安卓使用包出错
在使用开发完成之后,构建安卓的图标文件,可能会呈现报错:
✗ 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"
}
假如构建成功,你会看到输出目录提示内容类似下面:
✓ Built build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk (7.5MB).
目前暂时遇到这些 Bug
,后续会持续更新… 欢迎重视保藏
往期精彩引荐
- Dart 知识点 – 数据类型
- Dart 知识点 – 运算符
假如读者觉得文章还能够,不防一键三连:重视➕点赞➕保藏