J'utilise deux widgets (texte et plat plat) dans la ligne. Tout ce que je fais, il y a de l'espace entre eux. Je ne veux pas d'espace entre eux comment faire ça? Je veux comme ceci: Vous avez déjà un compte? Connexion P> P>
3 Réponses :
Si vous souhaitez créer un texte simple comme celui-ci, n'utilisez pas la ligne ou le bouton plat. Utilisez un texte riche à la place.
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
},
),
],
),
),
),
),
);
}
}
Vous obtenez l'espace parce que vous utilisez un Flatbutton CODE> et Flatbutton CODE> S possède un rembourrage par défaut. Vous devez utiliser un gesturétector code> à la place. 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,
),
),
),
],
),
),
),
);
}
}
J'ai essayé votre code et dans des coutures, l'espace n'est pas entre les composants, mais c'est le rembourrage du plat-flitton. Pour supprimer cela, vous aurez une autre composante au lieu d'un bouton plat. Essayez le ci-dessous
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,
// ),
],
),
),
),
);
}
}
Pouvez-vous partager une capture d'écran et du code s'il vous plaît?
Posté une réponse pour vous. Jetez un coup d'oeil