英文:
Flutter alignement and wrap of different texts
问题
我联系你是因为我想复制《Libération》报纸的应用程序,但我卡住了(已经!)在标题的问题上。
我附上了一个视觉示例,我会尽量清楚地说明。我希望标题的第一部分是红色的,然后标题继续是黑色的,再次对齐左边,位于红色标题的下方。我尝试了许多方法,但都没有成功。Expanded、Wrap... 要么文本溢出,要么当我设法使黑色文本换行时,它定位在黑色文本下方,而不是红色文本下方,考虑到块从红色块的右侧开始。
我尝试了Wrap、Row、Expanded。
谢谢
英文:
This is the model of what i want to do !
I'm contacting you because I'm trying to copy the Libération newspaper application but I'm stuck (already!) on the question of the title.
I have attached a visual and I will try to be clear. I would like the first part of the title to be in red and then the title to continue in black and line up again, aligned to the left, under the red title. I have tried many methods to no avail. Expanded, Wrap... either the text sticks out or, when I manage to make the line break of the black text, it is positioned under the black text, not under the red text, considering that the block starts on the right of the red block.
I tried Wrap, Row, Expanded.
Thank you
答案1
得分: 0
以下是您要翻译的代码部分:
this is just an example ,
If it's dynamic you might want to use: a separator; to split the title or the text or another symbol
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
final String title =
"Chez Pol; Et si on mesurait le bruit à l'Assemblée pour la santé des députés?";
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: SafeArea(
child: Scaffold(
body: RichText(
text: TextSpan(
text: title.split(';')[0].toString(),
style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
children: <TextSpan>[
TextSpan(
text: title.split(';')[1].toString(),
style: const TextStyle(color: Colors.black),
),
],
),
),
),
),
);
}
}
希望这有帮助!
英文:
this is just an example ,
If it's dynamic you might want to use: a separator; to split the title or the text or another symbol
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
final String title =
"Chez Pol; Et si on mesurait le bruit à l'Assemblée pour la santé des députés?";
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: SafeArea(
child: Scaffold(
body: RichText(
text: TextSpan(
text: title.split(';')[0].toString(),
style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold),
children: <TextSpan>[
TextSpan(
text: title.split(';')[1].toString(),
style: const TextStyle(color: Colors.black),
),
],
),
),
),
),
);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论