- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在设计一个 View ,用于根据 Firestore 数据创建一组用户。我想要一个像 whatsapp 类型的 View 创建一个组设计。下面是我的代码:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.deepOrange,
titleSpacing: 0.0,
centerTitle: true,
automaticallyImplyLeading: true,
leading: _isSearching ? const BackButton() : Container(),
title: _isSearching ? _buildSearchField() : Text("Create Group"),
actions: _buildActions(),
),
body: _buildGroupWidget(),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.deepOrange,
elevation: 5.0,
onPressed: () {
// create a group
createGroup();
},
child: Icon(
Icons.send,
color: Colors.white,
),
),
);
}
Widget _buildGroupWidget() {
return SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
selectedUserList != null && selectedUserList.length > 0
? Container(
height: 90.0,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: selectedUserList.length,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
selectedUserList.removeAt(index);
setState(() {});
},
child: Container(
margin: EdgeInsets.only(
left: 10.0, right: 10.0, top: 10.0, bottom: 10.0),
child: Column(
children: <Widget>[
Container(
height: 50.0,
width: 50.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
// color: Colors.primaries[Random().nextInt(Colors.primaries.length)],
color: Colors.primaries[
index % Colors.primaries.length],
),
),
Container(
height: 20.0,
width: 50.0,
child: Center(
child: Text(
selectedUserList[index].userName,
softWrap: true,
overflow: TextOverflow.ellipsis,
),
),
),
],
),
),
);
},
),
)
: Container(),
Container(
alignment: Alignment.centerLeft,
height: 30,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.deepOrange,
boxShadow: [
BoxShadow(
color: Colors.orange, blurRadius: 5, offset: Offset(0, 2)),
],
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Text(
"Contacts",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
),
userList != null && userList.length > 0
? ListView.builder(
shrinkWrap: true,
itemCount: userList.length,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return ListTile(
onTap: () {
if (selectedUserList.contains(userList[index])) {
selectedUserList.remove(userList[index]);
} else {
selectedUserList.add(userList[index]);
}
setState(() {});
},
title: Text(userList[index].userName),
subtitle: Text(userList[index].userContact),
leading: CircleAvatar(
backgroundColor: Colors.primaries[index],
),
);
},
)
: Center(
child: Text("Data Unavailable!!",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w500,
color: Colors.blueGrey)))
],
),
);
}
我的代码的问题是我想将我的最后一个小部件居中,该小部件是中心小部件,当没有数据时可以看到。我想将它设置到屏幕中央。
但是,它没有到达屏幕的中心。
我已经尝试过 Expanded、Flex 和其他引用资源中的其他解决方案。但是,它对我不起作用。
谁能建议我如何将我的最后一个小部件居中?
最佳答案
我认为扩展应该可以包装您的最后一个小部件。
不过,如果它对您不起作用,那么您可以从全屏中删除其他 2 个小部件的高度,因为您的两个小部件都具有静态高度,此处总高度为 120。
Container(
width: double.infinity,
height: MediaQuery.of(context).size.height - 120,
child: Center(
child: Text("Data Unavailable!!",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w500,
color: Colors.blueGrey)),
))
这将解决您的问题。
关于android - 如何将包含在 Singlechildscrollview 中的列中的 Widget 居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58534231/
我有一个父 SCS View (SingleChildScrollView)和一个子 SCS View 。在子 SCS View 中有一个数据表,数据表从屏幕底部的四分之一处开始。 现在,当用户滚动到
你们如何解决以下 Flutter 布局? 我有一个屏幕,我必须在其中显示,如图所示:一个 Logo + 3 个 TextFormFields + 2 个按钮 + 一个容器。 问题: 我需要将所有小部件
如何滚动 SingleChildScrollView以编程方式? 在长表单上,需要自动滚动到需要的输入字段。 最佳答案 有多种解决方案: 使用 ScrollController : 分配给 contr
我正在尝试归档类似于图像的布局,其中有一个顶部固定区域(红色)和一个可滚动区域(黄色),顶部有一些文本字段(文本 1、文本 2)和一个终端元素在可滚动区域的底部 (* Bottom Text)。我试着
我有一个 SingleChildScrollView,里面有一个 Container。我想要实现的是 Container 的 高度应该是一个完整的视口(viewport)高度。 我的代码: class
我在 flutter 方面遇到问题。我的屏幕没有滚动。我有几个组件使用 Column 功能将它们放在一个下方,但简单的滚动功能不起作用。 这是我的代码 Widget buildContent() {
我试图在用 singlechildscrollview 包裹的列中使用间隔器,它给了我一个错误。 RenderFlex children have non-zero flex but incoming
我尝试使用 ReorderableListView内SingleChildScrollView ,但我收到一个错误: I/flutter ( 9049): ══╡ EXCEPTION CAUGHT B
我不知道如何在 Flutter 中进行这种布局。我想要实现的是: 我有一列,包含一个固定高度的子项(标题文本小部件)和两个扩展小部件。我正在使用扩展,因为我希望每个人共享剩余屏幕的一半。 当方向更改为
是否可以检查 SingleChildScrollView 是否适合屏幕以便不需要滚动? 我想根据这些信息实现不同的行为。 提前感谢大家。 最佳答案 我遇到了同样的问题,并找到了解决方法。以下是我的制作
在我的 flutter 应用程序中,我需要一个布局,如果所有小部件对于屏幕而言都太长,我可以在其中滚动,因此我添加了一个 SingleChildScrollView。但是,如果小部件较小并且留有很多空
在我的 flutter 应用程序中,我需要一个布局,如果所有小部件对于屏幕而言都太长,我可以在其中滚动,因此我添加了一个 SingleChildScrollView。但是,如果小部件较小并且留有很多空
我有一个由列组成的布局,其中一个元素是一行(以便它占据屏幕的整个宽度)。在该行中,我有一个换行符,其内容相当大,我想将其放入 SingleChildScrollView 中。 @override
我正在尝试创建一个其中包含一列的 SingleChildScrollView,我希望在屏幕的最底部有一个按钮。为此,我尝试使用带有 SingleChildScrollView 和 FlatButton
这是我正在开发的登录页面的屏幕: https://ibb.co/X22g4rc 当键盘出现时,它告诉我有溢出,这似乎是正常的: https://ibb.co/mzVLJ4f 在网络上进行一些研究后,我
@override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color(0xff003859)
我的多行 TextField 需要一个滚动位置指示器,它被包裹在 SingleChildScrollView 中。 文本字段中的文本比可见的多,我看不出隐藏了一些文本及其隐藏位置(顶部或底部) 这是
我正在开发一个应用程序,并正在关注此 link 中的示例并遇到了一个问题,它说底部溢出 xx 像素,如下所示: 现在,我以前遇到过这个问题,通过添加 SingleChildScrollView 解决了
我正在使用 SingleChildScrollView,当点击其中的 FormTextField 时,键盘出现并且 ScrollView 向上滚动。关闭键盘后,我仍然可以手动滚动 Scrollview
每次我打开键盘时,图像都会根据键盘上方的屏幕尺寸进行缩放,而不是在设备的整个屏幕上。我的代码如下,请问如何解决?因为如果我不放置 SingleChieldScrollView,它将显示黄色像素警报横幅
我是一名优秀的程序员,十分优秀!