Флаттер TextField - textAlignVertical не работает - PullRequest
1 голос
/ 25 января 2020

Я использую Flutter TextField внутри пользовательского виджета, но почему-то свойство textAlignVertical не работает. Ниже приведен код для пользовательского виджета. Есть ли кто-нибудь, кто знает, откуда это поведение? Я попытался решить эту проблему, установив свойство height параметра style для TextField на 0, но это тоже не помогло.

Любая помощь очень ценится!

class CustomTextField extends StatefulWidget {
  final double width;
  final double height;
  final Color color;
  final TextEditingController controller;
  final String hintText;
  final TextStyle textStyle;
  final Icon icon;
  final String errorKey;
  final Map<String, String> errors;
  final BorderRadius borderRadius;

  CustomTextField({
    this.controller, 
    this.hintText, 
    this.textStyle,
    this.icon, 
    this.errorKey, 
    this.errors, 
    this.width,
    this.height,
    this.color,
    this.borderRadius});

  @override
  _CustomTextFieldState createState() => _CustomTextFieldState();
}

class _CustomTextFieldState extends State<CustomTextField> {
  bool showClearButton = false;
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Container(
          width: widget.width,
          height: 100,
          decoration: BoxDecoration(
            color: widget.color,
            borderRadius: widget.borderRadius
          ),
          child: Row(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(left: 10),
                child: widget.icon,
              ),
              Expanded(
                child: TextField(
                  textAlignVertical: TextAlignVertical.center,
                  controller: widget.controller,
                  decoration: InputDecoration(
                    contentPadding: EdgeInsets.only(left: 8),
                    hintText: widget.hintText,
                    border: InputBorder.none,
                  ),
                  onChanged: (value) {
                    if (widget.controller.text.isNotEmpty) {
                      setState(() { showClearButton = true; });
                    } 
                  },
                  onEditingComplete: () {
                    FocusScope.of(context).unfocus(); 
                  },
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(right: 8),
                child: (showClearButton || widget.controller.text.isNotEmpty) 
                  ? GestureDetector(
                      child: Icon(Icons.clear, color: BaseColors.orange,),
                      onTap: () { 
                        widget.controller.clear(); 
                        setState(() { showClearButton = false; });
                      }) 
                  : SizedBox(width: 0,),
              )
            ]
          )
        ),
        (widget.errors != null && widget.errors.containsKey(widget.errorKey)) 
          ? Container(
              alignment: Alignment.topLeft,
              child: Padding(padding: EdgeInsets.only(left: 10), child: Text(widget.errors[widget.errorKey], style: TextStyle(fontSize: 12)))
            )
          : SizedBox(height: 0),
        ]
    );
  }
}
...