Убрать пробел между виджетами в строке - Flutter - PullRequest
0 голосов
/ 21 июня 2020

Я использую два виджета (Text и Flatbutton) в строке. Что бы я ни делал, между ними есть пространство. Я не хочу пробелов между ними, как это сделать?

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
  home: Scaffold(
    appBar: AppBar(
      title: Text("TextColor checking"),
    ),
    body:
Row(mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
             Text("Already have a account?"),
               FlatButton(
                  onPressed: () {},
                  child: Text("Login"),
                  textColor: Colors.indigo,
                ),


          ],
        ),
       ),
    );
  }
}

Я хочу вот так: Уже есть учетная запись? Логин

Ответы [ 3 ]

0 голосов
/ 21 июня 2020

Вы получаете пространство, потому что вы используете FlatButton, а FlatButton s имеет отступы по умолчанию. Вместо этого вы должны использовать GestureDetector.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("TextColor checking"),
        ),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("Already have a account? "),
              GestureDetector(
                onTap: () {},
                child: Text(
                  "Login",
                  style: TextStyle(
                    color: Colors.indigo,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0 голосов
/ 21 июня 2020

Я пробовал ваш код, и в швах пространство не между компонентами, а заполнение FlatButton. чтобы удалить это, вам придется использовать другой компонент вместо Flat Button. попробуйте следующее

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("TextColor checking"),
        ),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("Already have a account?"),
              RawMaterialButton(
                  constraints: BoxConstraints(),
                  padding: EdgeInsets.all(
                      5.0), // optional, in order to add additional space around text     if needed
                  child: Text('Login'),
                  onPressed: () {})
//               FlatButton(
//                 onPressed: () {},
//                 child: Text("Login"),
//                 textColor: Colors.indigo,
//               ),
            ],
          ),
        ),
      ),
    );
  }
}
0 голосов
/ 21 июня 2020

Если вы хотите создать такой простой текст, не используйте кнопку строки или плоскую кнопку. Вместо этого используйте форматированный текст.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("TextColor checking"),
        ),
        body: Padding(
          padding: const EdgeInsets.all(8.0),
          child: RichText(
            text: TextSpan(
              style: TextStyle(fontSize: 16, color: Colors.white),
              children: <TextSpan>[
                TextSpan(
                  text: "Don't have an account? ",
                ),
                TextSpan(
                  text: "Login",
                  style: TextStyle(
                    //Add any decorations here
                    color: Colors.indigo,
                    decoration: TextDecoration.underline,
                  ),
                  recognizer: TapGestureRecognizer()
                    ..onTap = () {
                      //Enter the function here
                    },
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
...