123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import 'package:fis_jsonrpc/services/authentication.m.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flyinsonolite/controls/custom/customiconbutton.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 SearchTextField extends StatelessWidget {
- final VoidCallback? onPressed;
- final Key? uniqueKey;
- final TextEditingController? controller;
- final List<TextInputFormatter>? inputFormatters;
- final String? placeHolder;
- final ValueChanged<String>? onChanged;
- final bool obscureText;
- final bool autoFfocus;
- final bool expands;
- final String errorText;
- final TextStyle? textStyle;
- final int? maxLines;
- final int? minLines;
- final TextAlignVertical? textAlignVertical;
- final GestureTapCallback? onTap;
- final TapRegionCallback? onTapOutside;
- final TextInputType? keyboardType;
- final String route = Get.currentRoute;
- SearchTextField(this.onPressed,
- {super.key,
- required this.uniqueKey,
- this.controller,
- this.inputFormatters,
- this.placeHolder,
- this.onChanged,
- this.obscureText = false,
- this.autoFfocus = false,
- this.expands = false,
- this.errorText = '',
- this.maxLines = 1,
- this.minLines,
- this.textAlignVertical,
- this.textStyle,
- this.onTap,
- this.onTapOutside,
- this.keyboardType});
- @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 ??
- TextStyle(
- color: const Color.fromARGB(255, 96, 98, 102),
- fontSize: Storage.currentTheme.normalTextStyle.fontSize!.s),
- onChanged: onChanged,
- obscureText: obscureText,
- autofocus: autoFfocus,
- maxLines: maxLines,
- minLines: minLines,
- expands: expands,
- textAlignVertical: textAlignVertical,
- focusNode: focusNode,
- 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);
- },
- keyboardType: keyboardType,
- decoration: DefaultInputDecoration(
- placeHolder: placeHolder,
- errorText: errorText,
- suffixIcon: CustomIconButton(
- padding: const EdgeInsets.all(0),
- onPressed: onPressed,
- constraints: const BoxConstraints(),
- icon: Icon(Icons.search, size: 24.s),
- alignment: Alignment.center),
- ));
- }
- 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");
- }
- }
- }
|