import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import '../../common/util/MyUtils.dart';

class SearchWidget extends GetView {
  final String? keyword;
  final Color? color;
  String? hint;
  Function? onChange;
  Function? findCallback;

  SearchWidget(
      {required this.keyword,
      required this.color,
      this.hint = "请输入关键字",
      this.findCallback,
      this.onChange});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 0),
      child: Container(
        width: double.infinity,
        decoration: BoxDecoration(
          color: themeController.currentColor.sc3,
          borderRadius: BorderRadius.circular(16.rpx),
        ),
        child: Padding(
          padding: EdgeInsetsDirectional.fromSTEB(35.rpx, 0, 35.rpx, 0),
          child: Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Expanded(
                child: Row(
                  mainAxisSize: MainAxisSize.max,
                  children: [
                    Container(
                      width: 25.rpx,
                      height: 25.rpx,
                      // width: double.infinity,
                      decoration: BoxDecoration(),
                      child: SvgPicture.asset(
                        'assets/img/icon/query.svg',
                        fit: BoxFit.cover,
                        color: stringToColor("#333333"), //固定
                      ),
                    ),
                    Expanded(
                      child: Container(
                        width: 100.rpx,
                        height: 60.rpx,
                        decoration: BoxDecoration(
                          color: Colors.white,
                        ),
                        child: Align(
                          alignment: AlignmentDirectional(-1, 0),
                          child: TextFormField(
                            autofocus: false,
                            obscureText: false,
                            decoration: InputDecoration(
                              isDense: true,
                              labelStyle: TextStyle(
                                fontFamily: 'Inter',
                                fontSize: 26.rpx,
                                letterSpacing: 0.0,
                              ),
                              hintText: hint,
                              hintStyle: TextStyle(
                                  fontFamily: 'Inter',
                                  fontSize: 26.rpx,
                                  letterSpacing: 0.0,
                                  color: Color(0XFFC8CBD2)),
                              enabledBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  color: Color(0x00000000),
                                  width: 1.rpx,
                                ),
                                borderRadius: BorderRadius.circular(8.rpx),
                              ),
                              focusedBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  color: Color(0x00000000),
                                  width: 1.rpx,
                                ),
                                borderRadius: BorderRadius.circular(8.rpx),
                              ),
                              errorBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  width: 1.rpx,
                                ),
                                borderRadius: BorderRadius.circular(8.rpx),
                              ),
                              focusedErrorBorder: OutlineInputBorder(
                                borderSide: BorderSide(
                                  width: 1.rpx,
                                ),
                                borderRadius: BorderRadius.circular(8.rpx),
                              ),
                              filled: false,
                              fillColor: themeController.currentColor.sc22,
                              contentPadding: EdgeInsets.symmetric(
                                  vertical: 12.rpx, horizontal: 12.rpx), // 关键设置
                            ),
                            style: TextStyle(
                              fontFamily: 'Inter',
                              fontSize: 26.rpx,
                              color: Colors.black,
                              letterSpacing: 0.0,
                            ),
                            // cursorColor:
                            //     FlutterFlowTheme.of(context).primaryText,
                            // validator: _model
                            //     .textControllerValidator
                            //     .asValidator(context),
                            onChanged: (d) {
                              onChange?.call(d);
                            },
                          ),
                        ),
                      ),
                    ),
                  ].divide(SizedBox(width: 6.rpx)),
                ),
              ),
              Padding(
                  padding: EdgeInsetsDirectional.fromSTEB(26.rpx, 0, 0, 0),
                  child: InkWell(
                    onTap: () {
                      findCallback?.call();
                    },
                    child: Row(
                      mainAxisSize: MainAxisSize.max,
                      children: [
                        SizedBox(
                          height: 30.rpx,
                          child: VerticalDivider(
                            thickness: 2.rpx,
                            color: stringToColor("#333333"), //固定
                          ),
                        ),
                        Text(
                          '搜索'.tr,
                          style: TextStyle(
                            fontFamily: 'Inter',
                            fontSize: 30.rpx,
                            letterSpacing: 0.0,
                            color: stringToColor("#333333"), //固定
                          ),
                        ),
                      ].divide(SizedBox(width: 26.rpx)),
                    ),
                  )),
            ],
          ),
        ),
      ),
    );
  }
}
