2019-01-31 07:37:25 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-07 12:17:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-09-29 07:32:53 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
|
|
|
|
class Link extends StatelessWidget {
|
|
|
|
final Widget child;
|
2019-02-10 07:26:51 +01:00
|
|
|
final String url;
|
2019-02-21 11:43:41 +01:00
|
|
|
final Function onTap;
|
2019-11-02 16:36:49 +01:00
|
|
|
final VoidCallback onLongPress;
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-02-07 12:17:29 +01:00
|
|
|
Link({
|
2019-02-08 16:20:28 +01:00
|
|
|
this.child,
|
2019-02-10 07:26:51 +01:00
|
|
|
this.url,
|
2019-02-21 11:43:41 +01:00
|
|
|
this.onTap,
|
2019-11-02 16:36:49 +01:00
|
|
|
this.onLongPress,
|
2019-12-13 04:02:05 +01:00
|
|
|
});
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-09-24 15:04:30 +02:00
|
|
|
void _onTap(BuildContext context) {
|
2019-02-21 11:43:41 +01:00
|
|
|
if (onTap != null) {
|
2019-09-24 15:04:30 +02:00
|
|
|
return onTap();
|
2019-02-08 12:34:07 +01:00
|
|
|
}
|
2019-02-10 07:26:51 +01:00
|
|
|
if (url != null) {
|
2019-12-12 13:29:56 +01:00
|
|
|
if (url.startsWith('/')) {
|
|
|
|
Provider.of<ThemeModel>(context).push(context, url);
|
|
|
|
} else {
|
|
|
|
launchUrl(url);
|
|
|
|
}
|
2019-02-10 07:26:51 +01:00
|
|
|
}
|
2019-02-08 12:34:07 +01:00
|
|
|
}
|
|
|
|
|
2019-01-31 07:37:25 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-11-05 14:22:41 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context).theme;
|
|
|
|
|
2019-01-31 07:37:25 +01:00
|
|
|
return Material(
|
|
|
|
child: Ink(
|
2019-11-05 14:22:41 +01:00
|
|
|
color: CupertinoTheme.of(context).scaffoldBackgroundColor,
|
2019-01-31 07:37:25 +01:00
|
|
|
child: InkWell(
|
|
|
|
child: child,
|
2019-11-05 14:22:41 +01:00
|
|
|
splashColor:
|
|
|
|
theme == AppThemeType.cupertino ? Colors.transparent : null,
|
2019-09-24 15:04:30 +02:00
|
|
|
onTap: () => _onTap(context),
|
2019-11-05 14:22:41 +01:00
|
|
|
onLongPress: onLongPress,
|
2019-01-31 07:37:25 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|