Skip to content

Instantly share code, notes, and snippets.

@plateaukao
Created March 11, 2020 16:08
Show Gist options
  • Save plateaukao/46852e4a1b63d59a7928e9a445c94dc0 to your computer and use it in GitHub Desktop.
Save plateaukao/46852e4a1b63d59a7928e9a445c94dc0 to your computer and use it in GitHub Desktop.
class _SentenceWidgetState extends State<SentenceWidget> {
bool isDisplayDefinition = false;
Timer timer;
@override
Widget build(BuildContext context) {
return ListTile(
onTap: toggleDefinitionVisibility,
contentPadding: EdgeInsets.all(8),
title: Html(
data: widget.sentence,
defaultTextStyle: TextStyle(fontSize: 20),
),
subtitle: Visibility(
visible: isDisplayDefinition,
child: Html(
data: widget.explanation,
defaultTextStyle: TextStyle(fontSize: 18),
),
),
);
}
toggleDefinitionVisibility() {
timer?.cancel();
setState(() {
isDisplayDefinition = !isDisplayDefinition;
});
if (isDisplayDefinition) {
timer = Timer(Duration(seconds: 5), () => toggleDefinitionVisibility());
}
}
@override
void dispose() {
timer?.cancel();
super.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment