概述
1.2 使用TextSpan处理段落中的某个文本
1.源代码
import 'package:flutter/material.dart';
void main () => runApp(MyApp());
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context ){
return MaterialApp(
title:'Text widget usage',
home:Scaffold(
body:
Center(
child: Text.rich(TextSpan(
children: [
TextSpan(
text: '网址:',
style: TextStyle(
fontSize: 20.0,
color: Colors.blue
)
),
TextSpan(
text: 'http://www.baidu.com/',
style: TextStyle(
fontSize: 20.0,
color: Colors.red
)
),
]
),
),
),
),
);
}
}
2.解释源代码
import 'package:flutter/material.dart';
void main () => runApp(MyApp());
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context ){
return MaterialApp(
title:'Text widget usage',
home:Scaffold(
body:
Center(
//Text.rich() 方法将TextSpan添加到Text中
child: Text.rich(TextSpan(
children: [
TextSpan(
text: '网址:',
style: TextStyle(
fontSize: 20.0,
color: Colors.blue
)
),
TextSpan(
text: 'http://www.baidu.com/',
style: TextStyle(
fontSize: 20.0,
color: Colors.red
)
),
]
),
),
),
),
);
}
}
3.效果图
最后
以上就是腼腆高山为你收集整理的【自学Flutter】1.2 使用TextSpan处理段落中的某个文本的全部内容,希望文章能够帮你解决【自学Flutter】1.2 使用TextSpan处理段落中的某个文本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复