Flutter 开发出现的那些 Bugs 和解决方案「持续更新... 」

网友投稿 851 2022-08-27

Flutter 开发出现的那些 Bugs 和解决方案「持续更新... 」

Flutter 开发出现的那些 Bugs 和解决方案「持续更新... 」

记录 ​​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: InvalidConfigExceptionCannot 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. (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.0flutter.versionCode=1flutter.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.gradledefaultConfig { // // TODO: Specify your own unique Application ID ( // applicationId "com.example.jimmy_flutter_demo" // // You can update the following values to match your application needs. // // For more information, see: // 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​​,后续会持续更新... 欢迎关注收藏

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:css这么强大吗?
下一篇:介绍几个有趣的网站(二十)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~