There are a few ways to do this. Using widgets could definitely be an option, but that's probably going to cause you issues in the long run.
Let's break this into two parts:
1: Displaying the text
Instead of using widgets, I'd suggest using a RichText
with many TextSpan
children. You could create a custom class that accepts the string, splits it into characters, and puts each character in its own TextSpan. By using TextSpan.recognizer
. You could then either use a TapGestureRecognizer
with onTap
to show the information when tapped if you don't need the position at which it was tapped, or onTapDown
/onTapUp
if you do (for example if you want to show a popup right where the click happened as opposed to something like a bottom sheet that comes up).
2: Showing the information
Because you're wanting to deal with a large amount of characters, I'd suggest not doing it all in code but instead handling the characters in some other sort of format that can easily be manipulated, for example JSON. That way you can do things like splitting the data it into blocks and loading them as needed, and/or getting them from a web server.
Your data could look something like:
{
"家": {
"pronunciation": "jia",
"audio": "path/to/sound.m4a",
"animation": "path/to/animation.gif"
},
...
}
You could theoretically even do things like start loading the pronunciation files when the character is first shown or when they click on it.
When the character is tapped, you could:
- check if data in cache
- load the data if needed from network/disk
- open bottom sheet or popup displaying the pronunciation info + buttons for audio & drawing animation
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…