#flutter #dart
#flutter #dart
Вопрос:
Я новичок в flutter. Я хочу установить текст / метку над кнопками. Я не нашел ни одного простого текстового или меточного виджета во flutter.
Текст должен быть очень большим (изображение) и справа от экрана, и я хочу сохранить положение кнопок. Как я могу добиться этого с помощью Flutter?
Спасибо за вашу помощь.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Padding(
padding: const EdgeInsets.only(top: 375.0),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("1"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("2"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("3"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text(" "),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("4"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("5"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("6"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("-"),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("7"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("8"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("9"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("*"),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 80,
width: 290,
child: FloatingActionButton.extended(
elevation: 0.2,
onPressed: () {},
label: Text("="),
isExtended: true,
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("/"),
),
)
],
),
],
),
),
),
);
}
}
Комментарии:
1. оберните его с помощью Center()
Ответ №1:
Используйте расширенный :
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text(
"My Text",
textAlign: TextAlign.right,
style: TextStyle(fontSize: 68),
),
),
),
Полный код:
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Column(
children: <Widget>[
SizedBox(height: 24,),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Text(
"My Text",
textAlign: TextAlign.right,
style: TextStyle(fontSize: 68),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("1"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("2"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("3"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text(" "),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("4"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("5"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("6"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("-"),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("7"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("8"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("9"),
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("*"),
),
),
],
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 80,
width: 290,
child: FloatingActionButton.extended(
elevation: 0.2,
onPressed: () {},
label: Text("="),
isExtended: true,
),
),
SizedBox(
height: 100,
width: 90,
child: FloatingActionButton(
elevation: 0.2,
onPressed: () {},
child: Text("/"),
),
)
],
),
],
),
),
);
}
Ответ №2:
Вы можете использовать:
Center(
child: Text(
"Your text goes here",
style: TextStyle(
fontSize: 30.0
),
),
),