flutter 问题记录

1、listview 上下有空白间隔:MediaQuery.removePadding包裹

MediaQuery.removePadding(context: context,
    removeBottom: true,
    removeTop: true,
    child: ListView.builder(
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      itemCount: 5,
      itemBuilder: (context, index){
        return AssetsImage('home-bg-top.png', fit: BoxFit.fitWidth,);
      },
    )
)

2、flutter 打包Android debug和release包如果出现部分功能不一致,可能为 Flutter1.17以后增加了自带混淆功能。(在开发阿里百川功能时遇到的问题总结)

     解决两种方式:
                          1)增加flutter plugins在Android中proguard-rules.pro中的混淆配置

                          2)关闭混淆

minifyEnabled false //删除无用代码
useProguard false    //代码压缩设置
shrinkResources false //删除无用资源

signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

3、ios pod install 慢,导致部分库导入不成功。
    在podfile中增加:source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

    pod库版本低会导致部分flutter库导入不成功(jpush_flutter),解决(更新最新库)

pod repo update master

     ios运行或打包错误,一部分原因需要在android studio devices运行一遍,再在xcode中运行解决                         

4、微信相关,fluwx 3.4.2

     1)微信5.4.3开始jcenter关停。需要在根目录build.gradle增加mavenCentral()

     2) Android端由于kotlin版本问题导致:org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong bytecode错误。

    解决:修改根目录build.gradle,kotlin版本为1.3.72

5、系统分享,引用库:share_plus: ^2.1.4

    问题:安卓分享朋友多图在部分机型出现:分享失败,多文件分享仅支持照片格式。

    解决:需要下载库手动引入到plugins中,修改安卓Share.java文件中getUrisForPaths方法如下:

file = copyToShareCacheFolder(file);

//uris.add(FileProvider.getUriForFile(getContext(), providerAuthority, file));

ApplicationInfo applicationInfo = getContext().getApplicationInfo();
int targetSDK = applicationInfo.targetSdkVersion;
if (targetSDK >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
           
uris.add(Uri.parse(MediaStore.Images.Media.insertImage(getContext().getContentResolver(), file.getAbsolutePath(), file.getName(), null)));
} else {
  uris.add(Uri.fromFile(file));
}

6、webview_cookie_manager:1.0.3 库ios最低版本是11.0

        设备运行可以,但是hoc打包会出现module not found错误

        解决:

       需要在xcode-info中iOS Deployment Target中设置对应11

7、部分安卓机型(oppo r9s):
:DioError [DioErrorType.DEFAULT]: HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:354)) 无法获取本地证书

解决:
添加如下代码 强行信任

Dio dio = Dio();
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client){
    client.badCertificateCallback=(cert, host, port){
        return true;
    };
};

 CachedNetworkImage:https证书导致的问题解决:

CachedNetworkImage(
    width: width,
    height: height,
    fit: fit,
    imageUrl: imageUrl,
    cacheManager: EsoImageCacheManager(),
  );
import 'dart:async';

import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:http/http.dart' as http;
import 'dart:io';

/// 缓存管理
class EsoImageCacheManager extends CacheManager {
  static const key = 'libEsoCachedImageData';

  static EsoImageCacheManager _instance;
  factory EsoImageCacheManager() {
    _instance ??= EsoImageCacheManager._();
    return _instance;
  }

  EsoImageCacheManager._() : super(Config(key, fileService: EsoHttpFileService()));
}

class EsoHttpFileService extends FileService {
  HttpClient _httpClient;
  EsoHttpFileService({HttpClient httpClient}) {
    _httpClient = httpClient ?? HttpClient();
    _httpClient.badCertificateCallback = (cert, host, port) => true;
  }

  @override
  Future get(String url,
      {Map headers = const {}}) async {
    final Uri resolved = Uri.base.resolve(url);
    final HttpClientRequest req = await _httpClient.getUrl(resolved);
    headers?.forEach((key, value) {
      req.headers.add(key, value);
    });
    final HttpClientResponse httpResponse = await req.close();
    final http.StreamedResponse _response = http.StreamedResponse(
      httpResponse.timeout(Duration(seconds: 60)), httpResponse.statusCode,
      contentLength: httpResponse.contentLength,
      reasonPhrase: httpResponse.reasonPhrase,
      isRedirect: httpResponse.isRedirect,
    );
    return HttpGetResponse(_response);
  }
}

8、webview_flutter:2.0.10版本
不显示网页:I/X509Util: Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

解决:下载源码,导入plugins。修改FlutterWebViewClient.java文件中internalCreateWebViewClient和internalCreateWebViewClientCompat方法,增加:

@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler,         
         SslError error) {
  handler.proceed();
}

网页字体不随系统字体大小变化:

Android:WebSettings settings = webView.getSettings(); settings.setTextZoom(100);

iOS:body { -webkit-text-size-adjust: none !important; }

9、集成支付宝支付Tobias库时与flutter_alibc冲突。主要为UTDID冲突

解决:去阿里文档中心 https://docs.open.alipay.com/54/104509 重新下载没有UTDID冲突的库

flutter 问题记录_第1张图片

下载-解压,替换如下图(删除原来的):

flutter 问题记录_第2张图片

10、Android 11 存储权限问题(targetSdkVersion 30)

①AndroidManifest.xml  增加   

② flutter权限判断 

 if (await Permission.storage.request().isGranted && await Permission.manageExternalStorage.request().isGranted) {}

11、webview 微信支付,商家参数错误其中一个问题解决(android端referer丢失问题)
针对:webview_flutter:2.0.10

39行增加:
String mReffer = "";

91行修改:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
                        boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        if (!hasNavigationDelegate) {
             return false;
        }
        Map header = new HashMap<>();
        if (request != null&&request.getRequestHeaders()!=null) {
            header = request.getRequestHeaders();
        }
        header.put("Referer", mReffer);

        notifyOnNavigationRequest(request.getUrl().toString(), header, view, request.isForMainFrame());
        return request.isForMainFrame();
}

125行修改:
boolean shouldOverrideUrlLoading(WebView view, String url) {
     if (!hasNavigationDelegate) {
         return false;
     }
     Map header = new HashMap<>();
     header.put("Referer", mReffer);
     notifyOnNavigationRequest(url, header, view, true);
     return true;
}

194行增加:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
                             @Nullable
                             @Override
                             public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
        Map lRequestHeaders = request.getRequestHeaders();
        if (lRequestHeaders.containsKey("Referer")) {
            mReffer = lRequestHeaders.get("Referer");
        }
        return super.shouldInterceptRequest(view, request);
}

251行增加:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
                             @Nullable
                             @Override
                             public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
      Map lRequestHeaders = request.getRequestHeaders();
      if (lRequestHeaders.containsKey("Referer")) {
           mReffer = lRequestHeaders.get("Referer");
      }
      return super.shouldInterceptRequest(view, request);
}

12、Hero动画,当包含子组件有TextField是报错如下:

No Material widget found. Hero Animation is not working with TextField

解决:Hero子组件用Material包含。

Hero(
  tag: "search",
  child: Material(
    type: MaterialType.transparency,
    child: Row(
      children: [
        //TextField(),
        //GestureDetector(),
      ],
    ),
  ),
);

13、安卓任务栏文件名称不显示,在老版flutter会出现问题。(华为提版:您的应用存在隐藏最近任务列表名称的行为,不符合华为应用市场审核标准),解决:

在MainActivity文件中重写 setTaskDescription:

//因flutter里会重置setTaskDescription,会导致最近任务标题消失,所以这里需要把标题重新设置
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
  override fun setTaskDescription(taskDescription: ActivityManager.TaskDescription?) {
    val description: ActivityManager.TaskDescription
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
      description = ActivityManager.TaskDescription("名称", R.mipmap.ic_launcher)
    } else {
      description = ActivityManager.TaskDescription("名称", BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
    }
    super.setTaskDescription(description)
  }

你可能感兴趣的:(flutter,ios,微信)