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-02 15:52:32 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-02-10 07:26:51 +01:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
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-07 12:17:29 +01:00
|
|
|
final WidgetBuilder screenBuilder;
|
2019-02-21 11:43:41 +01:00
|
|
|
final Function onTap;
|
2019-02-06 06:06:11 +01:00
|
|
|
final Color bgColor;
|
2019-02-08 12:34:07 +01:00
|
|
|
final bool material;
|
|
|
|
final bool fullscreenDialog;
|
2019-02-08 16:20:28 +01:00
|
|
|
final Icon iconButton;
|
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-07 12:17:29 +01:00
|
|
|
this.screenBuilder,
|
2019-02-21 11:43:41 +01:00
|
|
|
this.onTap,
|
2019-02-07 12:17:29 +01:00
|
|
|
this.bgColor,
|
2019-02-08 12:34:07 +01:00
|
|
|
this.material = true,
|
|
|
|
this.fullscreenDialog = false,
|
2019-02-08 16:20:28 +01:00
|
|
|
this.iconButton,
|
2019-02-10 07:26:51 +01:00
|
|
|
}) : assert(child != null || iconButton != null),
|
|
|
|
assert(screenBuilder == null || url == null);
|
2019-01-31 07:37:25 +01:00
|
|
|
|
2019-02-08 12:34:07 +01:00
|
|
|
void _onTap(BuildContext context, int theme) {
|
2019-02-21 11:43:41 +01:00
|
|
|
if (onTap != null) {
|
|
|
|
onTap();
|
2019-02-08 12:34:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (screenBuilder != null) {
|
2019-09-02 15:52:32 +02:00
|
|
|
Provider.of<ThemeModel>(context).pushRoute(
|
|
|
|
context: context,
|
|
|
|
builder: screenBuilder,
|
|
|
|
fullscreenDialog: fullscreenDialog);
|
2019-02-08 12:34:07 +01:00
|
|
|
}
|
2019-02-10 07:26:51 +01:00
|
|
|
|
|
|
|
if (url != null) {
|
|
|
|
launch(url);
|
|
|
|
}
|
2019-02-08 12:34:07 +01:00
|
|
|
}
|
|
|
|
|
2019-01-31 07:37:25 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-09-02 15:52:32 +02:00
|
|
|
var theme = Provider.of<ThemeModel>(context).theme;
|
2019-02-08 12:34:07 +01:00
|
|
|
|
2019-02-08 16:20:28 +01:00
|
|
|
if (iconButton != null) {
|
|
|
|
return IconButton(
|
|
|
|
icon: iconButton,
|
|
|
|
onPressed: () => _onTap(context, theme),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-08 12:34:07 +01:00
|
|
|
if (!material) {
|
|
|
|
return GestureDetector(
|
|
|
|
child: child,
|
|
|
|
onTap: () => _onTap(context, theme),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-31 07:37:25 +01:00
|
|
|
return Material(
|
|
|
|
child: Ink(
|
2019-02-06 06:06:11 +01:00
|
|
|
color: bgColor ?? Colors.white,
|
2019-01-31 07:37:25 +01:00
|
|
|
child: InkWell(
|
|
|
|
child: child,
|
2019-09-15 11:36:09 +02:00
|
|
|
splashColor:
|
|
|
|
theme == AppThemeMap.cupertino ? Colors.transparent : null,
|
2019-02-08 12:34:07 +01:00
|
|
|
onTap: () => _onTap(context, theme),
|
2019-01-31 07:37:25 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|