建议将Expanded组件放在SizedBox组件里面,这样可以限制Column组件的大小,避免溢出。同时,可以将Text组件的宽度设置为固定值,避免因为文本过长导致溢出。例如:

Container( alignment: Alignment.topCenter, child: SizedBox( height: double.infinity, width: double.infinity, child: Card( margin: EdgeInsets.only(left: 30, top: 20, right: 30, bottom: 50), child: Form( key: _formKey, child: Container( padding: EdgeInsets.all(10), child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text('手机号', style: TextStyle(fontSize: 16)), ), SizedBox( width: 200, child: TextFormField( keyboardType: TextInputType.number, onSaved: (value) { _param['call_phone'] = value; }, ), ), ], ), SizedBox(height: 15), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text('查询备注', style: TextStyle(fontSize: 16)), ), SizedBox( width: 200, child: TextFormField( keyboardType: TextInputType.text, validator: (v) { return v!.trim().length > 0 ? null : "查询备注不能为空"; }, onSaved: (value) { _param['remark'] = value; }, ), ), ], ), SizedBox(height: 25), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ TextButton( onPressed: () { _showDatePicker(); }, child: Text('选择时间', style: TextStyle(fontSize: 16)), ), Text(_param['call_date_start'] ?? '', style: TextStyle(fontSize: 16)), ], ), SizedBox(height: 20), SizedBox( height: 50, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ TextButton( onPressed: () async { FilePickerResult? result = await FilePicker.platform.pickFiles( dialogTitle: "选择录音", type: FileType.audio, ); if (result != null) { PlatformFile file = result.files.single; path = file.name + ':' + file.size.toString(); setState(() {}); } else { // User canceled the picker } }, child: Text("选择录音信息", style: TextStyle(fontSize: 16)), ), Expanded( child: Text( '$path', maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: 16), ), ), ], ), ), SizedBox(height: 15), ElevatedButton( onPressed: () { FormState _form = _formKey.currentState as FormState; _form.save(); if (_form.validate()) { _param['user_name'] = Global.profile.user?.name; print(_param); if (_param['call_date_start'] == null) { EasyLoading.showError('请选择时间'); return; } if (_param['file'] == null) { EasyLoading.showError('请选择文件'); return; } if (_param['user_name'] == null) { EasyLoading.showError('用户名为空,请重新登录'); return; } // 请求接口 } }, child: Text('上传录音', style: TextStyle(fontSize: 16)), ) ], ), ), ), ), ), )

flutter的代码text组件溢出异常修复建议Container alignment AlignmenttopCenter child SizedBox height doubleinfinity width doubleinfinity child Card margin EdgeInset

原文地址: https://www.cveoy.top/t/topic/bsiH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录