Как настроить размер многострочного текста на основе контейнера во флаттере - PullRequest
0 голосов
/ 11 сентября 2018

если значения customeHeight и customeWidth изменяются, то дочернее значение также должно измениться.В то же время размер текста должен соответствовать размеру и высоте родительского контейнера.

fontSize должен увеличиваться и уменьшаться.

// Родительский класс

Padding(
          padding:
              EdgeInsets.only(left: 60.0, top: 60.0, right: 20.0, bottom: 20.0),
          child: Container(
              height: customeHeight,
              width: customeWidth,
              child: widget.child,
              decoration: BoxDecoration(
                border: Border.all(color: Colors.red, width: 4.0),
                borderRadius: BorderRadius.circular(2.0),
              )
              ),


    ),

===============================================================================

// дочерний класс // это вернётся как дочерний элемент к своему родителю

return LayoutBuilder(
                    builder: (BuildContext context, BoxConstraints constraints) {
                    print("container size $constraints");
                    print("no of character $noOfChar");
                    // double maxSize =
                    //     (constraints.maxWidth * constraints.maxHeight) / 3000;
                    // print("maxsize $maxSize");
                    return FittedBox(
                      fit: BoxFit.contain,
                      child: LimitedBox(
                        maxHeight: constraints.maxHeight + noOfChar,
                        maxWidth: constraints.maxWidth + noOfChar,
                        child: TextField(
                          keyboardType: TextInputType.multiline,
                          // maxLines: null,
                          onChanged: (str) {
                            setState(() {
                              noOfChar = str.length;
                            });
                          },
                          autofocus: true,
                          enabled: true,
                          // focusNode: myFocusNode,
                          textAlign: TextAlign.center,
                          style: TextStyle(
                              fontSize: 30.0,
                              color: const Color(0xFF000000),
                              fontWeight: FontWeight.bold,
                              fontStyle: FontStyle.italic,
                              fontFamily: widget.fontType),
                          decoration: new InputDecoration.collapsed(
                              hintText: widget.change),
                        ),
                      ),
                    );
                  })

1 Ответ

0 голосов
/ 11 сентября 2018

Использовать контейнер без фиксированной высоты и использовать атрибут Maxline для поддержки многострочного.

 Widget MultilineText(){
    return new Container(
      alignment: Alignment.topLeft,
      margin: const EdgeInsets.fromLTRB(16.0, 8.0, 16.0, 8.0),
      child: addTextView("Something something",15.0),
      ),
    );
  }
 Widget addTextView(String data, double fontSize){
    return  new Text(
        data,
        maxLines: 1000,
        overflow: TextOverflow.ellipsis,
        style: new TextStyle(
            color: Colors.black87,
            fontSize: fontSize,
            fontFamily: 'HelveticaNeue',
            fontWeight: FontWeight.w400
        )
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...