在颤动的文本之间生成小部件
Generate widgets in-between texts in flutter
我试图在每 300 个单词后生成一个页码列表,但不能。请问有人知道我该如何实现吗?
class Try extends StatelessWidget {
const Try({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final String text4 = lorem(paragraphs: 8, words: 2000);
return Scaffold(
body: SingleChildScrollView(
child: SafeArea(
child: Padding(
padding: const EdgeInsets.all(9),
child: Column(
children: [
Text(text4),
],
),
),
),
),
);
}
}
我尝试向其中添加以下代码但是...
for (int i = 0; i < text4.length;300 * i++)
//if (text4.length == 300)
Padding(
padding: const EdgeInsets.all(14),
child: Column(
children: [
const Text('page ${a += 1}'),
Divider(
color: Theme.of(context).primaryColor,
)
],
),
),
Text(text4),
您可以使用 substring
提取文本,页码逻辑将为 i / 300 + 1
。它将提供300封信。对于单词大小写,您需要通过拆分 space.
将文本转换为列表
final wordList = text4.split(" ").toList();
String text4 =
"I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.";
late final wordList = text4.split(" ").toList();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
// for (int i = 0; i < text4.length; i += 300)
for (int i = 0; i < wordList.length; i += 300)
Padding(
padding: const EdgeInsets.all(14),
child: Column(
children: [
Text('page ${i / 300 + 1}'),
Divider(
color: Theme.of(context).primaryColor,
),
/// for letters
// Text(text4.substring(
// i,
// i + 300 > text4.length ? text4.length : i + 300,
// )),
() {
final textX = wordList
.sublist(
i,
i + 300 > wordList.length
? wordList.length
: i + 300)
.toString();
return Text(textX.substring(1, textX.length - 1));
}()
],
),
),
],
),
),
);
}
[]
依赖原文,子串处理Text(textX.substring(1, textX.length - 1));
.
我试图在每 300 个单词后生成一个页码列表,但不能。请问有人知道我该如何实现吗?
class Try extends StatelessWidget {
const Try({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final String text4 = lorem(paragraphs: 8, words: 2000);
return Scaffold(
body: SingleChildScrollView(
child: SafeArea(
child: Padding(
padding: const EdgeInsets.all(9),
child: Column(
children: [
Text(text4),
],
),
),
),
),
);
}
}
我尝试向其中添加以下代码但是...
for (int i = 0; i < text4.length;300 * i++)
//if (text4.length == 300)
Padding(
padding: const EdgeInsets.all(14),
child: Column(
children: [
const Text('page ${a += 1}'),
Divider(
color: Theme.of(context).primaryColor,
)
],
),
),
Text(text4),
您可以使用 substring
提取文本,页码逻辑将为 i / 300 + 1
。它将提供300封信。对于单词大小写,您需要通过拆分 space.
final wordList = text4.split(" ").toList();
String text4 =
"I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.I am trying to generate a list of pages numbers after every 300 words but can't. please does anybody know how I can implement this?.";
late final wordList = text4.split(" ").toList();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
// for (int i = 0; i < text4.length; i += 300)
for (int i = 0; i < wordList.length; i += 300)
Padding(
padding: const EdgeInsets.all(14),
child: Column(
children: [
Text('page ${i / 300 + 1}'),
Divider(
color: Theme.of(context).primaryColor,
),
/// for letters
// Text(text4.substring(
// i,
// i + 300 > text4.length ? text4.length : i + 300,
// )),
() {
final textX = wordList
.sublist(
i,
i + 300 > wordList.length
? wordList.length
: i + 300)
.toString();
return Text(textX.substring(1, textX.length - 1));
}()
],
),
),
],
),
),
);
}
[]
依赖原文,子串处理Text(textX.substring(1, textX.length - 1));
.