flutter

ElevatedButton 背景修改

You can style ElevatedButton by using the styleFrom static method or the ButtonStyle class. The first one is more convenience than the second one.

Using styleFrom to style an ElevatedButton:

ElevatedButton(
      child: Text('Button'),
      onPressed: () {},
      style: ElevatedButton.styleFrom({
           Color primary, // set the background color 
           Color onPrimary, 
           Color onSurface, 
           Color shadowColor, 
           double elevation, 
           TextStyle textStyle, 
           EdgeInsetsGeometry padding, 
           Size minimumSize, 
           BorderSide side, 
           OutlinedBorder shape, 
           MouseCursor enabledMouseCursor, 
           MouseCursor disabledMouseCursor, 
           VisualDensity visualDensity, 
           MaterialTapTargetSize tapTargetSize, 
           Duration animationDuration, 
           bool enableFeedback
     }),
),

冲突 allowBackup tools:replace

出现的问题: Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:116:9-36
is also present at [manager:common:unspecified:release] AndroidManifest.xml:12:9-35 value=(true).
Suggestion: add ‘tools:replace=”android:allowBackup”‘ to <application> element at AndroidManifest.xml:114:5-1136:19 to override.

 

 

解决方法:

<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
package=”包名”>
在application节点添加

<application tools:replace=”android:allowBackup” ……

同样的还有

tools:replace=”android:icon, android:theme,android:allowBackup”

flutter text超出屏幕 自动换行

 Expanded(
                                child: Text(item[“content”],
                                    softWrap: true, maxLines: 10))
                          ])

running gradle task assembledebug stuck

Here is solution in my case.

  1. Open your flutter Project directory.
  2. Change directory to android directory in your flutter project directory cd android
  3. clean gradle ./gradlew clean
  4. Build gradle ./gradlew build or you can combine both commands with just ./gradlew clean build (Thanks @daniel for the tip)
  5. Now run your flutter project. If you use vscode, press F5. First time gradle running assembleDebug will take time.

PS: Delete gradle in case of all that steps don’t work

Flutter集成到Android Studio中遇到的各种坑(实测)

一、Android Studio not found at /Users/*/Application/Android Studio.app/Contents
问题出现的原因:(解决另一个问题(问题二.2)引起的)

1.配置完问题二.2后,我flutter doctor就出现

 

明明我的flutter插件和Dart插件都安装好了,还提示我未安装。

解决办法:运行命令:flutter config –android-studio-dir=

二、flutter项目在Android Studio中显示no devices,没法flutter run

问题环境(Mac、Android studio3.1.2) 这个问题真是坑,网上的各种办法都试了,就是不行,试过的办法有:

1、检查Android studio中的flutter项目的flutter sdk路径、Dartsdk路径、Androidsdk路径

 

 

 

上面三个路径都在我的项目设置中检查过,没问题,所以这个无法解决我的问题二。

2、在终端把flutter和Android studio绑定、在终端把flutter和Android sdk绑定。

flutter config –android-sdk 自己的android sdk路径

flutter config –android-studio-dir 自己的android studio安装路径

这里的Android studio安装路径我不知道 Mac电脑的程序安装路径到底是怎么获取(有知道的告知一下,我怀疑就是这里搞错了,才没解决问题二,并且引出了问题一),所以我在应用程序里面右键选择“显示包内容”,然后把这个里面的一个文件夹拖进去终端

 

3、最终我通过自己的方法运行项目:这个办法要先解决问题一

我在Android studio的终端Terminal运行了

flutter clean

flutter run

 

这样发现居然可以运行了,虽然点上面的运行绿色按钮还是提示no devices。但我觉得这个办法很牵强。

 

还可以配合这些命令使用flutter run。

三、FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ‘:app:compileDebugJavaWithJavac’.
> Could not resolve all task dependencies for configuration ‘:app:debugCompileClasspath’.
> Could not resolve io.flutter:flutter_embedding_debug:1.0.0-ee76268252c22f5c11e82a7b87423ca3982e51a7.

 

用了终端的flutter run运行遇到这个问题。

解决办法:在Android项目下的build.gradle增加一个仓库:maven { url “http://download.flutter.io” },增加完之后就

flutter run

这样我就在Mac运行了自己的第一个flutter项目。

 

四、…..\android\sdk\platform-tools\adb.exe is too old;please install version 1.0.39 or later

这个问题是Windows产生的,因为我电脑C盘和D盘有两个Android SDK,不知道他这里就选到了C盘下比较老的版本,既然这样,我就去settings里面设置我另一个Android SDK不就可以。结果我去一看,这明明已经是D盘下新的SDK:

 

然后就各种抓头,这是啥东西啊,搞人啊,最后没办法我把C盘下的SDK给删除了,就可以了。

五、Android studio新建Flutter项目,报错could not find an option named “platforms”(2021-08-08)
原因:Flutter SDK版本过低导致

解决:下载最新版本Flutter SDK即可

 

从flutter1.17.4升级到2.2.3;可能是我中间升级过一次Android Studio

六、Error: Cannot run with sound null safety, because the following dependenciesdon‘t support null safe
Flutter 启动运行的时候报错:

Error: Cannot run with sound null safety, because the following dependencies
don’t support null safety:

– package:banner_view

For solutions, see https://dart.dev/go/unsound-null-safety

Command PhaseScriptExecution failed with a nonzero exit code

解决方案:(这是因为flutter2.0增加了 null safety模式,很多第三方库还不支持这个模式)

可以直接在命令行中执行

flutter run –no-sound-null-safety
也可以到Android studio中去设置运行配置

首先打开Edit Configurations 页面,填上:–no-sound-null-safety

 

————————————————
版权声明:本文为CSDN博主「sunbinkang」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/sunbinkang/article/details/106941458

Flutter引用第三方库时Automatically assigning platform `ios` with version `8.0` on target `Runner`错误解决

Automatically assigning platform ios with version 8.0 on target Runner because no platform was specified. Please specify a platform for this target in your Podfile

在mac上使用引用了第三方库,发现报错,解决步骤如下:

解决办法:

1.platform version错误,解决方法是修改项目里的ios/Podfile文件:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '8.0' #增加的内容

之后又遇到如下问题

2.SWIFT_VERSION版本未指定问题,解决方法是修改项目里的ios/Podfile文件:

flutter Unable to determine Swift version for the following pods

是指定的SWIFT版本问题,但xcode的tagets中没有指定SWIFT_VERSION版本这一项,点buildSettings中的+号,添加SWIFT_VERSION,指定版本号4.2,再执行pod update –verbose –no-repo-update解决问题

修改项目里的ios/Podfile文件:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '4.2'  #增加修改内容
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

3.flutter ‘xxxxx/xxxx-Swift.h’ file not found问题:修改项目里的ios/Podfile文件

之后又遇到如下问题

flutter ‘xxxxx/xxxx-Swift.h’ file not found

修改项目里的ios/Podfile文件:

target 'Runner' do
  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  use_frameworks! # required by qr_code_tools #增加修改的内容
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')

4.PrerollContext does not support embedding错误问题,解决方法是添加plist选项:

Trying to embed a platform view but the PrerollContext does not support embedding

解决方法:
Currently apps need to opt-in for the UIViews embedding preview on iOS by adding a boolean property to the Info.plist (key=io.flutter.embedded_views_preview value=YES).

在iOS工程的info.plist文件中添加键值对key=io.flutter.embedded_views_preview value=YES

Flutter 升级到1.20.0后打包报错解决方法

在打包命令后加入 –no-tree-shake-icons

flutter build apk –release –target-platform android-arm –no-tree-shake-icons

flutter build appbundle –release –target-platform android-arm,android-arm64 –no-tree-shake-icons

flutter build ios –release –no-tree-shake-icons