如何将属性应用到Flutter工程中的导入库

92vpleto  于 2023-01-14  发布在  Flutter
关注(0)|答案(1)|浏览(125)

我是flutter的新手,我正在尝试向刚从pub.dev导入的库添加一些属性。
该库是以下存储库中的“flutter_input_field.dart”:https://github.com/SatishKumarRaizada/fancy_textfield/blob/master/lib/src/flutter_form_field.dart
在添加InputDecoration“(focusedBorder:大纲输入边框(边框侧:边框(颜色:borderColor)”属性,然后我得到一个错误:“无法将参数类型”InputDecoration“赋给参数类型”Color““

这就是密码

FlutterInputField(
              borderColor: InputDecoration(focusedBorder: OutlineInputBorder(
                borderSide: BorderSide(
                    color: borderColor),
              )),
              hintText: 'Enter 1st Flour Quantity',
              labelText: 'Flour Quantity',
              textFieldController: _textEditingController,
              filledColor: Colors.grey.shade200,
              onChange: (String st) {},
              prefixWidget: const Icon(Icons.fastfood),
              onDone: () {
              },
            ),
xuo3flqw

xuo3flqw1#

import 'package:flutter/material.dart';

class FlutterInputField extends StatelessWidget {
  final String hintText;
  final String labelText;
  final Function onChange;
  final Function onDone;
  final Widget? prefixWidget;
  final Widget? suffixWidget;
  final Color borderColor;
  final Color focusColor;
  final Color cursorColor;
  final TextEditingController? textFieldController;
  final Function? suffixTap;
  final Function? validateTextField;
  final Color? filledColor;
  final bool isSecure;
  final int lineHeight;
  final double labelFontSize;
  final double hintFontSize;

  const FlutterInputField(
      {Key? key,
      required this.hintText,
      required this.labelText,
      required this.onChange,
      required this.onDone,
      this.prefixWidget,
      this.suffixWidget,
      this.borderColor = Colors.blue,
      this.textFieldController,
      this.suffixTap,
      this.validateTextField,
      this.filledColor = Colors.lightBlue,
      this.isSecure = false,
      this.lineHeight = 1,
      this.labelFontSize = 16,
      this.hintFontSize = 16,
      this.focusColor = Colors.blue,
      this.cursorColor = Colors.blue})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(labelText),
        const SizedBox(height: 10),
        TextFormField(
          cursorColor: cursorColor,
          controller: textFieldController,
          obscureText: isSecure,
          maxLines: lineHeight,
          decoration: InputDecoration(
            focusColor: Colors.blue,
            contentPadding: const EdgeInsets.symmetric(
              horizontal: 10,
              vertical: 15,
            ),
            errorStyle: const TextStyle(
              fontSize: 16,
            ),
            filled: true,
            fillColor: filledColor,
            hintText: hintText,
            prefixIcon: prefixWidget,
            suffixIcon: suffixWidget,
            labelStyle: TextStyle(
              fontSize: labelFontSize,
            ),
            hintStyle: TextStyle(
              fontSize: hintFontSize,
            ),
            border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(8.0),
              borderSide: const BorderSide(
                width: 0,
                style: BorderStyle.none,
              ),
            ),
            focusedBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(8.0),
              borderSide: BorderSide(
                width: 0.5,
                style: BorderStyle.solid,
                color: focusColor,
              ),
            ),
          ),
          onChanged: (String str) {
            onChange(str);
          },
          validator: (String? value) {
            return validateTextField!(value);
          },
          onEditingComplete: () {
            onDone();
          },
        ),
      ],
    );
  }
}

将此文本字段添加到项目并调用它
Flutter 输入字段(边框颜色:颜色:白色,焦点颜色:Colors.green,提示文本:“输入第一次面粉量”,标签文本:“面粉量”,文本字段控制器:文本编辑控制器(),填充颜色:颜色.灰色.阴影200,更改时:(字符串st){},前缀小部件:常量图标(快餐图标,颜色:Colors.green,),光标颜色:绿色,打开完成:(){},),
我只是简单地添加了一个变量focuscolor并在构造函数中调用它,然后从我想调用它的地方分配颜色,注意如果你想borderColor和focusColor相同,你不需要这样做给予
边框颜色:Colors.black

相关问题