import 'package:fis_jsonrpc/services/authentication.m.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flyinsonolite/controls/defaultinputdecoration.dart'; import 'package:flyinsonolite/infrastructure/scale.dart'; import 'package:flyinsonolite/jsonrpc/fisLib/services/consultation.m.dart'; import 'package:flyinsonolite/jsonrpc/fisLib/services/log.m.dart'; import 'package:flyinsonolite/jsonrpc/jsonrpcclientforFISLib.dart'; import 'package:flyinsonolite/infrastructure/logger.dart'; import 'package:flyinsonolite/infrastructure/storage.dart'; import 'package:get/get.dart'; class FISTextField extends StatelessWidget { final Key? uniqueKey; final TextEditingController? controller; final List? inputFormatters; final bool readOnly; final String? placeHolder; final ValueChanged? onChanged; final bool obscureText; final bool autofocus; final bool expands; final String errorText; final int? maxLines; final int? minLines; final TextAlignVertical? textAlignVertical; final TextInputType? keyboardType; final Widget? suffixIcon; final ValueChanged? onSubmitted; final GestureTapCallback? onTap; final TapRegionCallback? onTapOutside; final Color? fillColor; final TextStyle? textStyle; final Color? borderColor; final Color? enabledBorderColor; final bool? enabled; final EdgeInsetsGeometry? contentPadding; final String route = Get.currentRoute; FISTextField({ super.key, required this.uniqueKey, this.controller, this.inputFormatters, this.readOnly = false, this.placeHolder, this.onChanged, this.obscureText = false, this.autofocus = false, this.expands = false, this.errorText = '', this.maxLines = 1, this.minLines, this.textAlignVertical, this.keyboardType, this.suffixIcon, this.onSubmitted, this.onTap, this.onTapOutside, this.fillColor, this.textStyle, this.borderColor, this.enabledBorderColor, this.enabled, this.contentPadding, }); @override Widget build(BuildContext context) { FocusNode focusNode = FocusNode(); return TextField( key: uniqueKey, scrollPadding: EdgeInsets.all(20.0.s), cursorWidth: 2.s, cursorHeight: 25.s, enableInteractiveSelection: Storage.platform == Platform.Windows, controller: controller, inputFormatters: inputFormatters, style: textStyle ?? Storage.currentTheme.normalTextStyle.copyWith( color: Colors.black, fontSize: Storage.currentTheme.normalTextStyle.fontSize!.s), readOnly: readOnly, onChanged: onChanged, obscureText: obscureText, autofocus: autofocus, focusNode: focusNode, maxLines: maxLines, minLines: minLines, expands: expands, textAlignVertical: textAlignVertical, keyboardType: keyboardType, onSubmitted: onSubmitted, enabled: enabled, decoration: DefaultInputDecoration( placeHolder: placeHolder, errorText: errorText, suffixIcon: suffixIcon, contentPadding: contentPadding ?? EdgeInsets.fromLTRB(12.s, 0, 12.s, 0), fillColor: enabled == false ? Colors.grey : fillColor, borderColor: borderColor, enabledBorderColor: enabledBorderColor, ), onTap: onTap ?? () async { if (route != Get.currentRoute || Storage.platform == Platform.Android) { return; } Offset position = const Offset(0, 0); Size screenSize = const Size(0, 0); double controlHeight = 0; if (uniqueKey is GlobalKey) { final RenderBox renderBox = (uniqueKey as GlobalKey) .currentContext! .findRenderObject() as RenderBox; position = renderBox.localToGlobal(Offset.zero); screenSize = MediaQuery.of((uniqueKey as GlobalKey).currentContext!).size; controlHeight = renderBox.size.height; } var positionY = position.dy + controlHeight > screenSize.height ? screenSize.height : position.dy + controlHeight; if (positionY < 0) { positionY = 0; } var fiscontrolPositionInfo = FISControlPositionInfo( isShowSoftwareKeyBoard: true, screenHeight: screenSize.height, screenWidth: screenSize.width, positionX: position.dx, positionY: positionY); await operateSoftKeyBoard(fiscontrolPositionInfo); }, onTapOutside: onTapOutside ?? (e) async { if (route != Get.currentRoute) { return; } focusNode.unfocus(); if (Storage.platform == Platform.Android) { return; } var fiscontrolPositionInfo = FISControlPositionInfo( isShowSoftwareKeyBoard: false, screenHeight: 0, screenWidth: 0, positionX: 0, positionY: 0); await operateSoftKeyBoard(fiscontrolPositionInfo); }, ); } } Future operateSoftKeyBoard( FISControlPositionInfo fisControlPositionInfo) async { try { if (fisControlPositionInfo.isShowSoftwareKeyBoard || Storage.isShowSoftKeyBoard != fisControlPositionInfo .isShowSoftwareKeyBoard) //因为OnTapOutSide一个页面如果有多个TextField控件会都触发 { Storage.isShowSoftKeyBoard = fisControlPositionInfo.isShowSoftwareKeyBoard; await jsonRpcProxyForFISLib.consultation .operateSoftKeyBoard(fisControlPositionInfo); } } catch (ex) { await loggerAsyn( FISDeviceLogCategory.Error, "OperateSoftKeyBoard error: $ex"); } }