Flutter FlatButton внутреннее пространство - PullRequest
1 голос
/ 02 мая 2020

В одном из моих приложений-флаттеров используйте FlatButton, как показано ниже

FlatButton(
   child: Text("Forgot ist ?",
       style: TextStyle(color: Color.fromRGBO(107, 106, 106, 1),fontFamily: 'ActoBook'),
       textAlign: TextAlign.left
   ),

   materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
   splashColor: Colors.transparent,  
   highlightColor: Colors.transparent,
   shape: RoundedRectangleBorder(
      borderRadius: new BorderRadius.circular(0.0),
      side: BorderSide(color: Colors.transparent),
   ),
   onPressed: (){
       Navigator.pushReplacement(context, new MaterialPageRoute( builder: (context) => LoginPage()),);
  },
)

Как сделать так, чтобы текст кнопки был выровнен по правому краю? В настоящее время он центрирован с равным пространством слева и справа.

В настоящее время отображается так

+-----------------+
|   Button Text   |
+-----------------+

Я пытаюсь сделать его похожим на

+-----------------+
|      Button Text|
+-----------------+

Ответы [ 2 ]

1 голос
/ 02 мая 2020

В настоящее время вы не можете использовать свойство Text class textAlign для решения этой проблемы, поскольку Text внутри FlatButton занимает минимальное количество места. Следовательно, это свойство ничего не будет делать. Вам нужно установить место для текстового виджета. Вот решение:

FlatButton(
          materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
          splashColor: Colors.transparent,  
          highlightColor: Colors.transparent,
          shape: RoundedRectangleBorder(
            borderRadius: new BorderRadius.circular(0.0),
            side: BorderSide(color: Colors.black),
          ),
          onPressed: (){
            Navigator.pushReplacement(context, new MaterialPageRoute( builder: (context) => LoginPage()));
          },
          child: Container(
            alignment: Alignment.centerRight,
            width: 100, // choose your width
            child: Text("Forgot ist ?",
              style: TextStyle(color: Color.fromRGBO(107, 106, 106, 1),fontFamily: 'ActoBook'),
            ),
          ),
        ),
0 голосов
/ 03 мая 2020

Это будет работать отлично, проверьте это.

FlatButton(
        padding: EdgeInsets.zero,
        color: Colors.blue,
        // wrap the text in a container and give it a specified width
        child: Container(
          width: 100,
          child: Text(
            "Forgot ist ?",
            style: TextStyle(
              color: Color.fromRGBO(107, 106, 106, 1),
              fontFamily: 'ActoBook',
            ),
            // set the alignment of the text to TextAlign.end
            textAlign: TextAlign.end,
          ),
        ),
        materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
        splashColor: Colors.transparent,
        highlightColor: Colors.transparent,
        shape: RoundedRectangleBorder(
          borderRadius: new BorderRadius.circular(0.0),
          side: BorderSide(color: Colors.transparent),
        ),
        onPressed: () {
        Navigator.pushReplacement(context, new MaterialPageRoute( builder: (context) => LoginPage()),);
        },
      )),

Этот код выше дает следующий вывод: This is the output

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...