我試圖在每 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),
uj5u.com熱心網友回復:
您可以使用substring提取文本和頁碼的邏輯將i / 300 1. 它將提供 300 封信。對于單詞大小寫,您需要通過空格分割將文本轉換為串列。
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));
}()
],
),
),
],
),
),
);
}

[] depends on original text, for substring it is handled Text(textX.substring(1, textX.length - 1));.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/433468.html
