一、使用RichText
代码如下(示例):
import 'dart:io';
import 'dart:ui';
import 'package:emoji_picker_flutter/emoji_picker_flutter.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
/// Example for EmojiPickerFlutter
class MyApp extends StatefulWidget {
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late TextStyle _textStyle;
void initState() {
// TODO: implement initState
super.initState();
_textStyle = TextStyle(color: Colors.white);
}
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('Emoji Picker Example App'),
),
body: Center(
child: RichText(
text: constTextSpan(
style: const TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold),
children: [
const TextSpan(text: '点击查看具体内容'),
TextSpan(
text: '隐私协议',
//点击之后功能实现操作
recognizer: TapGestureRecognizer()
..onTap = () => print('click 隐私协议'),
style: const TextStyle(
color: Colors.blueAccent,
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold)),
const TextSpan(text: '和'),
TextSpan(
text: '使用条款',
recognizer: TapGestureRecognizer()
..onTap = () => print('click 使用条款'),
style: const TextStyle(
color: Colors.blueAccent,
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold)),
])),
)),
);
}
}