refactor: handle global url

This commit is contained in:
Rongjian Zhang
2019-12-26 14:10:52 +08:00
parent 1ef1a5182e
commit 785c4368b6
2 changed files with 25 additions and 36 deletions

View File

@@ -7,25 +7,16 @@ class Link extends StatelessWidget {
final Widget child;
final String url;
final Function onTap;
final VoidCallback onLongPress;
Link({
this.child,
this.url,
this.onTap,
this.onLongPress,
});
void _onTap(BuildContext context) {
if (onTap != null) {
return onTap();
}
Provider.of<ThemeModel>(context).push(context, url);
}
@override
Widget build(BuildContext context) {
final theme = Provider.of<ThemeModel>(context).theme;
final theme = Provider.of<ThemeModel>(context);
return Material(
child: Ink(
@@ -33,9 +24,13 @@ class Link extends StatelessWidget {
child: InkWell(
child: child,
splashColor:
theme == AppThemeType.cupertino ? Colors.transparent : null,
onTap: () => _onTap(context),
onLongPress: onLongPress,
theme.theme == AppThemeType.cupertino ? Colors.transparent : null,
onTap: () async {
if (onTap != null) {
await onTap();
}
theme.push(context, url);
},
),
),
);