Flitter ListView.Builder卡小部件占据了屏幕的所有垂直空间
在Flitter ListView.Builder卡小部件占据了屏幕的所有垂直空间,listview,flutter,dart,Listview,Flutter,Dart,在ListView.Builder中的我的代码中有一个Card()小部件。那张卡占用了所有的垂直空间,留下了一些我想扔掉的空间。我希望卡片在行中最后一个元素(蓝色RaisedButton)之后结束。(设置硬编码的屏幕大小不是一个选项。)我曾尝试将行包装在Flexible()中,但这并没有解决问题 颤振医生结果: [✓] Flutter (Channel stable, v1.12.13+hotfix.7, on Mac OS X 10.15.1 19B88, locale en-LK)
ListView.Builder
中的我的代码中有一个Card()
小部件。那张卡占用了所有的垂直空间,留下了一些我想扔掉的空间。我希望卡片在行中最后一个元素(蓝色RaisedButton)之后结束。(设置硬编码的屏幕大小不是一个选项。)我曾尝试将行包装在Flexible()
中,但这并没有解决问题
颤振医生结果:
[✓] Flutter (Channel stable, v1.12.13+hotfix.7, on Mac OS X 10.15.1 19B88,
locale en-LK)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
[✓] Android Studio (version 3.5)
[✓] VS Code (version 1.42.1)
[✓] Connected device (1 available)
• No issues found!
proitzens-mini:~ proitzen$ flutter doctor -v
[✓] Flutter (Channel stable, v1.12.13+hotfix.7, on Mac OS X 10.15.1 19B88, locale en-LK)
• Flutter version 1.12.13+hotfix.7 at /Users/proitzen/Developer/flutter
• Framework revision 9f5ff2306b (4 weeks ago), 2020-01-26 22:38:26 -0800
• Engine revision a67792536c
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/proitzen/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3, Build version 11C29
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 41.0.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.42.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.1
[✓] Connected device (1 available)
• P10 • C8W7KTMJWP • android-arm64 • Android 7.1.2 (API 25)
• No issues found!
下面是Listview.builder()
方法
return ListView.builder(
itemBuilder: (BuildContext context, int index) {
if (noData) {
return _noBookingsForDay();
} else {
if (data[date] != null &&
data[date].length > 0 &&
data[date][index] != null) {
final bookingData = Booking.fromJson(data[date][index]);
return Container(
margin: EdgeInsets.only(left: 35.0,top: 5.0,bottom: 5.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(15.0)),
),
elevation: 15.0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
FractionalTranslation(
translation: Offset(-0.4, 0.0),
child: Align(
child: CircleAvatar(
backgroundImage: NetworkImage(
bookingData.childPicUrl),
radius: 40.0,
),
alignment:
FractionalOffset(0.5, 0.0),
),
),
SizedBox(width: 5.0),
Text(bookingData.room,
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold)),
SizedBox(width: 30.0),
GestureDetector(
child: RaisedButton(
color: Colors.blue,
onPressed: _showChangeSchdl,
child: Text(
"09:00 a.m - 18:00 p.m",
style: TextStyle(
fontSize: 16.0,
color: Colors.white,))),
),
SizedBox(width: 10.0),
],
)),
);
} else {
return Center(child: Text("No data found!"));
}
}
},
itemCount: (noData == false && data[date] != null)
? data[date].length
: 0,
);
返回ListView.builder(
itemBuilder:(构建上下文,int索引){
if(noData){
返回_noBookingsForDay();
}否则{
如果(数据[日期]!=null&&
数据[日期]。长度>0&&
数据[日期][索引]!=null){
final bookingData=Booking.fromJson(数据[日期][索引]);
返回容器(
边距:仅限边集(左:35.0,顶部:5.0,底部:5.0),
孩子:卡片(
形状:圆形矩形边框(
边界半径:
边界半径所有(半径圆形(15.0)),
),
标高:15.0,
孩子:排(
mainAxisSize:mainAxisSize.min,
儿童:[
分馏翻译(
平移:偏移量(-0.4,0.0),
子对象:对齐(
孩子:圆环星(
背景图片:NetworkImage(
bookingData.childPicUrl),
半径:40.0,
),
对齐:
分数偏移(0.5,0.0),
),
),
尺寸箱(宽度:5.0),
文本(bookingData.room、,
样式:TextStyle(
字体大小:16.0,
fontWeight:fontWeight.bold),
尺寸箱(宽度:30.0),
手势检测器(
孩子:升起按钮(
颜色:颜色,蓝色,
按下按钮:_showChangeSchdl,
子:文本(
“上午09:00-下午18:00”,
样式:TextStyle(
字体大小:16.0,
颜色:颜色。白色,),
),
尺寸箱(宽度:10.0),
],
)),
);
}否则{
返回中心(子项:文本(“未找到数据!”);
}
}
},
itemCount:(noData==false&&data[date]!=null)
?数据[日期].长度
: 0,
);
只需将您的
容器
包装在Align()中
为包装
卡的容器
小部件指定高度
属性。
return Align(
alignment: Alignment.centerLeft,
child: Container() // your container with the Card
);