Created
March 11, 2020 16:08
-
-
Save plateaukao/46852e4a1b63d59a7928e9a445c94dc0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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