1. 路由开启下一个页面的,后退黑屏问题
当Navigator.push开启下一个页面,这个页面Navigator.pop(context)回到上一个页面出现黑屏,把当前页面的MaterialApp去掉就好
2. 弹软键盘,布局随键盘顶上去问题
在Scaffold加属性resizeToAvoidBottomPadding: false
3. 弹软键盘,iOS关闭不了软键盘
在布局外层包裹一层点击事件
InkWell( onTap: () { FocusScope.of(context).requestFocus(FocusNode()); }, child: child )复制代码
4. 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]); });复制代码
5. Android 嵌套Flutter 后退键返回上一级页面处理
override fun onBackPressed() { if (flutterView != null) { flutterView?.popRoute() } else { super.onBackPressed() }}复制代码
6. 国际化 当用一些控件时 默认是英文这时候就需要国际化了(例如:选择日期组件)
依赖: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'), ], );复制代码
7. 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); } });复制代码
8. 集成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, grantResults: IntArray) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) flutterView?.pluginRegistry?.onRequestPermissionsResult(requestCode, permissions, grantResults)}复制代码
9. Flutter 在iPhone输入框中长按复制粘贴弹窗报错的问题
有一种方法在iOS中显示Android的风格
Theme( data: ThemeData(platform: TargetPlatform.android), child: TextField( *****) )复制代码