flutter弹窗高度过高,在弹出键盘后布局溢出问题

server/2024/10/10 20:40:27/

1.最外层套脚手架控件:Scaffold,设置背景为透明或半透明。目的是将弹出键盘是的高度计算调整交给Scaffold。(直接用SingleChildScrollView仍然会出现布局溢出)
2.使用SingleChildScrollView包裹弹窗布局。
示例:

import 'package:jade/bean/createExpParam/BuyChargeDetail.dart';
import 'package:jade/configs/PathConfig.dart';
import 'package:jade/customWidget/CusBehavior.dart';
import 'package:jade/utils/JadeColors.dart';
import 'package:jade/utils/Utils.dart';
import 'package:util/easy_loading_util.dart';
import 'package:util/navigator_util.dart';
import 'package:util/number_text_input_formatter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';class CellPriceInfo{int monthNum; //月数double price;//价格double originPrice;//原价
//  double oneMonthPrice;//单月价格bool isSelect; //是否选中TextEditingController priceController;TextEditingController originPriceController;CellPriceInfo({this.monthNum,this.price,this.originPrice,this.isSelect = false,this.priceController,this.originPriceController}){this.priceController = priceController ?? TextEditingController();this.originPriceController = originPriceController ?? TextEditingController();}
}class FillInCellPriceDialog extends StatefulWidget{final int showNum;final Function sureCallBack;final List<BuyChargeDetail> viewedPriceInfoList;const FillInCellPriceDialog({this.sureCallBack,this.showNum,this.viewedPriceInfoList});State<StatefulWidget> createState() {// TODO: implement createStatereturn _FillInCellPriceDialog();}
}class _FillInCellPriceDialog extends State<FillInCellPriceDialog>{List<CellPriceInfo> _priceInfoList = []; //绘制ui的数组List<BuyChargeDetail> _buyChargeDetailList = [];//从弹窗返出去的数组void initState() {// TODO: implement initStatesuper.initState();_priceInfoList = [CellPriceInfo(monthNum: 10007),CellPriceInfo(monthNum: 10014),CellPriceInfo(monthNum: 1),CellPriceInfo(monthNum: 3),CellPriceInfo(monthNum: 6),CellPriceInfo(monthNum: 12)];if(widget.viewedPriceInfoList != null && widget.viewedPriceInfoList.isNotEmpty){for (var viewedPriceInfo in widget.viewedPriceInfoList) {for (var priceInfo in _priceInfoList) {if(viewedPriceInfo.monthNum == priceInfo.monthNum){priceInfo.priceController.text = '${viewedPriceInfo.price}';priceInfo.originPriceController.text = '${viewedPriceInfo.originPrice ?? ''}';priceInfo.isSelect = true;}}}}}void dispose() {// TODO: implement disposeif(_priceInfoList.isNotEmpty){_priceInfoList.forEach((element) {element.priceController.dispose();element.originPriceController.dispose();});}super.dispose();}Widget build(BuildContext context) {// TODO: implement buildreturn Scaffold(backgroundColor: Colors.transparent,body:ScrollConfiguration(behavior: CusBehavior(),child: SingleChildScrollView(child: Container(alignment: Alignment.center,margin: EdgeInsets.only(top: Utils().screenWidth(context) * 0.18),child: UnconstrainedBox(child: Container(alignment: Alignment.center,width: Utils().screenWidth(context) * 0.76,padding: EdgeInsets.only(top: 40.w, bottom: 30.w),decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),child: Column(mainAxisSize: MainAxisSize.min,crossAxisAlignment: CrossAxisAlignment.start,children: [Container(padding: EdgeInsets.only(left: 30.w, right: 40.w,),child: Text(widget.showNum == null ? '展位(格口)价格设置' : '${widget.showNum}号展位(格口)价格设置',style: TextStyle(color: JadeColors.grey_2,fontSize: 30.sp,fontWeight: FontWeight.w600)),),Container(padding: EdgeInsets.only(left: 30.w, right: 40.w,),child: Text('需设置原价与活动价(即实际售卖价格)',style: TextStyle(color: JadeColors.grey,fontSize: 24.sp,fontWeight: FontWeight.w600)),),Container(height: 1,color: JadeColors.grey_5,margin: EdgeInsets.only(top: 30.w,bottom: 30.w)),_listView(),SizedBox(height: 40.w),_btnView()],))),)),));}_listView(){return ListView.separated(itemBuilder: (context, index) {return _itemView(index);},shrinkWrap: true,physics: const NeverScrollableScrollPhysics(),separatorBuilder: (context,index) =>Container(height: 30.w,),itemCount: _priceInfoList.length);}_itemView(int index){return Container(padding: EdgeInsets.only(left: 30.w, right: 40.w),child: Row(children: [GestureDetector(child: Container(color: Colors.white,padding: EdgeInsets.all(5),child: Image.asset(_priceInfoList[index].isSelect ? PathConfig.iconSelectBlue2 : PathConfig.iconUnselect, width: 34.w,height: 34.w),),onTap: (){setState(() {_priceInfoList[index].isSelect = !_priceInfoList[index].isSelect;});},),SizedBox(width: Utils().monthNumToDayNum(_priceInfoList[index].monthNum) > 99 ? 24.w : Utils().monthNumToDayNum(_priceInfoList[index].monthNum) < 10 ? 50.w :40.w),Text('${Utils().monthNumToDayNum(_priceInfoList[index].monthNum)}天:',style: TextStyle(color: JadeColors.grey_3,fontSize: 28.sp)),Expanded(child: Column(children: [Container(width: double.infinity,height: 54.w,padding: EdgeInsets.symmetric(horizontal: 20.w),alignment: Alignment.center,decoration: BoxDecoration(borderRadius: BorderRadius.circular(5),border: Border.all(width: 1.w,color: JadeColors.grey)),child: TextField(enabled: _priceInfoList[index].isSelect,textAlign: TextAlign.start,controller: _priceInfoList[index].priceController,style: TextStyle(fontSize: 24.sp, color: JadeColors.grey_2),keyboardType: TextInputType.number,textInputAction: TextInputAction.done,inputFormatters: [NumberTextInputFormatter(2),FilteringTextInputFormatter(RegExp("[0-9.]"), allow: true),],maxLines: 1,maxLength: 40,decoration: InputDecoration(filled: true,fillColor: Colors.white,isCollapsed: true,isDense: true,contentPadding: EdgeInsets.zero,hintText: '请输入活动价(必填)',hintStyle: TextStyle(fontSize: 24.sp,color: JadeColors.grey,),disabledBorder: OutlineInputBorder(borderSide: BorderSide.none,borderRadius: BorderRadius.circular(8.w)),enabledBorder: OutlineInputBorder(borderSide: BorderSide.none),focusedBorder: OutlineInputBorder(borderSide: BorderSide.none),border: OutlineInputBorder(borderSide: BorderSide.none),counterText: ''),onChanged: (value) {if(value.isNotEmpty){double _parsedDouble = double.tryParse(value);if(_parsedDouble == null || _parsedDouble < 1){esLoadingToast('活动价格不能低于1元');}}},cursorColor: JadeColors.grey,)),SizedBox(height: 10.w),Container(width: double.infinity,height: 54.w,padding: EdgeInsets.symmetric(horizontal: 20.w),alignment: Alignment.center,decoration: BoxDecoration(borderRadius: BorderRadius.circular(5),border: Border.all(width: 1.w,color: JadeColors.grey)),child: TextField(enabled: _priceInfoList[index].isSelect,textAlign: TextAlign.start,controller: _priceInfoList[index].originPriceController,style: TextStyle(fontSize: 24.sp, color: JadeColors.grey_2),keyboardType: TextInputType.number,textInputAction: TextInputAction.done,inputFormatters: [NumberTextInputFormatter(2),FilteringTextInputFormatter(RegExp("[0-9.]"), allow: true),],maxLines: 1,maxLength: 40,decoration: InputDecoration(filled: true,fillColor: Colors.white,isCollapsed: true,isDense: true,contentPadding: EdgeInsets.zero,hintText: '请输入原价',hintStyle: TextStyle(fontSize: 24.sp,color: JadeColors.grey,),disabledBorder: OutlineInputBorder(borderSide: BorderSide.none,borderRadius: BorderRadius.circular(8.w)),enabledBorder: OutlineInputBorder(borderSide: BorderSide.none),focusedBorder: OutlineInputBorder(borderSide: BorderSide.none),border: OutlineInputBorder(borderSide: BorderSide.none),counterText: ''),onChanged: (value) {},cursorColor: JadeColors.grey,)),],))],));}_btnView(){return Row(mainAxisAlignment: MainAxisAlignment.end,children: [GestureDetector(child: Container(height: 44.w,padding: EdgeInsets.symmetric(horizontal: 40.w),margin: EdgeInsets.only(right: 20.w),alignment: Alignment.center,decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(20),border: Border.all(color: JadeColors.blue_2,width: 1.w)),child: Text('取消',style: TextStyle(color: JadeColors.blue_2,fontSize: 26.sp)),),onTap: (){NavigatorUtil.pop();}),GestureDetector(child: Container(height: 44.w,padding: EdgeInsets.symmetric(horizontal: 40.w),margin: EdgeInsets.only(right: 40.w),alignment: Alignment.center,decoration: BoxDecoration(color: JadeColors.blue_2,borderRadius: BorderRadius.circular(20)),child: Text('确定',style: TextStyle(color: Colors.white,fontSize: 26.sp)),),onTap: () async {print('_getPriceData= ${_getPriceData()}');if(_getPriceData() == null || !_getPriceData()){return;}if(widget.sureCallBack != null){widget.sureCallBack(_buyChargeDetailList);}NavigatorUtil.pop();},)],);}//要返出去的参数_getPriceData(){_buyChargeDetailList.clear();bool _canCallback = false;for(var element in _priceInfoList){if(element.isSelect){String _price = element.priceController.text.trim();String _originPrice = element.originPriceController.text.trim();double _parsedPriceDouble = double.tryParse(_price);double _parsedOriginPriceDouble = double.tryParse(_originPrice);if(_price.isEmpty){esLoadingToast('请输入${Utils().monthNumToDayNum(element.monthNum)}天活动价');_canCallback = false;return;}else if(_price.isNotEmpty && _parsedPriceDouble == null || _parsedPriceDouble < 1){esLoadingToast('${Utils().monthNumToDayNum(element.monthNum)}天活动价不能低于1元');_canCallback = false;return;}else{_canCallback = true;}if(_parsedOriginPriceDouble != null && _parsedOriginPriceDouble < 1){esLoadingToast('${Utils().monthNumToDayNum(element.monthNum)}天原价不能低于1元');_canCallback = false;return;}BuyChargeDetail _buyChargeDetail = BuyChargeDetail(monthNum: element.monthNum,price: double.parse(_price),originPrice: _originPrice.isNotEmpty ? double.parse(_originPrice) : null,);_buyChargeDetailList.add(_buyChargeDetail);}}return _canCallback;}}

http://www.ppmy.cn/server/58374.html

相关文章

无人机对地面运动目标定位---获取目标的移动方向和速度

目录 一、引子 我们利用单目无人机通过等时间间隔拍照的形式对地面某移动目标进行定位&#xff0c;当前&#xff0c;我们已经获得了每张相片上该目标的三维坐标&#xff0c;并且知道该无人机在飞行过程中拍照的时间间隔&#xff0c;那么我们就可以通过一定的计算&#xff0c;得…

Java中的InetAddress类

InetAddress类是Java标准库中的一个重要类&#xff0c;用于表示互联网协议&#xff08;IP&#xff09;地址。它可以表示IPv4和IPv6地址&#xff0c;提供了用于查找主机名和IP地址的静态方法&#xff0c;以及获取本地主机和远程主机的网络地址信息的功能。本文将深入探讨InetAdd…

使用clion刷leetcode

如何优雅的使用clion刷leetcode 安装插件&#xff1a;LeetCode Editor) 插件配置&#xff1a; 这样我们每打开一个项目&#xff0c;就会创建类似的文件 我们的项目结构&#xff1a; 我们在题解文件中导入头文件myHeader.h并将新建的文件添加到cmakelists.txt文件&#xff0c;…

KBPC2504-ASEMI无人机专用整流桥KBPC2504

编辑&#xff1a;ll KBPC2504-ASEMI无人机专用整流桥KBPC2504 型号&#xff1a;KBPC2504 品牌&#xff1a;ASEMI 封装&#xff1a;KBPC-4 最大重复峰值反向电压&#xff1a;400V 最大正向平均整流电流(Vdss)&#xff1a;25A 功率(Pd)&#xff1a;中小功率 芯片个数&…

枚举类 (enum)

目录 一、为什么要有枚举类&#xff1f; 二、枚举的简介 三、自定义枚举类 四、使用enum关键字 五、注意事项 一、为什么要有枚举类&#xff1f; 假如我们有这样的一个需求&#xff1a;设计季节类&#xff0c;并创建对象。 我们就需要以下操作&#xff0c;创建Season类&…

CSS学习

CSS学习 CSS&#xff08;层叠样式表&#xff09;是网页设计和开发中的重要技术&#xff0c;用于描述HTML或XML文档的样式和布局。掌握CSS不仅能让网页看起来更加美观&#xff0c;还能提高网页的加载速度和可维护性。 一、CSS基础入门 1. CSS简介 CSS是一种用于描述HTML或XM…

kafka 消费者

消费者 消费者。消费者连接到Kafka上并接收消息&#xff0c;进而进行相应的业务逻辑处理。 消费组 消费者负责订阅Kafka中的主题&#xff0c;并且从订阅的主题上拉取消息。 消费组&#xff1a;每个消费者都有一个对应的消费组&#xff0c;每一个分区只能被一个消费组中的一个…

nginx优化

编辑nginx.conf server_tokens off 关闭版本号 修改用户与组 在配置文件中将用户注释掉 表示主进程master会有root创建&#xff0c;子进程由nginx用户来创建 设置页面的缓存时间&#xff0c;主要是针对动态页面&#xff0c;图片的缓存 cd html/ 先把图片托进来 配置文件做…