Flutter 问题解决总结

路由开启下一个页面的,后退黑屏问题

当Navigator.push开启下一个页面,这个页面Navigator.pop(context)回到上一个页面出现黑屏,把当前页面的MaterialApp去掉就好

弹软键盘,布局随键盘顶上去问题

在Scaffold加属性resizeToAvoidBottomPadding: false

弹软键盘,iOS关闭不了软键盘

在布局外层包裹一层点击事件
 InkWell(
        onTap: () {
            FocusScope.of(context).requestFocus(FocusNode());
        },
        child: child
     )

ScrollView 嵌套 ListView 滚动问题

ListView.builder(
        shrinkWrap: true,
        physics: NeverScrollableScrollPhysics(),// 主要这个
        padding: EdgeInsets.fromLTRB(15, 0, 15, 15),
        itemCount: subjects.length,
        itemBuilder: (BuildContext context, int position) {
            return getItem(context, subjects[position]);
      });

Android 嵌套Flutter 后退键返回上一级页面处理

override fun onBackPressed() {
    if (flutterView != null) {
        flutterView?.popRoute()
    } else {
        super.onBackPressed()
    }
}

国际化 当用一些控件时 默认是英文这时候就需要国际化了(例如:选择日期组件)

依赖:flutter_localizations:
             sdk: flutter

  import 'package:flutter_localizations/flutter_localizations.dart';
  
  return MaterialApp(
     home: child,
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('zh', 'CH'),
        // const Locale('en', 'US'),
      ],
    );

Rxdart 进行网络请求 例如:

ProgressDialog _progressDialog = ProgressDialog(context);
  ApiRepository.resetPassword(_phoneController.text, _codeController.text,
          _newPasswordContrpller.text)
      .doOnDone(() => _progressDialog.hide())
      .doOnListen(() => _progressDialog.show())
      .doOnError((error, stacktrace) {
    if (error is DioError) {
      showToast("加载失败,请检查网络连接");
    }
  }).listen((baseResp) {
    if (baseResp != null && baseResp.isSuccess()) {
      showToast("重置成功");
      Navigator.pop(context);
    } else {
      showToast(baseResp.msg);
    }
  });

集成image_pick不回调(Android端集成Flutter)

Android端添加回调代码
 override fun onActivityResult(requestCode: Int, resultCode:Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    flutterView?.pluginRegistry?.onActivityResult(requestCode, resultCode, data)
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    flutterView?.pluginRegistry?.onRequestPermissionsResult(requestCode, permissions, grantResults)
}

    原文作者:尤小红
    原文地址: https://zhuanlan.zhihu.com/p/61275459
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞