该列表是在小部件 Flutter 的底部创建的
The list is created at the bottom of the widget Flutter
需要帮助!遇到了问题。我在父小部件的底部创建了一个 ListView。我只需要在搜索栏下方的顶部创建一个列表,以便根据标准显示所有内容。我没有使用任何对齐小部件,但列表本身等于底部边缘,不清楚是什么原因,请问如何解决这个问题?
Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: Column(
children: [
const SizedBox(height: 178),
const BackStepWidget(text: 'Select Language'),
const SizedBox(height: 30),
SizedBox(
width: size.width,
child: Card(
color: constants.Colors.greyDark,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24)),
child: Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 16, right: 20),
child: Row(
children: [
Expanded(
child: TextFormField(
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(7),
filled: true,
fillColor: constants.Colors.greyLight,
hintText: 'Search',
hintStyle:
TextStyle(color: constants.Colors.white),
prefixIcon: Icon(
Icons.search,
color: constants.Colors.white,
),
suffixIcon: Icon(Icons.keyboard_voice,
color: constants.Colors.white),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(10)),
)),
)),
const SizedBox(width: 14),
const Text('Cancel',
style: constants.Styles.smallBookTextStyleWhite)
],
),
),
// const SizedBox(height: 14),
Padding(
padding: const EdgeInsets.only(left: 16, top: 0),
child: ListView.separated(
shrinkWrap: true,
separatorBuilder: ((context, index) => Divider(
height: 1,
color: constants.Colors.white.withOpacity(0.2))),
itemCount: language.length,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.only(top: 9, bottom: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
language[index],
style: constants.Styles.smallBoldTextStyleWhite,
),
Text(
language[index],
style:
constants.Styles.smallerBookTextStyleWhite,
),
],
),
// ),
),
),
)
],
),
),
)
],
),
);
您可以尝试用 MediaQuery.removePadding
小部件包装 ListView
并在其上添加 removeTop: true
。
MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView(
// your list view code.
),
),
需要帮助!遇到了问题。我在父小部件的底部创建了一个 ListView。我只需要在搜索栏下方的顶部创建一个列表,以便根据标准显示所有内容。我没有使用任何对齐小部件,但列表本身等于底部边缘,不清楚是什么原因,请问如何解决这个问题?
Padding(
padding: const EdgeInsets.only(left: 24, right: 24),
child: Column(
children: [
const SizedBox(height: 178),
const BackStepWidget(text: 'Select Language'),
const SizedBox(height: 30),
SizedBox(
width: size.width,
child: Card(
color: constants.Colors.greyDark,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24)),
child: Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 16, right: 20),
child: Row(
children: [
Expanded(
child: TextFormField(
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(7),
filled: true,
fillColor: constants.Colors.greyLight,
hintText: 'Search',
hintStyle:
TextStyle(color: constants.Colors.white),
prefixIcon: Icon(
Icons.search,
color: constants.Colors.white,
),
suffixIcon: Icon(Icons.keyboard_voice,
color: constants.Colors.white),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(10)),
)),
)),
const SizedBox(width: 14),
const Text('Cancel',
style: constants.Styles.smallBookTextStyleWhite)
],
),
),
// const SizedBox(height: 14),
Padding(
padding: const EdgeInsets.only(left: 16, top: 0),
child: ListView.separated(
shrinkWrap: true,
separatorBuilder: ((context, index) => Divider(
height: 1,
color: constants.Colors.white.withOpacity(0.2))),
itemCount: language.length,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.only(top: 9, bottom: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
language[index],
style: constants.Styles.smallBoldTextStyleWhite,
),
Text(
language[index],
style:
constants.Styles.smallerBookTextStyleWhite,
),
],
),
// ),
),
),
)
],
),
),
)
],
),
);
您可以尝试用 MediaQuery.removePadding
小部件包装 ListView
并在其上添加 removeTop: true
。
MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView(
// your list view code.
),
),