我正在尝试创建一个中心文本具有最大大小的行,如果文本内容太大,则它适合大小.
我插入TextOverflow.ellipsis属性来缩短文本并插入三点...但它不起作用.
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) => new Scaffold(
appBar: new AppBar(
backgroundColor: new Color(0xFF26C6DA),
),
body: new ListView (
children: <Widget>[
new Card(
child: new Container(
padding: new EdgeInsets.symmetric(horizontal: 16.0, vertical: 18.0),
child: new Row(
children: <Widget>[
new Container(
padding: new EdgeInsets.only(right: …Run Code Online (Sandbox Code Playgroud) 我有一个我希望在Flutter中作为下拉列表实现的位置列表.我对这门语言很陌生.这就是我所做的.
new DropdownButton(
value: _selectedLocation,
onChanged: (String newValue) {
setState(() {
_selectedLocation = newValue;
});
},
items: _locations.map((String location) {
return new DropdownMenuItem<String>(
child: new Text(location),
);
}).toList(),
Run Code Online (Sandbox Code Playgroud)
这是我的项目清单:
List<String> _locations = ['A', 'B', 'C', 'D'];
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
Another exception was thrown: 'package:flutter/src/material/dropdown.dart': Failed assertion: line 468 pos 15: 'value == null || items.where((DropdownMenuItem<T> item) => item.value == value).length == 1': is not true.
Run Code Online (Sandbox Code Playgroud)
我假设值为_selectedLocationnull.但我正在初始化它.
String _selectedLocation = 'Please choose a location';
我想要实现的是在固定高度的列中有一个文本小部件。当文本很长时,我希望overflow设置为TextOverflow.ellipsis启动的属性。文本小部件将其maxLines属性设置为高值以允许其自动换行。但是该列中还有其他小部件,无论是在文本小部件之前还是之后。文本小部件位于扩展小部件中,因此它在列中占据尽可能多的空间。完整代码粘贴在下面。
此设置的问题在于文本溢出其容器父级。我在容器上有一个边框装饰,显示了这种情况。为什么会发生这种情况,我该如何解决。
import 'package:flutter/material.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Overflow"),
),
body: Center(
child: Container(
width: 200.0,
height: 250.0,
child: Card(
child: Column(children: <Widget>[
Image.asset(
"assets/bereket.jpg",
width: double.infinity,
fit: BoxFit.cover,
),
Expanded(
child: Container(
padding: EdgeInsets.all(8.0),
child: (Column(
children: [
Text(
"???? ????? «???? ?? ???? ???? ???????! ???? ???? ????»",
maxLines: 2,
style: Theme.of(context)
.primaryTextTheme
.subhead …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个“事件”小部件,该小部件由排列在列中的两个文本小部件组成。事件小部件的宽度由第一个文本小部件(标题)确定。第二个文本(详细信息)应受标题宽度的限制并换行到下一行。这就是我想要的: https: //i.stack.imgur.com/0bbNr.png
我尝试过这种布局,但列的宽度设置为详细文本的宽度(最大的子项)
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text("Title"),
Text("Some longer text that should wrap")
]
)
Run Code Online (Sandbox Code Playgroud) 我有一个RenderFlex overflowed by 72 pixels on the right issue
当用户有很长的文本时,由第一个 Text() 小部件引起。我什至尝试使用 Textoverflow,但这也没有任何作用。
因此,我尝试按照此处建议的Flutter-wrapper text使用 Flex 来包装它,但它不起作用。知道我做错了什么吗?
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.p.description,
style: TextStyle(
fontWeight: FontWeight.w800,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 4.0),
Row(
children: [
Text(
timeago.format(widget.p.timestamp.toDate()),
style: TextStyle(),
),
SizedBox(width: 3.0),
StreamBuilder(
stream: lRef
.where('pId', isEqualTo: widget.p.pId)
.snapshots(),
builder:
(context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
QuerySnapshot snap = snapshot.data;
List<DocumentSnapshot> docs = snap.docs;
return buildCount(context, docs?.length ?? 0);
} else { …Run Code Online (Sandbox Code Playgroud) 所以,目标很简单,将一堆文本包装在一个容器中。\n为此,我遵循了Flutter 包装文本,但是创建的新行与前一行之间的空间太大。
\n我的 Container() 和 Text() 代码:
\n description == ""\n ? SizedBox.shrink()\n : Container(\n padding: const EdgeInsets.symmetric(horizontal: 10.0),\n //width: MediaQuery.of(context).size.width * 0.8,\n child: Column(\n mainAxisAlignment: MainAxisAlignment.start,\n children: [\n new Text(\n description,\n textAlign: TextAlign.left,\n style: TextStyle(fontSize: 18),\n ),\n ],\n ),\n )\nRun Code Online (Sandbox Code Playgroud)\n小提示:如果对父小部件有任何描述,我只是使用 SizeBox.shrink() 作为“空小部件”。
\n当前情况如何,空间太大:
\n\n应该如何:
\n\n我知道 1\xc2\xba 图像更大,但这不是行间距更大的原因
\n我正在为我的应用程序创建一个通知中心,它包含一些标题和正文的长字符串,它总是导致溢出,我尝试使用扩展小部件,以及以下堆栈溢出问题:问题 1 ,问题 2但我不能将它应用到我的代码中,现在它是这样的:
我从我的 firebase cloud firestore 获取文本,并使用列表视图输出文本。
该标题文字是这样的:“艾伦Indefenzo已取消同意您访问他/她的数据”
的正文是这样的:“他/她已经删除了所有的访问,您将不再能够查看/修改他的数据,再次访问要求用户再次向您提供他/她的特殊代码。”
这是我的代码:
Container(
color: Colors.white,
child: StreamBuilder(
stream: db
.collection('users')
.document(userData.userID)
.collection('notifications')
.snapshots(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
if (snapshot.data.documents.length != 0) {
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Row(
children: <Widget>[
Container(
height: 150,
width: 100,
child: Image(
image: NetworkImage(
snapshot.data.documents[index]['dpURL']), fit: BoxFit.contain,
),
), …Run Code Online (Sandbox Code Playgroud) Text在以下情况下,当屏幕不适合时,有没有办法自动断行文本?
Row(
children: [
SizedBox(width: 40, height:40),
Container(
child: Text("Long text without explicit line breaks, but still long.")
)
SizedBox(width: 40, height:40)
]
)
Run Code Online (Sandbox Code Playgroud)