Add hooks

This commit is contained in:
Ricardo Markiewicz
2020-02-10 10:27:16 -03:00
parent 98d77da5b8
commit a3e0f9ac43
4 changed files with 57 additions and 32 deletions
+9 -32
View File
@@ -1,25 +1,23 @@
import 'package:como_gasto/como_gasto_localizations.dart';
import 'package:como_gasto/hooks/tap_gesture_recognizer_hook.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
class LegalNoticeWidget extends StatefulWidget {
class LegalNoticeWidget extends HookWidget {
const LegalNoticeWidget({
Key key,
}) : super(key: key);
@override
_LegalNoticeWidgetState createState() => _LegalNoticeWidgetState();
}
class _LegalNoticeWidgetState extends State<LegalNoticeWidget> {
TapGestureRecognizer _recognizer1;
TapGestureRecognizer _recognizer2;
@override
Widget build(BuildContext context) {
final boldFont =
Theme.of(context).textTheme.body1.copyWith(fontWeight: FontWeight.bold);
ComoGastoLocalizations localizations = ComoGastoLocalizations.of(context);
final _recognizer1 = useTapGestureRecognizer(() =>
showHelp(context, _getTranslatedString(context, 'login.help.terms')));
final _recognizer2 = useTapGestureRecognizer(() =>
showHelp(context, _getTranslatedString(context, 'login.help.privacy')));
return RichText(
textAlign: TextAlign.center,
@@ -43,32 +41,11 @@ class _LegalNoticeWidgetState extends State<LegalNoticeWidget> {
);
}
@override
void initState() {
super.initState();
_recognizer1 = TapGestureRecognizer()
..onTap = () {
showHelp(_getTranslatedString('login.help.terms'));
};
_recognizer2 = TapGestureRecognizer()
..onTap = () {
showHelp(_getTranslatedString('login.help.privacy'));
};
}
@override
void dispose() {
super.dispose();
_recognizer1.dispose();
_recognizer2.dispose();
}
String _getTranslatedString(String key) {
String _getTranslatedString(BuildContext context, String key) {
return ComoGastoLocalizations.of(context).t(key);
}
void showHelp(String s) {
void showHelp(BuildContext context, String s) {
showDialog(
context: context,
builder: (context) => AlertDialog(