gpt4 book ai didi

flutter - 如果文本溢出抖动,如何自动换行

转载 作者:行者123 更新时间:2023-12-04 01:36:13 35 4
gpt4 key购买 nike

你好,现在我正在制作古兰经应用程序..我正在从 json 文件中获取数据。我想问一下,如果它像图片中那样溢出,我该如何创建一个新行?我尝试了很多东西,但似乎都不起作用..有没有办法用字符串变量手动创建一个新行?请分享您的解决方案.. 提前致谢:)

import 'dart:convert';

import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts_arabic/fonts.dart';
import 'package:waktusolatimprovised/menu.dart';

class QuranPage extends StatefulWidget {
final surahDipilih;

const QuranPage({Key key, this.surahDipilih}) : super(key: key);
@override
QuranPageState createState() => QuranPageState();
}

class QuranPageState extends State<QuranPage> {
List data;

var text;
var translate;

@override
Widget build(BuildContext context) {
Future<dynamic> loadJson() async {
String quranText =
await DefaultAssetBundle.of(context).loadString("images/quran.json");
String quranTranslate = await DefaultAssetBundle.of(context)
.loadString("images/quranterjemahan.json");
return {text = quranText, translate = quranTranslate};
}

return Scaffold(
appBar: AppBar(
title: Text("Load local JSON file"),
),
drawer: Durawa(),
body: Container(
child: Center(
// Use future builder and DefaultAssetBundle to load the local JSON file
child: FutureBuilder(
future: loadJson(),
builder: (context, snapshot) {
if (text == null && translate == null) {
return CircularProgressIndicator();
}
var quranText = json.decode(text);
var quranTranslation = json.decode(translate);
// Decode the JSONR

double c_width = MediaQuery.of(context).size.width * 0.8;

return ListView.builder(
// Build the ListView
itemBuilder: (BuildContext context, int index) {
List text = [
quranText['sura'][widget.surahDipilih]['aya'][index]
['_text'],
quranTranslation[widget.surahDipilih]['aya'][index]
['@text']
];

return Container(
child: Row(
children: <Widget>[
Flexible(
child: Column(
children: <Widget>[
Container(
child: AutoSizeText(
"${text[0]}",
style: TextStyle(
fontFamily: 'quran', fontSize: 30),
textAlign: TextAlign.end,
)),
Text('Malay Translation'),
Container(
child: Card(
child: Text(
"${text[1]}",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.w300),
textAlign: TextAlign.right,
)),
),
],
),
),
],
),
);
},
itemCount: 7,
);
}),
),
));
}
}


quranpage.dart

最佳答案

Flexible() 包裹你的文字小部件并添加 overflow Text() 的属性与 TextOverflow.visible你准备好了。

关于flutter - 如果文本溢出抖动,如何自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59473595/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com