Showing
7 changed files
with
151 additions
and
37 deletions
| @@ -14,16 +14,16 @@ if (flutterRoot == null) { | @@ -14,16 +14,16 @@ if (flutterRoot == null) { | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | -def flutterVersionCode = "462" | 17 | +def flutterVersionCode = "463" |
| 18 | if (flutterVersionCode == null) { | 18 | if (flutterVersionCode == null) { |
| 19 | - flutterVersionCode = '462' | 19 | + flutterVersionCode = '463' |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | -def flutterVersionName = "4.6.2" | 24 | +def flutterVersionName = "4.6.3" |
| 25 | if (flutterVersionName == null) { | 25 | if (flutterVersionName == null) { |
| 26 | - flutterVersionName = '4.6.2' | 26 | + flutterVersionName = '4.6.3' |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | 29 |
| 1 | import 'package:cached_network_image/cached_network_image.dart'; | 1 | import 'package:cached_network_image/cached_network_image.dart'; |
| 2 | import 'package:common_utils/common_utils.dart'; | 2 | import 'package:common_utils/common_utils.dart'; |
| 3 | import 'package:flutter/material.dart'; | 3 | import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter/services.dart'; | ||
| 4 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 5 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
| 5 | import 'package:provider/provider.dart'; | 6 | import 'package:provider/provider.dart'; |
| 6 | 7 | ||
| 7 | import '../../../models/wine_manage_model.dart'; | 8 | import '../../../models/wine_manage_model.dart'; |
| 8 | import '../../../provider/upload_img_provider.dart'; | 9 | import '../../../provider/upload_img_provider.dart'; |
| 9 | import '../../../res/colors.dart'; | 10 | import '../../../res/colors.dart'; |
| 11 | +import '../../../utils/precision_limit_formatter.dart'; | ||
| 10 | import '../../../utils/screen_util.dart'; | 12 | import '../../../utils/screen_util.dart'; |
| 11 | import '../../../utils/upload_image_util.dart'; | 13 | import '../../../utils/upload_image_util.dart'; |
| 12 | import '../../../utils/utils.dart'; | 14 | import '../../../utils/utils.dart'; |
| @@ -77,6 +79,16 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | @@ -77,6 +79,16 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | ||
| 77 | alignment: Alignment.centerRight, | 79 | alignment: Alignment.centerRight, |
| 78 | child: TextField( | 80 | child: TextField( |
| 79 | maxLines: 1, | 81 | maxLines: 1, |
| 82 | + keyboardType: TextInputType.numberWithOptions( | ||
| 83 | + decimal: | ||
| 84 | + true), //由于某些机型键盘并不能做到强制故再条件上加上FilteringTextInputFormatter.allow(RegExp('[0-9.,]+') | ||
| 85 | + inputFormatters: title == '出库数量' | ||
| 86 | + ? [ | ||
| 87 | + PrecisionLimitFormatter(2), | ||
| 88 | + FilteringTextInputFormatter.allow( | ||
| 89 | + RegExp('[0-9.,]+')) | ||
| 90 | + ] | ||
| 91 | + : [], | ||
| 80 | //输入文本的样式 | 92 | //输入文本的样式 |
| 81 | style: TextStyle( | 93 | style: TextStyle( |
| 82 | fontSize: ScreenUtil().setSp(32), | 94 | fontSize: ScreenUtil().setSp(32), |
| @@ -104,15 +116,15 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | @@ -104,15 +116,15 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | ||
| 104 | onChanged: (value) { | 116 | onChanged: (value) { |
| 105 | // print(value); | 117 | // print(value); |
| 106 | if (value != null && value.trim().length > 0) { | 118 | if (value != null && value.trim().length > 0) { |
| 107 | - bool isNumber = | ||
| 108 | - Utils.isInteger(value); //判断输入的内容是否是数字 | ||
| 109 | - if (!isNumber) { | ||
| 110 | - Utils.showToast('请输入数字'); | ||
| 111 | - controller.text = ''; | ||
| 112 | - return; | ||
| 113 | - } | ||
| 114 | - if (int.parse(value) > | ||
| 115 | - int.parse( | 119 | + // bool isNumber = |
| 120 | + // Utils.isInteger(value); //判断输入的内容是否是数字 | ||
| 121 | + // if (!isNumber) { | ||
| 122 | + // Utils.showToast('请输入数字'); | ||
| 123 | + // controller.text = ''; | ||
| 124 | + // return; | ||
| 125 | + // } | ||
| 126 | + if (double.parse(value) > | ||
| 127 | + double.parse( | ||
| 116 | widget.wineManageSunModel.wineAmount)) { | 128 | widget.wineManageSunModel.wineAmount)) { |
| 117 | Utils.showToast('出库数量大于库存数量,请重新输入!'); | 129 | Utils.showToast('出库数量大于库存数量,请重新输入!'); |
| 118 | controller.text = ''; | 130 | controller.text = ''; |
| @@ -121,7 +133,6 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | @@ -121,7 +133,6 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | ||
| 121 | widget.wineManageSunModel.checkAmount = value; | 133 | widget.wineManageSunModel.checkAmount = value; |
| 122 | // controller.text = value; | 134 | // controller.text = value; |
| 123 | } | 135 | } |
| 124 | - | ||
| 125 | 136 | ||
| 126 | // if (value.trim().isEmpty || value.trim().length > 11) { | 137 | // if (value.trim().isEmpty || value.trim().length > 11) { |
| 127 | // //内容为空,或 超过11位 | 138 | // //内容为空,或 超过11位 |
| @@ -149,7 +160,6 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | @@ -149,7 +160,6 @@ class _ApplyOutStoreItemPageState extends State<ApplyOutStoreItemPage> { | ||
| 149 | // _controller.jumpTo(_controller.position.maxScrollExtent); | 160 | // _controller.jumpTo(_controller.position.maxScrollExtent); |
| 150 | // }); | 161 | // }); |
| 151 | }, | 162 | }, |
| 152 | - keyboardType: TextInputType.number, | ||
| 153 | ))), | 163 | ))), |
| 154 | // InkWell( | 164 | // InkWell( |
| 155 | // onTap: () { | 165 | // onTap: () { |
| @@ -12,6 +12,7 @@ import '../../../app.dart'; | @@ -12,6 +12,7 @@ import '../../../app.dart'; | ||
| 12 | import '../../../models/upload_img_model.dart'; | 12 | import '../../../models/upload_img_model.dart'; |
| 13 | import '../../../models/wine_manage_model.dart'; | 13 | import '../../../models/wine_manage_model.dart'; |
| 14 | import '../../../provider/store_wine_provider.dart'; | 14 | import '../../../provider/store_wine_provider.dart'; |
| 15 | +import '../../../provider/upload_img_provider.dart'; | ||
| 15 | import '../../../provider/user_model.dart'; | 16 | import '../../../provider/user_model.dart'; |
| 16 | import '../../../res/colors.dart'; | 17 | import '../../../res/colors.dart'; |
| 17 | import '../../../utils/dialog_util.dart'; | 18 | import '../../../utils/dialog_util.dart'; |
| @@ -47,6 +48,8 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | @@ -47,6 +48,8 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | ||
| 47 | String wineSerial = ''; | 48 | String wineSerial = ''; |
| 48 | int wineSerialSub = 1; | 49 | int wineSerialSub = 1; |
| 49 | 50 | ||
| 51 | + UploadImageProvider _uploadImageProvider; | ||
| 52 | + | ||
| 50 | @override | 53 | @override |
| 51 | void initState() { | 54 | void initState() { |
| 52 | // TODO: implement initState | 55 | // TODO: implement initState |
| @@ -61,6 +64,16 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | @@ -61,6 +64,16 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | ||
| 61 | wineSerial + Utils.addZeroNumberWithDouble(wineSerialSub); | 64 | wineSerial + Utils.addZeroNumberWithDouble(wineSerialSub); |
| 62 | wineManageModel.img = []; | 65 | wineManageModel.img = []; |
| 63 | dataWine.add(wineManageModel); | 66 | dataWine.add(wineManageModel); |
| 67 | + | ||
| 68 | + WidgetsBinding.instance.addPostFrameCallback((_) async { | ||
| 69 | + _getQiniuInfo(); | ||
| 70 | + }); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + ///获取七牛云token | ||
| 74 | + /// | ||
| 75 | + _getQiniuInfo() async { | ||
| 76 | + await _uploadImageProvider.getQiniuInfo(context, {}); | ||
| 64 | } | 77 | } |
| 65 | 78 | ||
| 66 | ///初始化存酒编号 | 79 | ///初始化存酒编号 |
| @@ -176,6 +189,8 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | @@ -176,6 +189,8 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | ||
| 176 | @override | 189 | @override |
| 177 | Widget build(BuildContext context) { | 190 | Widget build(BuildContext context) { |
| 178 | storeWineProvider = Provider.of<StoreWineProvider>(context, listen: true); | 191 | storeWineProvider = Provider.of<StoreWineProvider>(context, listen: true); |
| 192 | + _uploadImageProvider = | ||
| 193 | + Provider.of<UploadImageProvider>(context, listen: true); | ||
| 179 | return Scaffold( | 194 | return Scaffold( |
| 180 | appBar: SystemAppBar( | 195 | appBar: SystemAppBar( |
| 181 | '新建存酒', | 196 | '新建存酒', |
| @@ -345,6 +360,7 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | @@ -345,6 +360,7 @@ class _CreateStoreWinePageState extends State<CreateStoreWinePage> { | ||
| 345 | wineManageSunModel: wineManageModel, | 360 | wineManageSunModel: wineManageModel, |
| 346 | controller: _controller, | 361 | controller: _controller, |
| 347 | index: index, | 362 | index: index, |
| 363 | + uploadImageProvider: _uploadImageProvider, | ||
| 348 | onDel: () { | 364 | onDel: () { |
| 349 | dataWine.removeAt(index); | 365 | dataWine.removeAt(index); |
| 350 | setState(() {}); | 366 | setState(() {}); |
| @@ -7,8 +7,10 @@ import 'package:provider/provider.dart'; | @@ -7,8 +7,10 @@ import 'package:provider/provider.dart'; | ||
| 7 | import '../../../models/wine_manage_model.dart'; | 7 | import '../../../models/wine_manage_model.dart'; |
| 8 | import '../../../provider/upload_img_provider.dart'; | 8 | import '../../../provider/upload_img_provider.dart'; |
| 9 | import '../../../res/colors.dart'; | 9 | import '../../../res/colors.dart'; |
| 10 | +import '../../../utils/precision_limit_formatter.dart'; | ||
| 10 | import '../../../utils/screen_util.dart'; | 11 | import '../../../utils/screen_util.dart'; |
| 11 | import '../../../utils/upload_image_util.dart'; | 12 | import '../../../utils/upload_image_util.dart'; |
| 13 | +import '../../../utils/utils.dart'; | ||
| 12 | import '../../../widgets/MyDivider.dart'; | 14 | import '../../../widgets/MyDivider.dart'; |
| 13 | import '../../../widgets/v_empty_view.dart'; | 15 | import '../../../widgets/v_empty_view.dart'; |
| 14 | import '../../online_check/img_picker_widget.dart'; | 16 | import '../../online_check/img_picker_widget.dart'; |
| @@ -18,13 +20,15 @@ class CreateWineItemPage extends StatefulWidget { | @@ -18,13 +20,15 @@ class CreateWineItemPage extends StatefulWidget { | ||
| 18 | final ScrollController controller; | 20 | final ScrollController controller; |
| 19 | final int index; | 21 | final int index; |
| 20 | final GestureTapCallback onDel; | 22 | final GestureTapCallback onDel; |
| 23 | + final UploadImageProvider uploadImageProvider; | ||
| 21 | 24 | ||
| 22 | CreateWineItemPage( | 25 | CreateWineItemPage( |
| 23 | {Key key, | 26 | {Key key, |
| 24 | this.wineManageSunModel, | 27 | this.wineManageSunModel, |
| 25 | this.controller, | 28 | this.controller, |
| 26 | this.index, | 29 | this.index, |
| 27 | - this.onDel}) | 30 | + this.onDel, |
| 31 | + this.uploadImageProvider}) | ||
| 28 | : super(key: key); | 32 | : super(key: key); |
| 29 | 33 | ||
| 30 | @override | 34 | @override |
| @@ -62,6 +66,13 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | @@ -62,6 +66,13 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | ||
| 62 | // focusNode: _phoneNode, | 66 | // focusNode: _phoneNode, |
| 63 | textAlign: TextAlign.right, | 67 | textAlign: TextAlign.right, |
| 64 | textAlignVertical: TextAlignVertical.center, | 68 | textAlignVertical: TextAlignVertical.center, |
| 69 | + inputFormatters: title == '存酒数量' | ||
| 70 | + ? [ | ||
| 71 | + PrecisionLimitFormatter(2), | ||
| 72 | + FilteringTextInputFormatter.allow( | ||
| 73 | + RegExp('[0-9.,]+')) | ||
| 74 | + ] | ||
| 75 | + : [], | ||
| 65 | 76 | ||
| 66 | // textAlignVertical: | 77 | // textAlignVertical: |
| 67 | // TextAlignVertical.center, | 78 | // TextAlignVertical.center, |
| @@ -78,22 +89,20 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | @@ -78,22 +89,20 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | ||
| 78 | border: | 89 | border: |
| 79 | OutlineInputBorder(borderSide: BorderSide.none), | 90 | OutlineInputBorder(borderSide: BorderSide.none), |
| 80 | ), | 91 | ), |
| 92 | + | ||
| 81 | onChanged: (value) { | 93 | onChanged: (value) { |
| 82 | - print(value); | ||
| 83 | - // if (value.trim().isEmpty || value.trim().length > 11) { | ||
| 84 | - // //内容为空,或 超过11位 | ||
| 85 | - // setState(() { | ||
| 86 | - // _baseIndoProvider.userHistorys.clear(); | ||
| 87 | - // }); | ||
| 88 | - // return; | 94 | + // print(value); |
| 95 | + // if (value != null && value.trim().length > 0) { | ||
| 96 | + // bool isNumber = | ||
| 97 | + // Utils.isInteger(value); //判断输入的内容是否是数字 | ||
| 98 | + // if (!isNumber) { | ||
| 99 | + // Utils.showToast('请输入数字'); | ||
| 100 | + // controller.text = ''; | ||
| 101 | + // return; | ||
| 102 | + // } | ||
| 103 | + | ||
| 104 | + // // controller.text = value; | ||
| 89 | // } | 105 | // } |
| 90 | - // Map<String, String> params = { | ||
| 91 | - // "keywords": value.trim(), | ||
| 92 | - // "sid": Provider.of<UserModel>(context, listen: false) | ||
| 93 | - // .user | ||
| 94 | - // .sellerid, | ||
| 95 | - // }; | ||
| 96 | - // _baseIndoProvider.getUserHistorys(context, params); | ||
| 97 | }, | 106 | }, |
| 98 | onEditingComplete: () { | 107 | onEditingComplete: () { |
| 99 | // _phoneNode.unfocus(); | 108 | // _phoneNode.unfocus(); |
| @@ -150,7 +159,8 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | @@ -150,7 +159,8 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | ||
| 150 | ), | 159 | ), |
| 151 | VEmptyView(16), | 160 | VEmptyView(16), |
| 152 | _textFieldWidget('存酒数量', '点击输入数量', widget.wineManageSunModel.wineNumC, | 161 | _textFieldWidget('存酒数量', '点击输入数量', widget.wineManageSunModel.wineNumC, |
| 153 | - keyboardType: TextInputType.number), | 162 | + keyboardType: TextInputType.numberWithOptions(decimal: true)), |
| 163 | + // ,//由于某些机型键盘并不能做到强制故再条件上加上FilteringTextInputFormatter.allow(RegExp('[0-9.,]+') | ||
| 154 | VEmptyView(16), | 164 | VEmptyView(16), |
| 155 | _textFieldWidget( | 165 | _textFieldWidget( |
| 156 | '计量单位', '点击输入计量单位', widget.wineManageSunModel.wineUnitC), | 166 | '计量单位', '点击输入计量单位', widget.wineManageSunModel.wineUnitC), |
| @@ -161,7 +171,7 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | @@ -161,7 +171,7 @@ class _CreateWineItemPageState extends State<CreateWineItemPage> { | ||
| 161 | Consumer<UploadImageProvider>(builder: (context, model, _) { | 171 | Consumer<UploadImageProvider>(builder: (context, model, _) { |
| 162 | return ImgPickerWidget( | 172 | return ImgPickerWidget( |
| 163 | scrollController: widget.controller, | 173 | scrollController: widget.controller, |
| 164 | - model: model, | 174 | + model: widget.uploadImageProvider, |
| 165 | maxImageNumber: 3, | 175 | maxImageNumber: 3, |
| 166 | maxRemind: '三', | 176 | maxRemind: '三', |
| 167 | imageList: widget.wineManageSunModel.img, | 177 | imageList: widget.wineManageSunModel.img, |
| 1 | import 'dart:convert'; | 1 | import 'dart:convert'; |
| 2 | 2 | ||
| 3 | +import 'package:common_utils/common_utils.dart'; | ||
| 3 | import 'package:flutter/material.dart'; | 4 | import 'package:flutter/material.dart'; |
| 4 | import 'package:flutter_screenutil/flutter_screenutil.dart'; | 5 | import 'package:flutter_screenutil/flutter_screenutil.dart'; |
| 5 | import 'package:one_key/res/colors.dart'; | 6 | import 'package:one_key/res/colors.dart'; |
| @@ -226,7 +227,7 @@ class _SmsCodeInputPageState extends State<SmsCodeInputPage> { | @@ -226,7 +227,7 @@ class _SmsCodeInputPageState extends State<SmsCodeInputPage> { | ||
| 226 | 227 | ||
| 227 | if (element.checkAmount != null && | 228 | if (element.checkAmount != null && |
| 228 | element.checkAmount != '' && | 229 | element.checkAmount != '' && |
| 229 | - int.parse(element.checkAmount) > 0) { | 230 | + double.parse(element.checkAmount) > 0) { |
| 230 | //有输入数量 | 231 | //有输入数量 |
| 231 | WineCheckModel sunMoveModel = WineCheckModel(); | 232 | WineCheckModel sunMoveModel = WineCheckModel(); |
| 232 | sunMoveModel.wineName = element.wineName; | 233 | sunMoveModel.wineName = element.wineName; |
| @@ -258,14 +259,17 @@ class _SmsCodeInputPageState extends State<SmsCodeInputPage> { | @@ -258,14 +259,17 @@ class _SmsCodeInputPageState extends State<SmsCodeInputPage> { | ||
| 258 | if (success) { | 259 | if (success) { |
| 259 | List<Map<String, String>> data = []; | 260 | List<Map<String, String>> data = []; |
| 260 | widget.wineManageDetail.wineDataMove.forEach((element) { | 261 | widget.wineManageDetail.wineDataMove.forEach((element) { |
| 261 | - int wineStock = int.parse(element.wineAmount) - | ||
| 262 | - int.parse(element.checkAmount); | 262 | + double wineStock = double.parse(element.wineStock) - |
| 263 | + double.parse(element.checkAmount); | ||
| 264 | + String winestockStr = | ||
| 265 | + (NumUtil.getNumByValueDouble(wineStock, 2)) | ||
| 266 | + .toStringAsFixed(2); | ||
| 263 | Map<String, String> map = { | 267 | Map<String, String> map = { |
| 264 | 'wine_name': element.wineName, //酒名称 | 268 | 'wine_name': element.wineName, //酒名称 |
| 265 | 'wine_amount': element.wineAmount, //初始存酒量 | 269 | 'wine_amount': element.wineAmount, //初始存酒量 |
| 266 | 'unit': element.unit, //单位 | 270 | 'unit': element.unit, //单位 |
| 267 | 'wine_number': element.wineNumber, //存酒编号 | 271 | 'wine_number': element.wineNumber, //存酒编号 |
| 268 | - 'wine_stock': wineStock.toString(), //剩余库存, | 272 | + 'wine_stock': '${winestockStr}', //剩余库存, |
| 269 | 'cdate': element.cdate, | 273 | 'cdate': element.cdate, |
| 270 | 'img': element.img == null || element.img.length == 0 | 274 | 'img': element.img == null || element.img.length == 0 |
| 271 | ? null | 275 | ? null |
| @@ -288,7 +288,7 @@ class _WineDetailPageState extends State<WineDetailPage> { | @@ -288,7 +288,7 @@ class _WineDetailPageState extends State<WineDetailPage> { | ||
| 288 | i++) { | 288 | i++) { |
| 289 | WineManageSunMoveModel element = storeWineProvider | 289 | WineManageSunMoveModel element = storeWineProvider |
| 290 | .wineManageDetail.wineDataMove[i]; | 290 | .wineManageDetail.wineDataMove[i]; |
| 291 | - if (int.parse(element.wineStock) > 0) { | 291 | + if (double.parse(element.wineStock) > 0) { |
| 292 | can = true; | 292 | can = true; |
| 293 | break outerloop; | 293 | break outerloop; |
| 294 | } | 294 | } |
lib/utils/precision_limit_formatter.dart
0 → 100644
| 1 | +import 'package:flutter/services.dart'; | ||
| 2 | +import 'dart:math' as math; | ||
| 3 | + | ||
| 4 | +import 'package:one_key/utils/utils.dart'; | ||
| 5 | + | ||
| 6 | +class PrecisionLimitFormatter extends TextInputFormatter { | ||
| 7 | + int _scale; | ||
| 8 | + | ||
| 9 | + PrecisionLimitFormatter(this._scale); | ||
| 10 | + | ||
| 11 | + RegExp exp = RegExp(r"[0-9]"); | ||
| 12 | + static const String POINTER = "."; | ||
| 13 | + static const String DOUBLE_ZERO = "00"; | ||
| 14 | + static const String ZERO = "0"; | ||
| 15 | + | ||
| 16 | + @override | ||
| 17 | + TextEditingValue formatEditUpdate( | ||
| 18 | + TextEditingValue oldValue, TextEditingValue newValue) { | ||
| 19 | + print('oldValue:' + oldValue.text); | ||
| 20 | + print('newValue:' + newValue.text); | ||
| 21 | + if (newValue.text.startsWith('.')) { | ||
| 22 | + return TextEditingValue( | ||
| 23 | + text: '0.', selection: TextSelection.collapsed(offset: 2)); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + // if (newValue.text.startsWith(POINTER) && newValue.text.length == 1) { | ||
| 27 | + // //第一个不能输入小数点 | ||
| 28 | + // return oldValue; | ||
| 29 | + // } | ||
| 30 | + | ||
| 31 | + ///输入完全删除 | ||
| 32 | + if (newValue.text.isEmpty) { | ||
| 33 | + return TextEditingValue(); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + ///只允许输入小数 | ||
| 37 | + if (!exp.hasMatch(newValue.text)) { | ||
| 38 | + Utils.showToast('只能输入数字!'); | ||
| 39 | + return oldValue; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + if (newValue.text.startsWith(ZERO) && | ||
| 43 | + newValue.text.split("0")[1].startsWith(RegExp(r'[0-9]'))) { | ||
| 44 | + return TextEditingValue( | ||
| 45 | + text: '0', selection: TextSelection.collapsed(offset: 1)); | ||
| 46 | + | ||
| 47 | + // return newValue; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + ///包含小数点的情况 | ||
| 51 | + if (newValue.text.contains(POINTER)) { | ||
| 52 | + ///包含多个小数 | ||
| 53 | + if (newValue.text.indexOf(POINTER) != | ||
| 54 | + newValue.text.lastIndexOf(POINTER)) { | ||
| 55 | + return oldValue; | ||
| 56 | + } | ||
| 57 | + String input = newValue.text; | ||
| 58 | + int index = input.indexOf(POINTER); | ||
| 59 | + | ||
| 60 | + ///小数点后位数 | ||
| 61 | + int lengthAfterPointer = input.substring(index, input.length).length - 1; | ||
| 62 | + | ||
| 63 | + ///小数位大于精度 | ||
| 64 | + if (lengthAfterPointer > _scale) { | ||
| 65 | + return oldValue; | ||
| 66 | + } | ||
| 67 | + } else if (newValue.text.startsWith(POINTER) || | ||
| 68 | + newValue.text.startsWith(DOUBLE_ZERO)) { | ||
| 69 | + ///不包含小数点,不能以“00”开头 | ||
| 70 | + return oldValue; | ||
| 71 | + } | ||
| 72 | + return newValue; | ||
| 73 | + } | ||
| 74 | +} |
-
Please register or login to post a comment