#flutter #dart
#flutter #dart
Вопрос:
Я хотел бы показать несколько строк текста в моем DrawerHeader. Прямо сейчас я делаю это с одним фактическим текстовым виджетом, у которого есть строка для его значения, содержащая несколько значений » n», для достижения моей цели.
У меня есть следующий код:
Widget _buildDrawer() {
return ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text(
_currentUser.displayName "n" "Something 1 n" "Something 2", //Here is the problem, I would like to create a custom Text widget for each of these texts.
maxLines: 3,
style: TextStyle(
color: Colors.white
),
),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Stúdium jelentkezés'),
onTap: () {
// Update the state of the app.
// ...
// Then close the drawer.
Navigator.pop(context);
},
),
ListTile(
title: Text('Koleszhírek'),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text('Profil'),
onTap: () {
// Update the state of the app.
// ...
},
),
],
);
}
Ответ №1:
Вы можете использовать Wrap
официальный документ widget.
Wrap(
children: <Widget>[
Text(...),
Text(...),
],
)
Ответ №2:
Просто поместите столбец внутри DrawerHeader :
DrawerHeader(
child: Column(
children: <Widget>[
Text("One,"),
Text("Two,"),
Text("Three,"),
]
),
),
Ответ №3:
То, что вы делаете, неплохо. Другие ответы также являются хорошими способами достижения того же.
Но есть еще один способ получить что-то вроде этого:
Код:
UserAccountsDrawerHeader(
accountName: Text("Name"),
accountEmail: Text("Description / Mail"),
currentAccountPicture: CircleAvatar(
backgroundColor: Colors.blueGrey,
child: Image.network('link to any image')
),
// You can add some more properties
),
Надеюсь, этот ответ вам помог.